Overview
API routes are organized inapps/server/src/api/client/routes/ and grouped by feature:
- accounts/ - Authentication and account management
- workspaces/ - Workspace operations
- avatars/ - File upload/download
- sockets/ - WebSocket connections
Architecture
API structure:Step-by-step guide
Define request/response schemas
Create Zod schemas in Export from
packages/core/src/api/ for type-safe validation.packages/core/src/api/tasks/task-create.ts
packages/core/src/api/index.ts:Create the route handler
Implement the route in
apps/server/src/api/client/routes/.apps/server/src/api/client/routes/tasks/task-create.ts
Register the route
Create an index file to group related routes:Add to main router in
apps/server/src/api/client/routes/tasks/index.ts
apps/server/src/api/client/routes/index.ts:Route patterns
Basic CRUD operations
Error handling
Return appropriate HTTP status codes with error details:Authentication patterns
Rate limiting
Apply rate limiting to sensitive endpoints:Plugins
Available Fastify plugins inapps/server/src/api/client/plugins/:
- account-auth - Validates JWT and populates
request.account - workspace-auth - Validates workspace access and populates
request.user - auth-ip-rate-limit - Rate limits by IP address
- cors - CORS configuration
- error-handler - Global error handling
Request context
Database queries
Use Kysely for type-safe database queries:Testing API routes
File locations
- Schemas:
packages/core/src/api/[feature]/[action].ts - Routes:
apps/server/src/api/client/routes/[feature]/[action].ts - Plugins:
apps/server/src/api/client/plugins/[name].ts - Database:
apps/server/src/data/database.ts - Event bus:
apps/server/src/lib/event-bus.ts