How eggjs/egg works
Main Components Identification
The system architecture should highlight these key components:
a) Core Framework Layer:
• Application (lib/application.js)
• Agent (lib/agent.js)
• Core Utilities (lib/core/*)
• Loader System (lib/loader/*)
b) Middleware Layer:
• Built-in middlewares (app/middleware/*)
• Security
• Body Parser
• Session
• Static Files
c) Extension Layer:
• Context Extensions (app/extend/*)
• Application Extensions
• Request/Response Extensions
• Helper Extensions
d) Plugin System:
• Plugin Loader
• Plugin Registry
• Custom Plugins
Relationship Flows
Key interactions:
a) Request Flow:
• HTTP Request → Middleware Chain → Router → Controller → Service → Response
b) Lifecycle Flow:
• Master Process → Agent Workers → App Workers
• Plugin Loading → Config Loading → Application Initialization
Architectural Patterns
Patterns:
• MVC Architecture (Controller/Service/Model)
• Plugin-based Extension System
• Multi-process Model
• Middleware Pipeline
• Blue: Core Framework Components
• Green: Middleware Layer
• Yellow: Extension System
• Orange: Plugin System
• Gray: External Systems/Interfaces
• Rectangles: Major Components
• Hexagons: Plugins
• Diamonds: Decision Points
Key Sections
a) Process Architecture:
Master Process
• Agent Worker(s)
• App Worker(s)
b) Request Pipeline:
Request → Middleware → Router → Controller → Service → Response
c) Plugin System:
Framework
• Built-in Plugins
• Framework Plugins
• Application Plugins