Skip to content

Backend Overview

The SIM Backend is the NestJS 11 / TypeScript REST API for GLOBAL SIM GROUP. It serves all business modules — Résidence, Market, Pressing, Restaurant, Salle de fête, Facturation, Finances, and RH — over one PostgreSQL database using Kysely with generated types.

  • The architecture contract and the typed PostgreSQL access boundary
  • Getting the API running locally
  • Database access with Kysely, generated types, and the audit transaction boundary
  • Authentication, JWT refresh rotation, and RBAC
  • API conventions: controllers, DTOs, validation, and error handling
  • Business modules and their routes
  • Integrations: Redis, S3/MinIO, PDF, Prometheus, BullMQ
  • Operations, Docker, deployment, and the db:verify invariant
  • Testing with Jest and live-DB slices
  • Cookbook recipes for common contributor tasks
Terminal window
cd sim-backend
pnpm install
pnpm db:verify # migrate sibling database, regenerate generated.ts, build, test
pnpm start:dev # hot reload on http://localhost:3000
# Swagger at http://localhost:3000/docs
Principle How it is implemented
Generated type boundary src/db/generated.ts is produced by dbgen/dbgen.mjs from PostgreSQL.
No ORM Kysely query builder; explicit repositories with no base class.
Audit threading Every write runs inside scope.audit(user.id, async (a) => …) which sets sim.id_utilisateur.
String-valued network bigint, numeric, and dates travel as strings; services cast to branded DB types.
Frozen CRUD surface DbAccess exposes equality + order/limit/offset; complex queries are explicit repository methods.
Schema belongs to sim-database Migrations are Flyway, not Nest; pnpm db:verify enforces generated.ts freshness.
Module Purpose
core Global parameters
client Single client referential, identity documents, emergency contacts
residence Buildings, rooms, contracts, rent, deposits, short stays, portal
market Products, stock, sales, barcodes
pressing Garment order lifecycle
restaurant Dishes, categories, orders
salle_fete Event-room reservations
facturation Services, invoices, settlement
finances Payments, expenses, cash drawers, consolidation
rh Employees, attendance, payroll
dashboard Aggregated tiles
rapports Global, financial, activity, HR reports
audit Read-only audit journal and masking
auth / admin JWT, RBAC, users, roles, permissions