{"success":true,"name":"write-the-api-contract-down-where-both-sides-can-read-it-bef","description":"Frontend and backend of a feature are built separately with no written endpoint spec","category":"ai-brimind","path":"ai-brimind/write-the-api-contract-down-where-both-sides-can-read-it-bef/SKILL.md","file":"SKILL.md","content":"---\nname: write-the-api-contract-down-where-both-sides-can-read-it-bef\ndescription: \"Frontend and backend of a feature are built separately with no written endpoint spec\"\n---\n\n# Write the API Contract Down Where Both Sides Can Read It — Before the Frontend Guesses\n\n## When to use\nA feature spans frontend and backend (possibly built at different times, by different people, or by different AI sessions), and the endpoints' shapes — paths, params, request bodies, response fields, error codes — exist only in the head or the code of whoever wrote the backend.\n\n## Example request\nFrontend expects { data: { clubs: [...] } } while the backend sends { clubs: [...] } → an hour lost debugging a 'broken' feature that was really two teams guessing differently; a five-line written contract would have cost two minutes. A field is named 'createdAt' in one endpoint and 'created_at' in another → every screen needs special-case mapping; contracts reviewed side by side expose naming drift before it ships. The backend changed a response shape and nothing documented who consumes it → three screens break silently; the contract file is also the list of promises you cannot break casually. A solo dev 'who remembers everything' → returns after three weeks and remembers nothing; the contract is a letter to future-you, and to the next AI session that must call these endpoints correctly.\n\n## Instructions\nAct as the diplomat between two nations — frontend and backend — who knows that wars between them never start from malice, only from each side assuming what the other meant; the treaty must be written, or every integration becomes archaeology through someone else's code. For any feature spanning the API boundary, do this: (1) Before or while building the backend, write the contract in a place both sides read — a simple markdown file in the repo per feature or one api-contract doc is enough at small scale; the format matters less than its existence. For each endpoint: method and path, params/query, request body shape with types, the success response shape with REAL example JSON, and the possible errors with their status codes per your error contract. Example JSON beats prose — 'returns the club object' says nothing; a pasted sample says everything. (2) Make the contract the reference the frontend codes AGAINST, instead of reading backend source or guessing from one lucky response: field names, nesting, and types come from the doc, and discrepancies discovered while coding are fixed IN THE DOC first, then in code — the doc is the truth, code is its implementation. (3) Review new contracts against existing ones for two minutes before building: naming conventions consistent (camelCase everywhere? 'id' vs '_id'?), pagination shaped like the other paginated endpoints, errors speaking the shared error contract — this cheap glance is where drift dies. (4) Treat the written contract as the list of promises your API-evolution discipline protects: anything in the doc has consumers, so changes to it trigger the deprecation thinking, not silent edits. (5) Keep it honest: when reality and doc diverge, updating the doc is part of the change, not optional cleanup — a stale contract is worse than none because it is trusted. Only start frontend work once the contract for the endpoints exists and one example request/response pair is written for each — ten minutes of writing that replaces the classic afternoon of 'why is this undefined', because 'undefined' is almost always just two sides of one API disagreeing about a name.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #225\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}