How coobaha/typed-fastify works
Main Components
a) Core Components:
• Schema Definition Layer
• Type Inference Engine
• JSON Schema Generator
• Runtime Validation Layer
• Fastify Integration Layer
b) Supporting Components:
• CLI Tool (tfs)
• Watch Mode System
• Documentation Generator
┌─ Application Layer ─────────────────┐
• User's Fastify Application │
• ┬───────────────────┘
• ↓
┌─ Typed Fastify Layer ──────────────┐
• ┌─────────────┐ ┌────────────┐ │
• Schema │←→│ Type │ │
• Definition │ │ Inference │ │
• ┘ └────────────┘ │
• ↓ ↓ │
• ┌─────────────┐ ┌────────────┐ │
• JSON Schema │←→│ Runtime │ │
• Generator │ │ Validation │ │
• ┘ └────────────┘ │
• ┬───────────────────┘
• ↓
┌─ Fastify Layer ──────────────────┐
• Fastify Framework │
• ┘
Key Interactions to Highlight
a) Development Time Flow:
• TypeScript Schema Definition → Type Inference
• TypeScript Schema → JSON Schema Generation
• CLI Tool interaction with Schema Generation
b) Runtime Flow:
• Request → Schema Validation
• Response → Type Checking
• Runtime Validation → Fastify Integration
Important Details
a) Type System Components:
• Request handling (body, headers, querystring, params)
• Response handling (status-based typing)
• Path parameter inference
b) Schema Generation:
• typescript-json-schema integration
• Custom transforms
• @tjs annotations support
┌─ CLI Tools ──────────────┐
• ┌─────────┐ ┌─────────┐ │
• tfs │ │ Watch │ │
• gen │ │ Mode │ │
• ┘ └─────────┘ │
• ┘
Implementation Notes
• Small annotations explaining key transformations
• Version information and compatibility notes