Deep DivesAPI

Development

Local development guide for the RawStack API component.

Setup

cd apps/api
npm install
docker compose up -d
cp .env.dist .env
npm run dev

The API starts on http://localhost:3001. OpenAPI docs are served at http://localhost:3001/docs.

Project structure

apps/api/
├── src/
│   ├── main.ts               # Bootstrap — NestJS app, Zod pipes, Swagger
│   ├── app.module.ts         # Root module
│   ├── auth/                 # Auth module (CQRS + DDD)
│   ├── user/                 # User module (CQRS + DDD)
│   └── common/               # Shared filters, base models
├── prisma/
│   ├── schema.prisma         # Database schema
│   └── migrations/           # Migration history
├── test/
│   ├── unit/                 # Jest unit tests
│   ├── integration/          # Integration tests (real DB)
│   └── e2e/                  # End-to-end API tests
├── docker-compose.yml
├── .env.dist
└── Dockerfile

Adding a new module

Follow the existing auth or user module as a template:

  1. Create src/<module>/domain/ — entities, value objects, repository interfaces
  2. Create src/<module>/application/ — commands, queries, handlers
  3. Create src/<module>/infrastructure/ — controllers, Prisma repos, sagas
  4. Register the module in app.module.ts

Database migrations

# Generate a new migration from schema changes
npx prisma migrate dev --name <migration-name>

# Apply migrations (production)
npx prisma migrate deploy

# Open Prisma Studio (GUI)
npx prisma studio

Useful scripts

ScriptDescription
npm run devStart with watch mode + auto-migrate
npm run buildCompile TypeScript
npm run lintESLint
npm run formatPrettier