How maua-dev/epep_api works
Purpose and Runtime
This is a Python Clean Architecture template for stateless AWS Lambda microservices. The included reference domain is user CRUD: create, retrieve one/all, update, and delete. Application dependencies are declared in requirements-app.txt; runtime environment selection is centralized in src/shared/environments.py.
Invocation and Request Boundary
Lambda-oriented HTTP request/response abstractions and authorization helpers form the outer boundary:
• src/shared/helpers/external_interfaces/http_lambda_requests.py
• src/shared/helpers/external_interfaces/http_models.py
• src/shared/helpers/auth/authorizer_user.py
Handlers are wrapped for shared observability behavior via src/shared/helpers/observability/wrap_handler.py. IAM policy construction is isolated in src/shared/helpers/auth/iam_policy.py, allowing API-facing authentication/authorization concerns to remain outside use cases.
Feature Modules: Controller → Use Case → Presenter
Each operation is independently organized under src/modules/<operation>/app, separating input orchestration, business execution, and output formatting. Representative stages:
• Controller validates/adapts inbound request: src/modules/create_user/app/create_user_controller.py
• Use case applies operation logic through repository interfaces: src/modules/create_user/app/create_user_usecase.py
• Presenter and viewmodel create external response shape: src/modules/create_user/app/create_user_presenter.py, src/modules/create_user/app/create_user_viewmodel.py
The same pipeline exists for retrieval, mutation, and deletion, e.g. src/modules/get_user/app/get_user_usecase.py and src/modules/update_user/app/update_user_controller.py.
Domain Core and Dependency Boundary
Shared domain code holds business concepts independent of AWS and transport:
• User entity: src/shared/domain/entities/user.py
• Role/state value enums: src/shared/domain/enums/role_enum.py, src/shared/domain/enums/state_enum.py
• Repository port: src/shared/domain/repositories/user_repository_interface.py
Use cases should depend on IUserRepository rather than DynamoDB implementations. Error families in src/shared/helpers/errors/ distinguish domain, use-case, and controller failures at layer boundaries.
Persistence and DynamoDB Adapter
The infrastructure layer implements persistence behind the repository contract. DynamoDB integration is divided between access/key mechanics and domain-oriented repository mapping:
• Data source/table access: src/shared/infra/external/dynamo/datasources/dynamo_datasource.py, src/shared/infra/external/dynamo/dynamo_table.py
• DynamoDB key and DTO mapping: src/shared/infra/external/dynamo/dynamo_keys.py, src/shared/infra/dto/template_dynamo_dto.py
• Repository implementation: src/shared/infra/repositories/template_repository_dynamo.py
Mock repository and Dynamo loading support local/test-oriented substitution: src/shared/infra/repositories/user_repository_mock.py, src/shared/infra/repositories/load_user_mock_to_dynamo.py.
Observability and External Services
Observability is expressed as a domain-facing interface with AWS and mock adapters:
• src/shared/domain/observability/observability_interface.py
• src/shared/infra/external/observability/observability_aws.py
• src/shared/infra/external/observability/observability_mock.py
Material external services are AWS Lambda, DynamoDB, IAM, and AWS observability facilities. Local DynamoDB is supported through iac/local/docker-compose.yml.
Infrastructure, Packaging, and Delivery
AWS resources are provisioned with Python CDK. The IaC app and stacks define Lambda deployment, DynamoDB table provisioning, and template-level composition:
• iac/app.py
• iac/iac/lambda_stack.py
• iac/iac/template_dynamo_table.py
• iac/iac/template_stack.py
CI/CD and pull-request automation are defined in .github/workflows/CI.yml, .github/workflows/CD.yml, and .github/workflows/CREATE_PR.yml.
Main entry points: create_user_usecase.py User CRUD use cases · http_lambda_requests.py HTTP Lambda boundary · create_user_controller.py Operation controllers · wrap_handler.py Handler wrapper
Components 20
Lambda Runtime
- HTTP Lambda boundary · Normalizes Lambda HTTP requests and responses.
src/shared/helpers/external_interfaces/http_lambda_requests.py - Authorization
src/shared/helpers/auth/authorizer_user.py - Handler wrapper
src/shared/helpers/observability/wrap_handler.py - AWS Lambda
- IAM policy builder
src/shared/helpers/auth/iam_policy.py
Application Core
- Operation controllers · One controller per user CRUD operation.
src/modules/create_user/app/create_user_controller.py - User CRUD use cases · Create, retrieve, update, and delete operations depend on repository ports.
src/modules/create_user/app/create_user_usecase.py - Presenters & viewmodels
src/modules/create_user/app/create_user_presenter.py - User domain
src/shared/domain/entities/user.py - IUserRepository · Dependency boundary for persistence.
src/shared/domain/repositories/user_repository_interface.py - Observability port
src/shared/domain/observability/observability_interface.py - Layer errors · Domain, use-case, and controller errors are separated.
Persistence
- Dynamo repository adapter
src/shared/infra/repositories/template_repository_dynamo.py - Dynamo keys & DTOs
src/shared/infra/external/dynamo/dynamo_keys.py - Dynamo data source
src/shared/infra/external/dynamo/datasources/dynamo_datasource.py - Amazon DynamoDB
- AWS observability adapter
src/shared/infra/external/observability/observability_aws.py - AWS observability
Infrastructure & Delivery
- CDK app & stacks · Provisions Lambda, DynamoDB, and template composition.
iac/app.py - CI/CD workflows
.github/workflows/CI.yml
Connections 23
- AWS Lambda → Handler wrapper: invokes
- Handler wrapper → HTTP Lambda boundary: wraps
- HTTP Lambda boundary → Authorization: auth context
- HTTP Lambda boundary → Operation controllers: adapts request
- Authorization → Operation controllers: authorized request
- Operation controllers → User CRUD use cases: executes
- User CRUD use cases → Presenters & viewmodels: result
- Presenters & viewmodels → HTTP Lambda boundary: HTTP response
- User CRUD use cases → User domain: applies
- User CRUD use cases → IUserRepository: depends on
- User CRUD use cases → Observability port: emits through
- Operation controllers → Layer errors: boundary errors
- Dynamo repository adapter → IUserRepository: implements
- Dynamo repository adapter → Dynamo keys & DTOs: maps entities
- Dynamo keys & DTOs → Dynamo data source: builds keys and DTOs
- Dynamo data source → Amazon DynamoDB: reads and writes
- AWS observability adapter → Observability port: implements
- AWS observability adapter → AWS observability: publishes
- Handler wrapper → Observability port: records invocation
- IAM policy builder → Authorization: constructs policies
- CDK app & stacks → AWS Lambda: provisions
- CDK app & stacks → Amazon DynamoDB: provisions
- CI/CD workflows → CDK app & stacks: deploys