3.0 KiB
Backend Generation Process
Backend generation follows a pipeline aligned with runtime and validation docs:
DSL ↓ CLI scaffolding ↓ code generation ↓ runtime infrastructure ↓ database runtime ↓ migration ↓ seed ↓ validation
Follow backend/runtime-rules.md, backend/prisma-rules.md, backend/prisma-service.md, backend/database-runtime.md, backend/seed-rules.md, and backend/service-rules.md.
Step 1 — Parse DSL
Read DSL inputs and extract:
- entities
- attributes (including primary key attribute name per entity)
- enums
- foreign keys
Step 2 — CLI scaffolding
Use official CLIs before generating backend code:
- NestJS project scaffold in
server/(seegeneration/scaffolding-rules.md) - Install backend dependencies (
@prisma/client,prisma,@nestjs/config, and seed runner when needed)
Step 3 — Code generation
Generate backend source artifacts:
- Prisma schema (
server/prisma/schema.prisma) from domain DSL:- attributes
- primary keys
- relations
- enums
- NestJS modules per entity:
- module
- controller (path params use actual PK name:
:id,:code, etc.) - service (must sanitize update payload before Prisma — see backend/service-rules.md)
- DTO files:
create-entity.dto.tsupdate-entity.dto.tsentity.response.dto.ts(or equivalent)
- PrismaService:
OnModuleInit+await this.$connect()- no
beforeExithook
- Service update methods: Sanitize update payload before passing to Prisma (remove
id, primary key, and readonly attributes fromdata). Do not pass the raw request body asdatatoprisma.*.update().
Use mapping rules from backend/prisma-rules.md:
- DSL
decimal-> DTOstring - DSL
date-> DTOstring(ISO)
Step 4 — Runtime infrastructure
Generate runtime config files:
server/.envserver/.env.exampleserver/package.jsonlifecycle:"postinstall": "prisma generate"
server/package.jsonPrisma seed:"prisma": { "seed": "ts-node prisma/seed.ts" }(ortsxvariant by project standard)
Commands that must be supported/documented:
npx prisma generatenpx prisma migrate devnpx prisma db seed
Step 5 — Database runtime
Generator must create docker-compose.yml at the project root with PostgreSQL.
Minimum required compose characteristics:
services.postgresimage: postgres:16ports: ["5432:5432"]
Credentials/database in compose must match DATABASE_URL.
Step 6 — Migration
Apply schema to development database:
cd server
npx prisma migrate dev
Step 7 — Seed
Run development seed:
cd server
npx prisma db seed
Seed file location: server/prisma/seed.ts.
Step 8 — Validation
Run runtime and contract checks from generation/post-generation-validation.md, including:
- docker-compose exists and DB container starts
- Prisma lifecycle commands succeed
- seed runs
/healthresponds- React Admin receives
idin every record