Skip to content

Latest commit

 

History

History
114 lines (86 loc) · 3.69 KB

File metadata and controls

114 lines (86 loc) · 3.69 KB

DraftDream API

NestJS 11 + Fastify/Mercurius GraphQL backend for the DraftDream platform.

Scope

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

Technical stack

  • 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

Architecture

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

Getting started

cd api
npm install
npm run start:dev

Default local GraphQL endpoint: http://localhost:3000/graphql

Configuration

Create api/.env with environment-specific values. Never commit secrets to git.

Key variables:

  • MONGO_URL: MongoDB connection string
  • JWT_SECRET: Secret for signing tokens
  • NODE_ENV: dev, test, or prod
  • MORGANS_ENDPOINT: Morgans GraphQL endpoint (default: http://localhost:8025/graphql)
  • MORGANS_API_KEY: Optional API key sent via x-api-key header
  • MORGANS_LOCAL: Set to true to use the fake mail adapter (no outgoing HTTP call)

Reference for defaults: src/config/defaults.ts and src/config/**.

Available Scripts

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

Database Commands

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

Project structure

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

Documentation

Quality Checklist

  1. npm run lint - No linting errors
  2. npm run build - Successful compilation
  3. npm test - All 900+ tests passing
  4. Update api/docs/usecases and api/docs/features when logic changes

Docker

The API is part of the monorepo compose stack. Run the full platform with:

make up-dev

Or build the image directly: docker build -t fitdesk-api ./api.