Adding an endpoint
The steps from a model to a contract, a repository method and a service handler, with Todo as the reference.
Todo is the reference: models/todo-model, contracts/todo-contracts, domains/todo-domain and services/todo-service.
- Add portable resource fields to
models/<x>-model, keeping IDs and dates serialized. - Add or extend the procedure in
contracts/<x>-contracts, composing model schemas andlibs/contract-kitconventions. New public error codes go inmodels/app-error-model. - Add the repository method in the owning
domains/<x>-domainpackage (<x>.repository.tsand its Mongoose schema). Thedomain-repository-testsskill covers its tests. - Implement the handler in
services/<x>-service/src/lib/handlers/, wired throughimplement(contract).$context<RequestContext>()and guarded byrequireRole(...)fromlibs/authwhere needed.- A workspace-scoped procedure declares
intentin its contract.meta()instead, and goes throughcreateRequireIntent. Intents andROLE_INTENTSlive inmodels/workspace-model. - A procedure that changes something also declares
audit: { action, changes?, target? }besideintent. ThecreateAuditMiddlewarefromdomains/audit-domain, placed before the intent guard, records it. Actions live inmodels/audit-model. - The
service-handler-testsandapi-endpointsskills cover the tests and the generated spec. - Public or abuse-prone procedures get a
rateLimitmeta in the contract (libs/rate-limit). Todocreateis the example.
- A workspace-scoped procedure declares
- Typecheck and test the affected layers, then check the generated spec at
/docs. - Update the docs in the same change, following the table in AGENTS.md.