API & Interface Design
Overview
Define the contract before the implementation. A good interface is predictable, hard to misuse, and validated at its edges.
When to use
- New or changed endpoints, SDK surfaces, or cross-module interfaces.
- Establishing conventions for a service or library.
Process
- Model the resource/operation — nouns and verbs, not incidental implementation.
- Specify the contract first (OpenAPI/types/schema): inputs, outputs, status/error codes.
- Validate at the boundary — reject malformed input early; never trust callers.
- Be consistent — naming, pagination, filtering, errors, and auth follow one convention.
- Design errors — typed, actionable, with stable codes; don't leak internals.
- Plan versioning & compatibility — additive changes; deprecate, don't break (see
deprecation-and-migrationif it existed, else document the migration). - Document alongside the contract; add tests for the contract.
Red flags
- Leaking database shapes or internal enums through the public surface.
- Inconsistent error formats across endpoints.
- Booleans/flags that should be explicit states; over-broad "do everything" endpoints.
- Breaking changes shipped without a version or deprecation path.
Verification
- The contract is written and validated; invalid input is rejected with typed errors.
- A new consumer can integrate from the contract alone, without reading the implementation.
Reference Index
references/expanded-guidance.md— deeper API/interface design principles, examples, and compatibility guidance.