NestJS 11 + Fastify/Mercurius GraphQL backend for the DraftDream platform.
The API exposes core business capabilities used by frontoffice, backoffice, and showcase:
- Authentication and session flows (JWT + Role-based access)
- User and athlete management
- Sport and nutrition domains (programs, sessions, exercises, meals, plans, records)
- Wellness reports and KPI summaries
- Support and contact-message pipeline
- Legal document compliance and signatures
- Runtime: Node.js 20+
- Framework: NestJS 11
- API: Fastify + Mercurius (GraphQL)
- Database: MongoDB (Native Driver + Mongoose for schema-based models)
- DI Container: Inversify
- Testing: Jest + ts-jest
The service follows a Hexagonal Architecture (Ports and Adapters):
- Core:
src/usecases/**(Pure business logic, framework-agnostic) - Driving Adapters:
src/graphql/**(Resolvers, GQL DTOs),src/http/**(Controllers) - Driven Adapters:
src/services/**(Infrastructure: Mongo repositories, Auth, Crypto, Logging) - Dependency Wiring:
src/inversify/investify.ts
cd api
npm install
npm run start:devDefault local GraphQL endpoint: http://localhost:3000/graphql
Create api/.env with environment-specific values. Never commit secrets to git.
Key variables:
MONGO_URL: MongoDB connection stringJWT_SECRET: Secret for signing tokensNODE_ENV:dev,test, orprodMORGANS_ENDPOINT: Morgans GraphQL endpoint (default:http://localhost:8025/graphql)MORGANS_API_KEY: Optional API key sent viax-api-keyheaderMORGANS_LOCAL: Set totrueto use the fake mail adapter (no outgoing HTTP call)
Reference for defaults:
src/config/defaults.tsandsrc/config/**.
| Script | Description |
|---|---|
npm run start:dev |
Start API in watch mode with NODE_ENV=dev |
npm run start |
Start API |
npm run build |
Compile TypeScript via Nest CLI |
npm run test |
Run all Jest tests |
npm run test:coverage |
Run tests with coverage report |
npm run lint |
Run ESLint check |
npm run lint:fix |
Run ESLint and auto-fix |
| Script | Description |
|---|---|
npm run db:reset |
Drop all collections (interactive confirmation) |
npm run db:reset:dev |
Drop collections and restart in dev mode |
npm run seed:dev |
Insert idempotent development dataset |
npm run db:fresh |
Full reset + fresh seed |
src/
common/ # Shared utilities, enums and constants
config/ # Runtime configuration mapping
graphql/ # GraphQL resolvers, GQL-specific DTOs, guards
http/ # HTTP controllers and public endpoints
inversify/ # Inversify container and module wiring
services/ # Infrastructure adapters (DB, Auth, Crypto, Logger)
usecases/ # Application business logic (The Core)
docs/
usecases/ # Detailed documentation for complex use cases
features/ # Functional feature descriptions- Detailed Use Cases Documentation
- GraphQL Create/Update Input Validation Audit
- Project Guidelines (GEMINI.md)
npm run lint- No linting errorsnpm run build- Successful compilationnpm test- All 900+ tests passing- Update
api/docs/usecasesandapi/docs/featureswhen logic changes
The API is part of the monorepo compose stack. Run the full platform with:
make up-devOr build the image directly: docker build -t fitdesk-api ./api.