Register all active platform services and base features in core DB so admin can manage them, add delivery/hospitality/sports-center backend phases, update apps catalog and production deploy tooling. Co-authored-by: Cursor <cursoragent@cursor.com>
4.1 KiB
4.1 KiB
API Template
REST / DTO / validation / versioning / error / OpenAPI standards for service APIs.
Short contract form: templates/api-template.md.
Enterprise default: mandatory-phase-artifacts.md · definition-of-done.md.
REST Standards
| Rule | Detail |
|---|---|
| Prefix | /api/v1 for public service APIs |
| Resources | Nouns; plural collections (/programs, /leads) |
| Methods | GET read · POST create/actions · PATCH/PUT update · DELETE remove/archive as designed |
| Auth | JWT (and documented internal tokens); deps in api/deps.py |
| Tenant | X-Tenant-ID (and documented alternatives); reject when missing on tenant routes |
| Pagination | Shared page meta pattern — required on collection list endpoints |
| Filtering | Query params for common attributes — required when lists are filterable |
| Sorting | Stable sort keys documented — required on collection lists |
| Searching | Text/search params when users must find by name/code/etc. |
| Thin routers | Validate → authorize → command/query/service call → map response |
Operational & Capability Surfaces
| Endpoint | Purpose | Required |
|---|---|---|
GET /health |
Liveness / basic readiness signal | Every runnable service |
GET /capabilities |
Feature/channel/bundle discovery | Platform / discoverable services |
GET /metrics |
Operational metrics | Prefer yes; else justified N/A |
| Permission routes / registry | List or document {service}.* tree |
Privileged services |
OpenAPI Documentation
- FastAPI-generated OpenAPI must include all new/changed public routes before Complete.
- Operation summaries, response models, and error shapes should be accurate.
- Export or link OpenAPI in service README / reference docs when contracts stabilize.
- Undocumented public routes fail the API Completeness gate (quality-gates.md).
DTO Rules
- Pydantic schemas in
app/schemas/—Create,Update,Read,Listsuffixes. - Never expose password hashes, provider secrets, or internal tokens.
- Do not return ORM models directly from routers.
- External refs are explicit fields (
crm_contact_ref, etc.). - Document breaking field changes in phase handover.
- List responses include page metadata (items + total/page/size or cursor as per service pattern).
Validation Rules
- Request body/query validated by Pydantic.
- Domain rules enforced in services/validators/policies/specs — not only at the edge.
tenant_idin body does not override resolved tenant context.- Path IDs are UUIDs/strings as per service; always combined with tenant scope server-side.
Versioning
- Current public version:
v1. - Additive changes preferred within
v1. - Breaking changes require a new version path (
/api/v2) or a documented migration window in the phase. - Deprecated fields remain until the compatibility gate allows removal.
Error Responses
- Use shared exception types / stable
error_codevalues. - Map to appropriate HTTP status: 400 validation · 401 auth · 403 forbidden · 404 not found · 409 conflict · 422 domain · 429 rate limit · 500 unexpected.
- Do not leak stack traces or secrets in production payloads.
- Document new error codes in the phase API section.
Endpoint Documentation Block
| Method | Path | Description | Auth / Permission |
| --- | --- | --- | --- |
| POST | /api/v1/example | Create example | JWT + `service.example.create` |
Also update api-reference.md / services-contracts.md when the phase publishes stable contracts.