Skip to Content
gentlemans-stack

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.

The five steps: model, contract, repository method, handler, docs

  1. Add portable resource fields to models/<x>-model, keeping IDs and dates serialized.
  2. Add or extend the procedure in contracts/<x>-contracts, composing model schemas and libs/contract-kit conventions. New public error codes go in models/app-error-model.
  3. Add the repository method in the owning domains/<x>-domain package (<x>.repository.ts and its Mongoose schema). The domain-repository-tests skill covers its tests.
  4. Implement the handler in services/<x>-service/src/lib/handlers/, wired through implement(contract).$context<RequestContext>() and guarded by requireRole(...) from libs/auth where needed.
    • A workspace-scoped procedure declares intent in its contract .meta() instead, and goes through createRequireIntent. Intents and ROLE_INTENTS live in models/workspace-model.
    • A procedure that changes something also declares audit: { action, changes?, target? } beside intent. The createAuditMiddleware from domains/audit-domain, placed before the intent guard, records it. Actions live in models/audit-model.
    • The service-handler-tests and api-endpoints skills cover the tests and the generated spec.
    • Public or abuse-prone procedures get a rateLimit meta in the contract (libs/rate-limit). Todo create is the example.
  5. Typecheck and test the affected layers, then check the generated spec at /docs.
  6. Update the docs in the same change, following the table in AGENTS.md.