19 lines
959 B
Text
19 lines
959 B
Text
---
|
|
description: Constants and shared elements synchronization between backend and frontend
|
|
alwaysApply: false
|
|
---
|
|
# Backend-to-Frontend Synchronization
|
|
|
|
The backend is the source of truth. Frontend types and constants are generated/validated from backend definitions.
|
|
|
|
## Two Mechanisms
|
|
|
|
1. **OpenAPI → TypeScript**: API response types are generated from FastAPI's OpenAPI schema using `openapi-typescript`. Regenerate with `make generate-types-standalone` after changing Pydantic schemas.
|
|
|
|
2. **Shared Constants**: `shared/constants.json` holds values needed by both sides (roles, statuses, validation rules). Backend validates this file matches its definitions at startup.
|
|
|
|
## Key Principle
|
|
|
|
Never manually define types or constants in the frontend that originate from the backend. Import from `generated/api.ts` or `shared/constants.json` instead.
|
|
|
|
See `Makefile` for sync commands (`generate-types-standalone`, `check-types-fresh`, `check-constants`).
|