# maua-dev/epep_api architecture

> Architecture diagram of the GitHub repository maua-dev/epep_api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maua-dev/epep_api
- Repository: https://github.com/maua-dev/epep_api

## Overview

#### 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: [`src/modules/create_user/app/create_user_usecase.py`](https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_usecase.py) (User CRUD use cases), [`src/shared/helpers/external_interfaces/http_lambda_requests.py`](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/external_interfaces/http_lambda_requests.py) (HTTP Lambda boundary), [`src/modules/create_user/app/create_user_controller.py`](https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_controller.py) (Operation controllers), [`src/shared/helpers/observability/wrap_handler.py`](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/observability/wrap_handler.py) (Handler wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Lambda Runtime"]
  node_http_boundary["HTTP Lambda boundary<br/>request adapter"]
  node_authorization["Authorization<br/>auth helper<br/>[authorizer_user.py]"]
  node_handler_wrapper["Handler wrapper<br/>observability wrapper<br/>[wrap_handler.py]"]
  node_lambda{{"AWS Lambda<br/>AWS compute"}}
  node_iam_policy["IAM policy builder<br/>access policy<br/>[iam_policy.py]"]
end

subgraph group_application["Application Core"]
  node_controllers["Operation controllers<br/>input orchestration"]
  node_use_cases["User CRUD use cases<br/>application logic"]
  node_presenters["Presenters &amp; viewmodels<br/>output formatting"]
  node_user_domain["User domain<br/>entity and enums<br/>[user.py]"]
  node_user_repository_port(("IUserRepository<br/>repository port"))
  node_observability_port(("Observability port<br/>domain interface"))
  node_error_boundaries["Layer errors<br/>error families"]
end

subgraph group_persistence["Persistence"]
  node_dynamo_repository["Dynamo repository adapter<br/>repository implementation"]
  node_dynamo_mapping["Dynamo keys &amp; DTOs<br/>persistence mapping<br/>[dynamo_keys.py]"]
  node_dynamo_access["Dynamo data source<br/>table access"]
  node_dynamodb[("Amazon DynamoDB<br/>AWS database")]
  node_observability_adapter["AWS observability adapter<br/>infrastructure adapter"]
  node_aws_observability["AWS observability<br/>external service"]
end

subgraph group_delivery["Infrastructure &amp; Delivery"]
  node_cdk_stacks["CDK app &amp; stacks<br/>infrastructure as code<br/>[app.py]"]
  node_ci_cd["CI/CD workflows<br/>GitHub Actions<br/>[CI.yml]"]
end

node_lambda -->|"invokes"| node_handler_wrapper
node_handler_wrapper -->|"wraps"| node_http_boundary
node_http_boundary -->|"auth context"| node_authorization
node_http_boundary -->|"adapts request"| node_controllers
node_authorization -->|"authorized request"| node_controllers
node_controllers -->|"executes"| node_use_cases
node_use_cases -->|"result"| node_presenters
node_presenters -->|"HTTP response"| node_http_boundary
node_use_cases -->|"applies"| node_user_domain
node_use_cases -->|"depends on"| node_user_repository_port
node_use_cases -->|"emits through"| node_observability_port
node_controllers -.->|"boundary errors"| node_error_boundaries
node_dynamo_repository -->|"implements"| node_user_repository_port
node_dynamo_repository -->|"maps entities"| node_dynamo_mapping
node_dynamo_mapping -->|"builds keys and DTOs"| node_dynamo_access
node_dynamo_access -->|"reads and writes"| node_dynamodb
node_observability_adapter -->|"implements"| node_observability_port
node_observability_adapter -->|"publishes"| node_aws_observability
node_handler_wrapper -->|"records invocation"| node_observability_port
node_iam_policy -->|"constructs policies"| node_authorization
node_cdk_stacks -->|"provisions"| node_lambda
node_cdk_stacks -->|"provisions"| node_dynamodb
node_ci_cd -->|"deploys"| node_cdk_stacks

