How hummingbird-project/hummingbird works
Project type and purpose
• This is a modular Swift server framework (Hummingbird). It is not a monolithic full-stack application but a library/framework built on top of SwiftNIO to provide HTTP server functionality, routing, middleware, TLS, HTTP/2, codable support, testing, and benchmarks.
• The README confirms it is a “lightweight, flexible modern web application framework” with built-in extensions (router, TLS, HTTP/2, testing) and a minimal core.
File structure
• Top-level directories:
• Sources: multiple modules: Hummingbird (high-level API), HummingbirdCore (NIO integration), HummingbirdHTTP2, HummingbirdTLS, HummingbirdRouter, HummingbirdTesting, PerformanceTest
• Tests: unit tests for each module
• Benchmarks: performance tests for routing
• docker, scripts: environment setup and CI scripts
• Patterns:
• Layered architecture: Application → Router → Middleware → Core HTTP server → NIO
• Extension modules plugged into the core (router, HTTP/2, TLS)
• Middleware pipeline pattern
• Adapter pattern for storage drivers
README for additional insights
• The user code instantiates a Router, configures routes, creates an Application with address configuration, and runs runService()
• It describes built-in and external extensions, highlighting the plug-in architecture
Detailed breakdown
• Layer 2: Network/TLS
• HummingbirdTLS.TLSChannel (encrypt/decrypt)
• Layer 3: Transport
• HummingbirdHTTP2.HTTP2Channel & HummingbirdCore.Server HTTP1Channel
• Layer 4: Core Server
• HummingbirdCore.ServerBuilder → RequestResponder
• Layer 5: Middleware
• LogRequestMiddleware → CORSMiddleware → FileMiddleware → MetricsMiddleware → TracingMiddleware
• Layer 6: Router
• Hummingbird.Router / HummingbirdRouter.RouterBuilder / TrieRouter
• Layer 7: Handlers
• User-defined GET /hello, etc.
• Layer 8: Codable
• JSONCoding & URLEncodedFormEncoder/Decoder
• Layer 9: Storage
• MemoryPersistDriver or custom PersistDriver
• Layer 10: Utils (ByteBuffer+foundation, DateCache, HexDigest)