Skip to content

API Design Rules ​

These Accepted rules cover API contracts at different scopes. The scope column distinguishes framework-independent decisions from NestJS implementations. They complement the reactive, database, observability, and testing rules rather than replacing them.

Rules ​

RuleScopeDecision
001-business-oriented-api-design.mdGeneric APIDesign API operations around consumer use cases, not database tables.
002-rest-resource-and-response-views.mdPortable contract; implementation details are stack-specificKeep resource URLs stable and select supported collection representations with view.
003-response-dtos-and-reactive-projections.mdNestJS/RxJSClean and project raw data in typed business-service methods that return Observables.
004-nestjs-dto-validation-and-transformation.mdNestJS/TypeScriptUse project-owned DTO classes with NestJS ValidationPipe, class-validator, and class-transformer.
005-openapi-contracts-for-business-responses.mdPortable contract; NestJS toolingKeep request, response, view, and status contracts visible in OpenAPI.
006-backend-for-frontend-aggregation.mdNestJS/RxJS implementation; BFF principle is portable and latency targets are contextualAggregate repeated multi-service frontend workflows behind one API-owned route.
007-api-design-reference-conventions.mdGeneric REST APIUse versioned plural noun resources, lower camel case, documented query conventions, and precise HTTP methods and status codes.
008-cross-resource-data-access.mdPortable ownership principle; NestJS implementationAccess another resource through its owning service and use batch retrieval to avoid N+1 queries.

Relationship to Other Rules ​

  • Reactive programming defines the Observable boundary and service/controller lifecycle.
  • Database rules define persistence concerns. Database models MUST NOT become public API contracts automatically.
  • Observability rules define safe error and log handling.
  • Performance targets for materially different endpoint workloads and response shapes are project-specific; this skill has no shared performance rule set yet.
  • Testing rules define HTTP contract and E2E verification.

NestJS/TypeScript Design Checklist ​

  • [ ] The endpoint serves a documented business or frontend use case.
  • [ ] The response uses a project-owned DTO, not a persistence entity.
  • [ ] Collection views use the documented view enum when representations differ.
  • [ ] Business cleanup, composition, and derivation happen in a service.
  • [ ] The controller selects the use case and returns its Observable without a manual subscription.
  • [ ] Request DTOs use class-validator and NestJS ValidationPipe.
  • [ ] class-transformer behavior is explicit for transformation or serialization.
  • [ ] OpenAPI documents the request, response, view options, and status codes.
  • [ ] Each materially different response shape is tested and measured.
  • [ ] A frontend workflow that needs data from roughly 3-4 business services has been reviewed for an API-owned aggregate route.
  • [ ] An aggregate route has one owner, one public DTO, explicit authorization and failure behavior, and parallel reactive composition where safe.
  • [ ] Aggregate request and dependency latency are observable and measured against the applicable performance target.

You own what ships.