Generated the API contract from the database out
Generated the API contract outward from the database — OpenAPI, a
44,076‑line typed TypeScript client, 61 mock handlers and the limits
the UI enforces — with a guard at every hop that fails on drift.
2025

Situation. Frontend and backend move at their own pace, and their
assumptions about a request payload can drift apart without anyone
noticing. The way you usually find out is a 422 in the browser —
after the mismatch has already shipped, which is the most expensive
moment to learn about it. Writing the two sides by hand from the
same document does not fix it; it just moves the drift to whoever
forgot to reread the document.

Task. The two sides had to be generated from one source rather than
agreed between two, with every step of the generation checked
instead of trusted.

Action. The chain starts at the database and runs outward. The
schema and its functions define the shapes; the Go types define the
API; Huma emits the OpenAPI description from those; a typed
TypeScript client — 44,076 lines of it — is generated from that
description; 61 mock handlers are generated alongside it so the
frontend's own tests run against the real contract rather than a
hand‑written fixture; and the limits the UI enforces on a form come
from the same place instead of being retyped into a validator. Every
hop has a guard. A contract check in CI compares what the frontend
sends against what the API expects and fails the build on
divergence, with a schema probe underneath it that checks the real
shapes rather than a description of them. It deliberately covers
where drift likes to hide: optional body fields, where "missing" and
"null" get confused, and query‑parameter enums, where the two sides
can quietly disagree on the allowed values.

Result. A field cannot change on one side only — it fails at the
first hop that notices, in a build, minutes after the change. That
took out a recurring and genuinely annoying class of bug, the kind
invisible in code review that only shows up at runtime. The cost is
a generation step in the middle of everything: regenerating is a
chore, and the chain is only as trustworthy as its least‑guarded
link, which is why each hop got one.

Categories:
1Backend Engineering	/categories/backend/	engineer.company	70
1APIs & Integration	/categories/api/	engineer.company	70
1DevOps	/categories/devops/	engineer.company	70
1Automation & CI/CD	/categories/automation/	engineer.company	70
1Reliability & Backups	/categories/reliability/	engineer.company	70
1Testing & QA	/categories/testing/	engineer.company	70

Services:
1Backend & API Development	/services/backend-development/	engineer.company	70
1AI Agent Tools & MCP Servers	/services/ai-tools/	engineer.company	70
1DevOps & CI/CD Automation	/services/devops-cicd/	engineer.company	70

hThis page on the web	URL:https://engineer.company/portfolio/generated-the-api-contract-from-the-database-out/	engineer.company	70