click node_http_boundary "https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/external_interfaces/http_lambda_requests.py"
click node_authorization "https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/auth/authorizer_user.py"
click node_handler_wrapper "https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/observability/wrap_handler.py"
click node_controllers "https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_controller.py"
click node_use_cases "https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_usecase.py"
click node_presenters "https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_presenter.py"
click node_user_domain "https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/entities/user.py"
click node_user_repository_port "https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/repositories/user_repository_interface.py"
click node_observability_port "https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/observability/observability_interface.py"
click node_dynamo_repository "https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/repositories/template_repository_dynamo.py"
click node_dynamo_mapping "https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/dynamo/dynamo_keys.py"
click node_dynamo_access "https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/dynamo/datasources/dynamo_datasource.py"
click node_observability_adapter "https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/observability/observability_aws.py"
click node_cdk_stacks "https://github.com/maua-dev/epep_api/blob/dev/iac/app.py"
click node_ci_cd "https://github.com/maua-dev/epep_api/blob/dev/.github/workflows/CI.yml"
click node_iam_policy "https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/auth/iam_policy.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http_boundary,node_authorization,node_handler_wrapper,node_lambda,node_iam_policy toneBlue
class node_controllers,node_use_cases,node_presenters,node_user_domain,node_user_repository_port,node_observability_port,node_error_boundaries toneAmber
class node_dynamo_repository,node_dynamo_mapping,node_dynamo_access,node_dynamodb,node_observability_adapter,node_aws_observability toneMint
class node_cdk_stacks,node_ci_cd toneRose
```

## Components

### Lambda Runtime

- [HTTP Lambda boundary](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/external_interfaces/http_lambda_requests.py): request adapter · Normalizes Lambda HTTP requests and responses. · `src/shared/helpers/external_interfaces/http_lambda_requests.py`
- [Authorization](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/auth/authorizer_user.py): auth helper · `src/shared/helpers/auth/authorizer_user.py`
- [Handler wrapper](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/observability/wrap_handler.py): observability wrapper · `src/shared/helpers/observability/wrap_handler.py`
- **AWS Lambda**: AWS compute
- [IAM policy builder](https://github.com/maua-dev/epep_api/blob/dev/src/shared/helpers/auth/iam_policy.py): access policy · `src/shared/helpers/auth/iam_policy.py`

### Application Core

- [Operation controllers](https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_controller.py): input orchestration · One controller per user CRUD operation. · `src/modules/create_user/app/create_user_controller.py`
- [User CRUD use cases](https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_usecase.py): application logic · Create, retrieve, update, and delete operations depend on repository ports. · `src/modules/create_user/app/create_user_usecase.py`
- [Presenters & viewmodels](https://github.com/maua-dev/epep_api/blob/dev/src/modules/create_user/app/create_user_presenter.py): output formatting · `src/modules/create_user/app/create_user_presenter.py`
- [User domain](https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/entities/user.py): entity and enums · `src/shared/domain/entities/user.py`
- [IUserRepository](https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/repositories/user_repository_interface.py): repository port · Dependency boundary for persistence. · `src/shared/domain/repositories/user_repository_interface.py`
- [Observability port](https://github.com/maua-dev/epep_api/blob/dev/src/shared/domain/observability/observability_interface.py): domain interface · `src/shared/domain/observability/observability_interface.py`
- **Layer errors**: error families · Domain, use-case, and controller errors are separated.

### Persistence

- [Dynamo repository adapter](https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/repositories/template_repository_dynamo.py): repository implementation · `src/shared/infra/repositories/template_repository_dynamo.py`
- [Dynamo keys & DTOs](https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/dynamo/dynamo_keys.py): persistence mapping · `src/shared/infra/external/dynamo/dynamo_keys.py`
- [Dynamo data source](https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/dynamo/datasources/dynamo_datasource.py): table access · `src/shared/infra/external/dynamo/datasources/dynamo_datasource.py`
- **Amazon DynamoDB**: AWS database
- [AWS observability adapter](https://github.com/maua-dev/epep_api/blob/dev/src/shared/infra/external/observability/observability_aws.py): infrastructure adapter · `src/shared/infra/external/observability/observability_aws.py`
- **AWS observability**: external service

### Infrastructure & Delivery

- [CDK app & stacks](https://github.com/maua-dev/epep_api/blob/dev/iac/app.py): infrastructure as code · Provisions Lambda, DynamoDB, and template composition. · `iac/app.py`
- [CI/CD workflows](https://github.com/maua-dev/epep_api/blob/dev/.github/workflows/CI.yml): GitHub Actions · `.github/workflows/CI.yml`

## Connections

- 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
