Local Development
Quick Start
Section titled “Quick Start”git clone https://github.com/RelativeSure/LeafLock.gitcd LeafLockcp .env.example .envmake upmake logsgit clone https://github.com/RelativeSure/LeafLock.gitcd LeafLockcp .env.example .envdocker compose up -ddocker compose logs -fServices:
- Frontend:
http://localhost:3000 - Backend:
http://localhost:8080 - Health:
http://localhost:8080/api/v1/health
Shutdown: make down or docker compose down
Environment Configuration
Section titled “Environment Configuration”Required variables in .env:
POSTGRES_PASSWORD=<secure-password>REDIS_PASSWORD=<secure-password>JWT_SECRET=<64-char-base64> # openssl rand -base64 64SERVER_ENCRYPTION_KEY=<32-char> # openssl rand -base64 32CORS_ORIGINS=http://localhost:3000See Environment Variables for complete reference.
Backend Development
Section titled “Backend Development”Location: backend/
cd backendgo run main.go # Dev servergo test -v ./... # All testsgolangci-lint run ./... # Lint (required after complex changes)
# Build pipelinemake -C backend fmt # Formatmake -C backend vet # Vetmake -C backend build # Compile binary → backend/bin/leaflockmake -C backend test # Tests with coverageHot reload: Use air (configured in backend/.air.toml):
make devImplementation:
- Go 1.23+ with Fiber v2
- PostgreSQL (pgx driver)
- Redis for sessions/rate limiting
- JWT auth:
backend/middleware/jwt.go - Handlers:
backend/handlers/
Frontend Development
Section titled “Frontend Development”Location: frontend/
cd frontendpnpm installpnpm run dev # Vite dev server (HMR enabled)pnpm run build # Production build → frontend/distpnpm test # Testspnpm run lint # ESLintpnpm run type-check # TypeScript checkImplementation:
- React 18 + TypeScript (100%
.tsx, enforced byscripts/check-no-jsx.sh) - Vite 5 for build tooling
- Zustand for state management
- shadcn/ui components
- Quill 2.0 + Lexical for rich text editing
⚠️ CRITICAL: Never create .jsx files. All React files must use .tsx extension.
Database Migrations
Section titled “Database Migrations”Auto-run on backend startup. MUST bump version when modifying schema:
File: backend/database/database.go:21
const MigrationSchemaVersion = "2024.12.25.003" // Increment last numberSchema: backend/database/schema.go
Skip check (benchmarks only): SKIP_MIGRATION_CHECK=true
API Documentation
Section titled “API Documentation”Swagger UI: http://localhost:8080/api/v1/docs (admin-only)
OpenAPI Spec: http://localhost:8080/api/v1/docs/openapi.json
Local access: Set ADMIN_USER_IDS=<your-user-id> in .env to bootstrap admin access.
Complete API reference: REST API
Pre-commit Hooks
Section titled “Pre-commit Hooks”# Installpython3 -m pip install --user pre-commit~/.local/bin/pre-commit install
# Manual run~/.local/bin/pre-commit run --all-files
# Skip (not recommended)git commit --no-verify -m "message"Hooks:
- Security: detect-secrets, private key detection
- Go: go-fmt, go-vet, go test, golangci-lint
- Frontend: check-no-jsx, pnpm lint, pnpm test
- General: trailing whitespace, YAML/JSON validation
Config: .pre-commit-config.yaml
Health Checks
Section titled “Health Checks”# Liveness (3-5s)curl http://localhost:8080/api/v1/health/live
# Readiness (15-30s, checks DB/Redis)curl http://localhost:8080/api/v1/health/ready
# Response{"status": "ready","admin_ready": true,"templates_ready": true,"redis_ready": true}Testing
Section titled “Testing”Backend:
cd backendgo test -v ./... # All testsgo test -v ./handlers/share_links_test.go # Specificgo test -v -cover ./... # With coverageFrontend:
cd frontendpnpm test # All testspnpm test ShareDialog.test # Specificpnpm test --coverage # With coverageCommon Tasks
Section titled “Common Tasks”Reset database:
make downdocker volume rm leaflock_postgres_datamake upView logs:
make logs # All servicesdocker compose logs -f backenddocker compose logs -f frontendAccess database:
docker compose exec postgres psql -U postgres notesAccess Redis:
docker compose exec redis redis-cli -a "$REDIS_PASSWORD"Troubleshooting
Section titled “Troubleshooting”Frontend can’t reach backend:
- Check
VITE_API_URLin.env - For IPv6: Use
http://[::1]:8080format - Verify backend is running:
curl http://localhost:8080/api/v1/health
Migration didn’t run:
- Check if
MigrationSchemaVersionwas bumped inbackend/database/database.go:21 - Existing deployments skip if version matches
Docker containers can’t communicate:
- Use service names (
postgres,redis,backend) not IPs - Check
docker-compose.ymlservice names
Build failures:
# Clean and rebuilddocker compose downdocker compose build --no-cachedocker compose up -dSee Troubleshooting for platform-specific issues.
Additional Resources
Section titled “Additional Resources”- Architecture: Frontend, Backend, Encryption
- Deployment: Docker, Kubernetes, Railway
- CLAUDE.md: Repository root contains complete development guidelines