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.
Prerequisites
Section titled “Prerequisites”- Node.js 22 LTS
- pnpm 11.9+ (the project uses pnpm)
- PostgreSQL 18 (or the
sim-databaselocal Docker stack) - Redis 7 (optional locally; an in-memory fallback is available)
- MinIO or S3 (optional locally; uploads will use S3 in production)
Repository layout
Section titled “Repository layout”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 stubsEnvironment setup
Section titled “Environment setup”- Copy
.env.exampleto.env. - Adjust PostgreSQL and Redis settings for your local Docker stack.
- Set
NODE_ENV=developmentandSWAGGER_ENABLED=truefor 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 |
Install dependencies
Section titled “Install dependencies”cd sim-backendpnpm installDatabase generation and verification
Section titled “Database generation and verification”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:
- Migrates
../sim-database(Flyway). - Regenerates
src/db/generated.tswithdbgen/dbgen.mjs. - Checks the diff is empty (
git diff --exit-code -- src/db/generated.ts). - Runs
tsc --noEmit. - Runs
pnpm test. - Runs
pnpm db:smoke. - Runs
pnpm db:slice.
pnpm db:verifyIf you only want to regenerate generated.ts after a migration:
pnpm db:genRun the API
Section titled “Run the API”Development with hot reload:
pnpm start:devProduction build and run:
pnpm buildpnpm start:prodExplore the API
Section titled “Explore the API”When SWAGGER_ENABLED=true, the OpenAPI spec is available at:
http://localhost:3000/docsBase paths:
/api/v1/*— protected business API/metrics— Prometheus scrape endpoint/api/v1/health/live— liveness probe/api/v1/health/ready— readiness probe (PostgreSQL + Redis)
Common commands
Section titled “Common commands”| 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 |