Never let your API drift from your database schema again. Living Contracts watches your Prisma schema and automatically generates type-safe APIs, SDKs, validation rules, and documentation that evolve with your data.
Every TypeScript developer knows this pain:
// Monday: Backend updates the schema
model User {
username String
email String
phoneNumber String? // NEW FIELD
}
// Wednesday: Frontend breaks in production
// TypeScript types? Outdated.
// API docs? Still showing old schema.
// Validation? Rejecting the new field.graph TD
subgraph "Day 1: In Sync"
DB1[Database] <--> API1[API] <--> FE1[Frontend]
end
subgraph "Day 30: The Drift"
DB2[Database] -- "Schema Change" --> API2[API]
API2 -. "Broken Contract" .- FE2[Frontend]
style API2 stroke:#f00,stroke-width:2px
style FE2 stroke:#f00,stroke-width:2px
end
Living Contracts creates a living connection between your database and your entire API surface:
npx living-contracts watch
β¨ Watching schema.prisma...
π Schema change detected!
π Regenerating TypeScript SDK...
π Updating API endpoints...
π Learning validation rules from data...
π Updating documentation...
β
Everything in sync!Instead of guessing validation rules, Living Contracts learns from your actual data:
// Analyzes your database and discovers:
username: string // 4-28 chars, lowercase, allows underscores
email: string // valid emails, max 255 chars
price: number // 0.99-9999.99, always 2 decimal placesKnow exactly what breaks before you deploy:
β οΈ Breaking Change Detected!
Field renamed: username β userName
Affected:
- 17 API endpoints
- 43 frontend components
- 3 mobile apps
π Migration guide generated with AI assistance
- TypeScript SDK - Type-safe client with perfect IntelliSense
- API Endpoints - REST/GraphQL endpoints that match your schema
- Validation - Zod schemas based on real data patterns
- Documentation - Always current, never lies
- Tests - Generated from actual usage patterns
# Install globally
npm install -g living-contracts
# Or use npx
npx living-contracts init# In your Prisma project
living-contracts init
# Start watching for changes
living-contracts watch// Import your auto-generated, type-safe SDK
import { api } from './generated/sdk'
// Perfect IntelliSense, always up-to-date
const user = await api.users.create({
username: 'alice', // β
Validates: 4-28 chars
email: '[email protected]',
phoneNumber: '+1234567890' // β
New field already typed!
})graph TD
A[schema.prisma] -->|Parse| B(Schema Parser)
C[Database Data] -->|Analyze| D(Validation Inference)
B --> E{Code Generator}
D --> E
E --> F[Generated SDK]
E --> G[API Endpoints]
E --> H[Zod Schemas]
E --> I[Documentation]
- Watches your Prisma schema for changes
- Analyzes your actual database data to infer patterns
- Generates everything you need for a type-safe API
- Detects breaking changes before they break
- Guides migrations with AI-powered suggestions
classDiagram
class CLI {
+generate()
+watch()
}
class SchemaParser {
+parse(schemaPath)
}
class InferenceEngine {
+inferRules(data)
+detectPatterns()
}
class Generators {
+SdkGenerator
+ApiGenerator
+ValidationGenerator
+DocsGenerator
}
CLI --> SchemaParser : Uses
CLI --> InferenceEngine : Uses
CLI --> Generators : Orchestrates
InferenceEngine ..> Generators : Feeds Rules
living-contracts init # Initialize in your project
living-contracts generate # One-time generation
living-contracts watch # Watch mode (recommended)
living-contracts validate # CI/CD validation
living-contracts analyze # Analyze data patterns.living-contracts.json:
{
"output": "./generated",
"generators": ["sdk", "api", "validation", "docs"],
"watch": true,
"inferValidation": true,
"ai": {
"provider": "openai",
"model": "gpt-4"
}
}generated/
βββ sdk/
β βββ index.ts # Type-safe client
β βββ types.ts # Generated TypeScript types
β βββ client.ts # API client with React Query hooks
βββ api/
β βββ users.ts # User endpoints
β βββ [...].ts # Other model endpoints
βββ validation/
β βββ schemas.ts # Zod validation schemas
βββ docs/
βββ api.md # Auto-generated API documentation
// .living-contracts.config.ts
export default {
generators: {
custom: async (schema, data) => {
// Your custom generation logic
}
}
}{
"hooks": {
"beforeGenerate": ["npm run lint:fix"],
"afterGenerate": ["npm run test:generated"]
}
}living-contracts generate --schema ./tenant1/schema.prisma
living-contracts generate --schema ./tenant2/schema.prisma- TypeScript SDK generation
- Validation inference from data
- Breaking change detection
- GraphQL support
- Python/Go/Java SDKs
- VS Code extension
- GitHub Actions integration
- Team collaboration features
We love contributions! Please see our Contributing Guide for details.
# Clone the repo
git clone https://github.com/yourusername/living-contracts
cd living-contracts
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run buildTraditional API contracts are static documents that drift from reality. Living Contracts are alive - they grow and evolve with your application, always reflecting the truth of your data.
MIT Β© 2025
Built with β€οΈ by developers who were tired of API drift.