7.7 KiB
Post-Generation Validation
After generating the backend or fullstack application, run these checks to ensure the project will run without runtime errors.
Validation Checklist
1. Environment file
.envexists in the backend root (e.g.server/.env)..env.exampleexists with at leastDATABASE_URLand a placeholder value.DATABASE_URLis present in.env(or documented in.env.exampleso the user can copy and set it).
Failure symptom: Environment variable not found: DATABASE_URL at startup.
2. PrismaService implementation
- A PrismaService (or equivalent) class exists and extends
PrismaClient. - It implements
OnModuleInitand callsawait this.$connect()inonModuleInit(). - It does not use
this.$on('beforeExit', ...)or anybeforeExithook.
Failure symptom: Deprecation/runtime errors in Prisma 5 when using beforeExit.
Reference: backend/prisma-service.md
3. Prisma client lifecycle
package.jsonincludes a script that runs Prisma client generation:- Either
"postinstall": "prisma generate"(ornpx prisma generate), - Or clear documentation to run
npx prisma generateafter install.
- Either
- After schema generation or change,
npx prisma generatehas been run (or will run via postinstall).
Failure symptom: Cannot find module '@prisma/client' or missing types at build/run.
4. Database migration
- Migration workflow is documented (e.g. in README or generation docs).
- Instruction to run
npx prisma migrate dev(orprisma migrate deployfor production) after first generation or schema change. - Generation pipeline (see
generation/backend-generation.md) includes or documents the migration step.
Failure symptom: Tables do not exist; Prisma errors on first query.
5. REST route parameters
- For each entity, path parameters use the correct primary key name from the DSL.
- Entity with PK
id(uuid): routes use/:id(e.g.GET /equipment/:id,PATCH /equipment/:id). - Entity with non-
idprimary key (e.g.code): routes use/:code(or the actual PK attribute name), e.g.GET /equipment-types/:code, notGET /equipment-types/:id.
Example:
| Entity | Primary key | Correct path | Incorrect path |
|---|---|---|---|
| Equipment | id | /equipment/:id | — |
| EquipmentType | code | /equipment-types/:code | /equipment-types/:id |
| RepairOrder | id | /repair-orders/:id | — |
Failure symptom: Controller expects params.id but route is defined with :code; or vice versa; 404 or wrong resource updated.
Reference: backend/architecture.md — API path rules for non-id primary keys.
6. DTO type mapping (serialization)
- DSL
decimal→ In DTO/API response, usestring(or a type that serializes to string), not PrismaDecimal, to avoid JSON serialization issues. - DSL
date→ In DTO/API response, usestring(ISO 8601) or ensure DateTime is serialized to string, so React Admin and JSON consumers receive a string.
Reference: backend/prisma-rules.md — DTO type mapping table.
7. React Admin ID field in API responses
- Every API response object (list items and single-resource GET) contains a field named
id. - If the entity primary key is not named
id, the response must map the primary key toid: e.g.id: record.codefor EquipmentType, so the payload includes bothidandcode(or at leastidwith the PK value). - The
idfield value must be the primary key value (string or uuid as appropriate).
Failure symptom: React Admin fails to identify records, breaks cache/references, or throws when expecting record.id.
Reference: frontend/react-admin-rules.md — React Admin ID Field Requirement.
8. Update payload sanitization (service layer)
- Update endpoint must not pass
id(or primary key) in Prismadata. The service must sanitize the incoming DTO before callingprisma.*.update({ where, data }): removeid, remove the entity primary key field (e.g.code), and remove any readonly attributes. Only updatable fields should be passed asdata. - Generated update methods follow the pattern from backend/service-rules.md (e.g.
const { id, code, ...data } = dtothen passdatato Prisma).
Failure symptom: Prisma throws when data contains id or another field that is not on the model or not writable (e.g. entity with PK code receives body with id from React Admin).
Reference: backend/service-rules.md
9. Database runtime (docker-compose)
docker-compose.ymlexists at the project root (or documented location).- It defines a PostgreSQL service with image (e.g.
postgres:16), port5432, and credentials/DB name matchingDATABASE_URLinserver/.env. - Database container starts:
docker compose up -druns without error and the container is reachable on the configured port.
Failure symptom: PrismaClientInitializationError P1001: Can't reach database server at localhost:5432.
Reference: backend/database-runtime.md
10. Migrations and seed
npx prisma migrate devruns successfully fromserver/when the database is up (schema is applied or created).- Seed script exists at
server/prisma/seed.ts(or equivalent) and creates minimal sample data (e.g. one EquipmentType, one Equipment, one RepairOrder). npx prisma db seedruns without error (package.json hasprisma.seedconfigured and seed runner installed).
Reference: backend/seed-rules.md, generation/runtime-bootstrap.md
11. Health endpoint
- Backend exposes GET /health (or equivalent health route).
- API responds to /health: With backend running,
GET http://localhost:<port>/healthreturns HTTP 200 and a body such as{ "status": "ok" }.
Reference: backend/architecture.md — Health Endpoint
Summary Table
| Check | Required artifact / rule |
|---|---|
| .env | File exists with DATABASE_URL |
| DATABASE_URL | Present in .env or .env.example |
| PrismaService | OnModuleInit + $connect(); no beforeExit |
| prisma generate | postinstall script or documented step |
| Migration | Documented step: prisma migrate dev |
| REST path params | Use entity PK name (:id or :code, etc.) |
| Decimal/Date in DTO | Map to string for serialization |
API response id |
Every record has id; if PK ≠ id, map PK → id |
| Update payload | Service strips id, PK, readonly from data before Prisma |
| docker-compose.yml | Exists at project root; PostgreSQL service |
| Database container | Starts with docker compose up -d |
| prisma migrate dev | Runs successfully from server/ |
| Seed script | Exists; prisma db seed runs |
| GET /health | Backend responds with 200 and status payload |
Integration with generation pipeline
- Backend generation (see
generation/backend-generation.md) should produce artifacts that satisfy the above by default. - After generation, run this checklist manually or via a script that parses generated code and config.
- If any check fails, the AI context or generator should be updated so that future runs pass.