Skip to content

Getting started

The SIM backend is a NestJS 11 / TypeScript 5.7 API. It expects a PostgreSQL database, Redis (optional in dev) and a compatible Node.js 22 runtime.

  • Node.js 22 LTS
  • pnpm 11.9+ (the project uses pnpm)
  • PostgreSQL 18 (or the sim-database local Docker stack)
  • Redis 7 (optional locally; an in-memory fallback is available)
  • MinIO or S3 (optional locally; uploads will use S3 in production)
sim-backend/
├── package.json
├── pnpm-workspace.yaml
├── nest-cli.json
├── tsconfig.json
├── tsconfig.build.json
├── Dockerfile
├── docker-compose.local.yml
├── docker-compose.dev.yml
├── docker-compose.prod.yml
├── docker-entrypoint.sh
├── scripts/
│ └── db-verify.mjs # full migration -> generated.ts -> tsc -> test chain
├── dbgen/
│ ├── dbgen.mjs # generated.ts generator
│ └── dbgen.metadata.json # generator metadata overrides
├── src/
│ ├── main.ts
│ ├── app.module.ts
│ ├── app.setup.ts
│ ├── config/
│ ├── db/
│ ├── common/
│ ├── auth/
│ ├── admin/
│ ├── core/
│ ├── client/
│ ├── residence/
│ ├── market/
│ ├── pressing/
│ ├── restaurant/
│ ├── salle_fete/
│ ├── facturation/
│ ├── finances/
│ ├── rh/
│ ├── dashboard/
│ ├── rapports/
│ ├── audit/
│ ├── abonnement/
│ ├── jobs/
│ ├── health/
│ ├── metrics/
│ ├── redis/
│ ├── s3/
│ ├── uploads/
│ └── pdf/
└── test/ # Jest e2e harness + kysely/puppeteer stubs
  1. Copy .env.example to .env.
  2. Adjust PostgreSQL and Redis settings for your local Docker stack.
  3. Set NODE_ENV=development and SWAGGER_ENABLED=true for local exploration.

Key variables:

Variable Purpose Default / source
NODE_ENV development, test, production development
PORT HTTP port 3000
PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE PostgreSQL connection DB_DEFAULTS
JWT_ACCESS_SECRET, JWT_REFRESH_SECRET JWT signing (required in production) dev throwaway
REDIS_URL Redis for token revocation / queues / throttling in-memory if absent
S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY Object storage S3_DEFAULTS
PUPPETEER_EXECUTABLE_PATH Chrome binary for PDF rendering auto-resolved in Dockerfile
Terminal window
cd sim-backend
pnpm install

The backend requires src/db/generated.ts to be in sync with the live PostgreSQL catalog. The simplest path is to run pnpm db:verify, which:

  1. Migrates ../sim-database (Flyway).
  2. Regenerates src/db/generated.ts with dbgen/dbgen.mjs.
  3. Checks the diff is empty (git diff --exit-code -- src/db/generated.ts).
  4. Runs tsc --noEmit.
  5. Runs pnpm test.
  6. Runs pnpm db:smoke.
  7. Runs pnpm db:slice.
Terminal window
pnpm db:verify

If you only want to regenerate generated.ts after a migration:

Terminal window
pnpm db:gen

Development with hot reload:

Terminal window
pnpm start:dev

Production build and run:

Terminal window
pnpm build
pnpm start:prod

When SWAGGER_ENABLED=true, the OpenAPI spec is available at:

http://localhost:3000/docs

Base paths:

  • /api/v1/* — protected business API
  • /metrics — Prometheus scrape endpoint
  • /api/v1/health/live — liveness probe
  • /api/v1/health/ready — readiness probe (PostgreSQL + Redis)
Command Purpose
pnpm lint ESLint 9 with strict TypeScript rules
pnpm build tsc compile to dist/
pnpm test Jest unit suites (uses test/kysely-stub.cjs)
pnpm test:e2e Jest e2e suites (see test/jest-e2e.json)
pnpm db:gen Regenerate src/db/generated.ts
pnpm db:check Fail if generated.ts is stale
pnpm db:smoke Run src/db/smoke.ts against the live DB
pnpm db:slice:core Run the Core live-DB e2e script
pnpm security:audit pnpm audit --prod