Direct answer
AI coding tools write the frontend, the backend and the database in separate sessions, and nothing forces those pieces to agree. One prompt renames a field, another changes an enum value, a third edits a table, and each side still looks correct on its own. The fix is to keep one schema as the source of truth, generate types and clients from it, validate data where it crosses a boundary, and run a contract test in CI so drift fails a build instead of a user’s request.
Why drift is the default in AI-built code
A human developer who renames a field usually remembers the screen that sends it. An AI assistant working in one file at a time does not, and it will happily invent a plausible shape for data it has never seen. Prototypes hide the gap because demo data is shaped to match whatever the screen expects, and empty test fixtures pass every check.
In the production issues we reviewed across about 25 projects in October, contract and schema drift between frontend, backend, database and copies of the codebase appeared in five of them.
Four cases we worked on
- A visa paperwork app failed at the last step. The frontend posted its form data in its own field names and used a short label for the case type, while the backend’s model expected different names and a longer label. Users saw “Package generation failed” with a 422 behind it. Sending null where the model required an empty object failed the same way. The fix mapped form data to the backend’s shape in one place and surfaced the actual validation error.
- A broker dashboard rejected every real response. An audit found the backend returned snake_case names and numeric IDs, while the frontend validated responses against a schema expecting camelCase names and string IDs. Every non-empty response failed validation and showed an error state. Tests passed because they used empty arrays. The same audit found queries referencing columns that did not exist in the migrated schema.
- A booking marketplace kept three copies of one constant. The current terms-of-service version was hard-coded in three separate functions, so updating one would silently break the consent check in the others. It now lives in one shared module that every function imports.
- A content pipeline had its schemas overwritten by a copy. A recursive sync of tooling files clobbered seven per-content-type schema files with another copy’s versions. Syncs now use a per-file allowlist, and every artifact passed between steps is parsed against a schema before it is written.
Make one schema the source of truth
Pick one place where the contract lives and generate everything else from it. For HTTP APIs, that is usually an OpenAPI document. The OpenAPI Specification describes itself as a language-agnostic interface description that tooling can use to generate servers, clients and tests. For apps built on Supabase, the database is the contract: Supabase’s guide to generating TypeScript types explains that its APIs are generated from the database, so the CLI can produce types from the live schema, and it shows a GitHub Action that keeps them updated.
The rule that matters is direction. Change the schema, regenerate, and let the compiler show you every caller that broke. Never hand-edit a generated file, and never let a new feature skip the spec “just this once.” In one coaching marketplace we reviewed, newer features called the API with hand-written requests that bypassed the generated client, so the spec described only half the app.
Validate at the boundary, strictly
Types disappear at runtime, so check data where it enters: request bodies on the server, responses in the client. Choose the strictness on purpose. Zod’s documentation notes that by default an object schema strips unrecognized keys from the parsed result, and that z.strictObject throws on them instead. Stripping is convenient until a field the frontend relies on vanishes without an error. Strict parsing at the boundary turns a silent drop into a visible failure, which fits the wider rule from our piece on fake success in AI-built apps.
Convert naming styles in one place. If the database uses snake_case and the UI uses camelCase, write one serializer, not a conversion in every component.
Put a contract test in CI
A type check proves the code agrees with the generated types. It does not prove the generated types agree with the running system. Add a test that does:
- Regenerate and diff. In CI, regenerate types from the schema and fail the build if the committed files differ.
- Run migrations, then query. Apply every migration to a disposable database and run the real queries against it, so a missing column fails the build.
- Test with real shapes. Feed the client’s validators a representative, non-empty response from the actual backend. Empty fixtures prove nothing.
- Keep one copy. If the codebase exists in several folders or branches, decide which one ships and delete or archive the rest.
Our Production Readiness Standard covers the rest of what we check before launch.
Related Zenveus services: AI Prototype Hardening, the Fix it lane and the 48-Hour Verdict