How kludex/mangum works
Main Components
• ASGI Application – At the core, there is an ASGI application that defines application behavior (as shown in the README examples). This external component is what gets “adapted.”
• Mangum Adapter – The main entry point that wraps the ASGI app and converts AWS Lambda events to the ASGI format. The file mangum/adapter.py is a central piece.
• Event Handlers – Located under mangum/handlers, these modules (e.g., for API Gateway, ALB, Lambda@Edge) represent distinct event sources. They encapsulate the conversion logic from each AWS event type.
• Protocol Handlers – Inside mangum/protocols, you have modules for HTTP and Lifespan protocol management. These ensure that HTTP requests and lifespan events (startup/shutdown) are properly managed.
• Exceptions and Types – The modules (like mangum/exceptions.py and mangum/types.py) support the adapter’s error handling and type declarations.
• Testing & CI/CD – The tests directory and CI configurations (in .github/workflows) support code quality and testing pipelines. Although not directly part of runtime architecture, they show how the project ensures correctness.
• Documentation and Deployment Tools – The docs and scripts directories indicate there is a documented structure as well as automation for linting, testing, and building documentation.
Mapping Out Interactions and Relationships
• Receiving the event.
• Converting the event into a format understood by the adapter.
• From the Event Handlers, show the flow to the Mangum Adapter (mangum/adapter.py), which then calls the ASGI application.
• Within the adapter logic, include interactions with designated Protocol Handlers:
• The HTTP protocol module (mangum/protocols/http.py) manages the HTTP aspects of the request/response cycle.
• The Lifespan protocol (mangum/protocols/lifespan.py) manages application startup and shutdown events.
• Optionally, include a side note showing external integration with deployment tools like Serverless Framework and AWS SAM, which would be used to deploy the entire Lambda + ASGI setup.
Apply Architectural Design Principles
• Adapter Pattern – Emphasize that Mangum acts as an adapter, converting between AWS Lambda event formats and the ASGI specification.