api-contract-design
Skill3 starsChanged 10 days agoMITView on GitHub
Use this skill when freezing the interface between a backend and its clients before parallel work starts, or when changing an endpoint other code already calls - request/response shapes, status codes, error envelope, pagination, filtering, idempotency, versioning, and the breaking-change rules. Covers writing the contract as a checkable artifact so frontend, tests, and backend cannot drift.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- OugeX/dsh-web-dev-modetheir own version, first seen Nov 1, 2026
- dathuynh1108/agent-skillstheir own version, first seen Oct 11, 2026
- hemapriyan-rk/claude-rigor-skillstheir own version, first seen Sep 26, 2026
- LeonxLJX/web-engineer-skillstheir own version, first seen Sep 3, 2026
- 05-deepak-patidar/claude-skillstheir own version, first seen Jul 7, 2026
- MohOneX/claude-opus-skillstheir own version, first seen Jun 6, 2026
Used with
Projects with it also use testing-strategy.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
BlockSkilltesting-strategy
Guidelines for writing effective tests in this project
Also in 3 projects that use this
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- 05-deepak-patidar/claude-skills★ 4same name
- dathuynh1108/agent-skills★ 4same name
- hemapriyan-rk/claude-rigor-skills★ 1same name
- LeonxLJX/web-engineer-skills★ 0same name
- MohOneX/claude-opus-skills★ 0same name
- OugeX/dsh-web-dev-mode★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository72 other files it gives its agents.
- workflow/AGENTS.mdAGENTS.md
- docs/llms.txtllms.txt
- llms.txtllms.txt
- ai-video-prompt-engineerSkill
- api-hardeningSkill
- brainstormingSkill
- cavecrewSkill
- caveman-commitSkill
- caveman-compressSkill
- caveman-helpSkill
- caveman-reviewSkill
- cavemanSkill
- councilSkill
- database-migrationsSkill
- deep-researchSkill
- dependency-auditSkill
- deployment-patternsSkill
- e2e-testingSkill
- error-handlingSkill
- exa-searchSkill
- finishing-a-development-branchSkill
- frontend-securitySkill
- github-opsSkill
- graphifySkill
- graphyloop-wavesSkill
- graphyloop-workflowSkill
- gsap-coreSkill
- gsap-frameworksSkill
- gsap-performanceSkill
- gsap-pluginsSkill
- gsap-reactSkill
- gsap-scrolltriggerSkill
- gsap-timelineSkill
- gsap-utilsSkill
- high-end-visual-designSkill
- image-to-codeSkill
- last30daysSkill
- minimalist-uiSkill
- postgres-patternsSkill
- prisma-patternsSkill
- receiving-code-reviewSkill
- redesign-existing-projectsSkill
- remotion-video-creationSkill
- requesting-code-reviewSkill
- search-firstSkill
- secrets-hygieneSkill
- security-reviewSkill
- security-scanSkill
- short-video-productionSkill
- story-engineeringSkill
- supabase-setupSkill
- swarm-memorySkill
- systematic-debuggingSkill
- tdd-workflowSkill
- terminal-opsSkill
- threejs-animationSkill
- threejs-fundamentalsSkill
- threejs-geometrySkill
- threejs-interactionSkill
- threejs-lightingSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 79
Never return a 200 with {"success": false} — every caller then has to unwrap errors twice, and monitoring sees no failures.
- Very specific: line 81
Never leak stack traces, SQL, or internal ids (see api-hardening).
- Distinctive: line 108
Never break a contract mid-wave: if the implementation cannot honor it, stop and re-freeze with the integrator rather than silently …
- Very specific: line 120
If the API is public, the spec lints (npx @redocly/cli lint openapi.yaml).
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
API contract design
Parallel lanes fail at the seam: the backend returns {data: {...}}, the frontend
was written against {...}, and the tests mock a third shape. Freezing the contract
first is what makes wave-style parallel work safe (see graphyloop-waves) — this
skill is what "frozen" means in practice.
When to activate
- Wave 0 / contract stage of any feature with a backend and a client.
- Adding an endpoint, or changing one that already has callers.
- A field rename, a nullable-to-required change, an error-shape change.
- "The frontend is broken but the API works" — usually a contract drift.
The contract artifact
A contract is a file in the repo, not a paragraph in chat. One of:
- OpenAPI/JSON Schema (
openapi.yaml) — best when clients are generated from it. - A shared schema module (zod/valibot/pydantic) imported by both handler and client — the type checker becomes the enforcer.
- A typed client + a fixtures file consumed by the tests.
Whichever you pick, it must state per endpoint: method + path · auth + required role/scope · path/query params with types and defaults · request body schema · success status + response schema · every error status with its code · idempotency and rate-limit behavior. Anything not written down is not part of the contract and will be implemented differently by each lane.
Shapes and naming
- One envelope for the whole API, chosen once: either bare resources
(
{"id": ...}) or wrapped ({"data": ..., "meta": ...}). Mixing them per endpoint is the single most common drift. - Consistent casing (
snake_caseorcamelCase) across every payload — including nested objects and error fields. Pick one; a mapper at the boundary if the database disagrees. - Timestamps: ISO 8601 UTC strings (
2026-08-16T14:03:00Z). Money: integer minor units or a decimal string plus acurrency— never a float. Ids: string in JSON even when numeric in the database. - Nullable vs absent is a decision, not an accident: prefer explicit
nullfor "known empty", omit only for "not requested" (sparse fieldsets). - Collections always return an object, never a bare top-level array — you will need
to add
metalater, and an array cannot grow. - Enums are closed and documented; clients must tolerate an unknown value without crashing (render a fallback).
Status codes and errors
| Situation | Code |
| Read ok / update ok | 200 |
Created (add Location) | 201 |
| Accepted for async work | 202 |
| Deleted, nothing to return | 204 |
| Malformed syntax / unparsable | 400 |
| Not authenticated | 401 |
| Authenticated, not allowed | 403 |
| Missing, or hidden from this caller | 404 |
| Conflict: duplicate, version mismatch | 409 |
| Valid syntax, failed validation | 422 |
Rate limited (add Retry-After) | 429 |
| Server fault | 500 / 503 |
One error envelope for every failure, machine-readable first:
{ "error": { "code": "validation_failed", "message": "Human readable summary",
"details": [{ "field": "email", "code": "invalid_format" }],
"request_id": "req_01H..." } }codeis stable and switch-able by clients;messagemay change freely.- Never return a 200 with
{"success": false}— every caller then has to unwrap errors twice, and monitoring sees no failures. - Never leak stack traces, SQL, or internal ids (see
api-hardening). - The same validation failure returns the same code from every endpoint.
Collections: pagination, filtering, sorting
- Cursor pagination (
?limit=&cursor=) for anything that grows or reorders; offset (?page=&per_page=) only for small stable sets. Returnmeta: {next_cursor, has_more}— a total count only if you can afford the query. limithas a default and a hard maximum, both documented.- Filter and sort parameters are an allow-list of named fields
(
?sort=-created_at&status=open), never raw column names or expressions. - Empty result is
200with an empty list, not404.
Change rules (what breaks a client)
Safe (additive): new optional field in a response, new optional request field with a default, new endpoint, new enum value clients are told to tolerate, relaxed validation.
Breaking: removing/renaming a field, changing a type or casing, making an
optional request field required, tightening validation, changing a status code or
error code, changing pagination style, changing the envelope.
For a breaking change: version it (/v2/... or a header), keep the old path alive
with a deprecation window (Deprecation / Sunset headers, changelog entry),
migrate callers, then remove. Grep for callers first — rg -n "endpoint-path" across
the client, mobile app, tests, and any other service — and list them in the plan.
Never break a contract mid-wave: if the implementation cannot honor it, stop and
re-freeze with the integrator rather than silently shipping a different shape.
Verification
- Contract file committed before the parallel lanes start; every lane cites it.
- Handler validates against the same schema the client types come from (shared module, or generated client checked into CI).
- One test per endpoint asserting status + shape, plus one asserting the error envelope. Contract tests belong to the contract, not to the implementer.
curlthe real endpoint and diff the body against the contract for the fields that matter — types and casing included.- If the API is public, the spec lints (
npx @redocly/cli lint openapi.yaml).
Reporting
Name the contract file and commit, list endpoints with status codes, flag every breaking change with its affected callers, and state what the tests assert. If the implementation deviated from the frozen contract, report the deviation explicitly — an undocumented deviation is the failure this skill exists to prevent.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

