How shelepuginivan/lunatic works
Main Components
a) Core Components:
• Server Component
• Router Component
• Request/Response Handlers
• Middleware System
• Type System
b) Built-in Middlewares:
• Body Parser
• Cookie Parser
• CORS Handler
• Form Parser
• Static File Server
• Not Found Handler
┌─ Application Layer ─────────────────────┐
• User Application Code │
• Framework Core ──────────────────────┬─┤
• ┌─────────────┐ ┌──────────────┐ │ │
• Server │◄───┤ Router │ │ │
• ┘ └──────────────┘ │ │
• ▲ ▲ │ │
• ┌─────────────┐ ┌──────────────┐ │ │
• Request │ │ Response │ │ │
• ┘ └──────────────┘ │ │
• Middleware Layer ───────────────────┤ │
• ┌─────────┐ ┌────────┐ ┌─────────┐ │ │
• Body │ │ Cookie │ │ CORS │ │ │
• Parser │ │ Parser │ │ Handler │ │ │
• ┘ └────────┘ └─────────┘ │ │
• ┌─────────┐ ┌────────┐ ┌─────────┐ │ │
• Form │ │ Static │ │ 404 │ │ │
• Parser │ │ Server │ │ Handler │ │ │
• ┘ └────────┘ └─────────┘ │ │
• Utilities ────────────────────────┬─┤ │
• ┌─────────┐ ┌────────┐ ┌────────┐ │ │ │
• MIME │ │ Path │ │ Other │ │ │ │
• Types │ │ Utils │ │ Utils │ │ │ │
• ┘ └────────┘ └────────┘ │ │ │
• ┘
Important Elements to Highlight
a) Request/Response Flow:
• How requests enter the system
• Middleware chain execution
• Demonstrate response generation and return path
b) Type System Integration:
• TypeScript interfaces and types
• Relationship between types and components
c) Middleware Pipeline:
• Demonstrate the sequential nature of middleware execution
• How middleware can be plugged into the system
Implementation Details
• HTTP method handlers (GET, POST, PUT, DELETE, PATCH)
• Static file serving capabilities
• Body parsing and form handling
• CORS configuration options
• Cookie management