← all devlogs
Engineering·2026-09-05·5 MIN READ

Type Sharing in Monorepos: The Schema-as-Contract Pattern

Why treating your database schema as the source of truth for TypeScript types eliminates an entire class of integration bugs across web, mobile, and API.

The most expensive bugs in multi-surface apps aren't logic errors — they're drift errors. The mobile app sends a field the API renamed. The web app reads a field the backend stopped returning.

The pattern

Generate types from your schema (Prisma, Zod, OpenAPI) and import them everywhere.

// Generated by Prisma, imported by web, mobile, and API
import type { Article } from "@repo/types";

What it eliminates

  • Runtime errors from mismatched field names
  • Manual type updates that miss a surface
  • "It works on my machine" integration issues

When it breaks

The pattern fails if you hand-write types in one surface. The fix is a lint rule or CI check that surfaces can't define their own copy of shared types.

TypeScriptMonorepoArchitecture