Type Flow Overview
Compile Time
Type checking with TypeScript - Prevent errors during development
Runtime
Actual data validation with Zod - Block invalid data
Database
PostgreSQL constraints - Guarantee data integrity
API Boundary
Request/Response validation - Safe data exchange
Layer-by-Layer Type Safety
1. Entity β TypeScript
Entity definitions are converted to TypeScript types.2. Entity β Zod Schema
Entity definitions are converted to Zod schemas for runtime validation.3. Entity β PostgreSQL
Entity definitions are converted to PostgreSQL table schemas.API Layer Type Safety
Model β API Client
Model methods are converted to type-safe API clients.Request Validation
API requests are automatically validated with Zod schemas.In Fastify router
Response Types
API responses are also type-safe.TanStack Query Type Safety
TanStack Query hooks also provide complete type safety.Subset Type Safety
Subset queries also provide complete type inference.Full Stack Type Flow Example
Shows how types flow in actual CRUD operations.Preventing Type Mismatches
Sonamuβs E2E type safety prevents common type mismatch issues.API Response Type Mismatch
API Response Type Mismatch
Problem: API returns different type than expectedSonamu Solution:
Request Parameter Mismatch
Request Parameter Mismatch
Problem: Client sends wrong parametersSonamu Solution:
Enum Value Mismatch
Enum Value Mismatch
Problem: Hardcoded string doesnβt match EnumSonamu Solution:
Missing Nullable Handling
Missing Nullable Handling
Problem: Using nullable field without null checkSonamu Solution: