Instruction file imported from TheMegafuji/fastify-starter-api-template (
.cursor/rules/api-endpoints.mdc). Copyright stays with the author.
API Endpoints Guide (Template)
This repository is a Fastify API template. Endpoints are organized by feature and follow a consistent flow:
Route → Schema → Controller → Service → Repository (ports/adapters) → Prisma/PostgreSQL
Where endpoints live
- Routes: src/routes/ (
*.routes.ts) - Route registration: src/routes/index.ts
- Schemas (TypeBox): src/schemas/ (
*.schema.ts) - Controllers: src/controllers/ (
*.controller.ts) - Services: src/services/ (
*.service.ts) - Data layer (ports/adapters):
- Ports (interfaces): src/repositories/ports/
- Adapters (Prisma): src/repositories/prisma/
- Adapters (in-memory for tests): src/repositories/memory/
Core endpoints (typical in projects using this template)
- GET
/healthcheck- Health check (API + DB/cache connectivity) - POST
/auth/login- Issues JWT (if you keep JWT auth enabled)
Note: this template may ship with additional sample feature modules under
src/routes/to demonstrate patterns. Replace/rename them to match your domain.
Swagger / OpenAPI
- Swagger UI is served at
/by default (see src/server.ts). - OpenAPI definitions live in src/docs/.
Authentication requirements
- Protected routes should require Bearer JWT:
Authorization: Bearer <token>. - Token validation is handled by src/plugins/auth.ts.
- The authenticated user context is exposed via
request.user.
Rate limiting
- Enabled via
@fastify/rate-limitin src/server.ts (default: 100 req/min/IP).
Tests
- Integration tests live in tests/ (Jest + Supertest).