This is a template for creating a FastAPI application with Onion Architecture and deploy it to AWS Lambda.
Here are the URLs of the articles I wrote based on this repository.
- 【全2回】AWS Lambda x FastAPIによるPythonモダンAPI開発のすゝめ 1(written in Japanese)
- 【全2回】AWS Lambda x FastAPIによるPythonモダンAPI開発のすゝめ 2(written in Japanese)
this is a project structure image in app directory. ※ different from the actual project structure
├── api # presentation layer
│ ├── __init__.py
│ └── v1
│ ├── __init__.py
│ ├── endpoints
│ │ ├── __init__.py
│ │ └── <specific name>
│ └── router.py
├── compose.yml
├── container_config # DI container
│ ├── __init__.py
│ ├── di_container.py
│ └── module
│ ├── __init__.py
│ └── repository_module.py
├── core
│ ├── __init__.py
│ ├── config.py
│ ├── logger
│ │ ├── __init__.py
│ │ ├── api_logger.py
│ │ └── logging_context_route.py
│ └── singleton.py
├── domain # domain layer
│ └── <specific name>
│ ├── service # business logic which is not written in entity and value object
│ ├── entity # mutable object
│ ├── i_repository # interface for repository(DIP)
│ └── value_object # immutable object
├── exceptions # custom exceptions
│ ├── core.py
│ ├── error_handle_middleware.py
│ └── error_messages.py
├── infrastructure # infrastructure layer
│ ├── repository_impl # implement repository interface
│ ├── model # ORM
├── main.py
├── schemas # DTO for using endpoint
├── scripts
│ └── compose_pytest
├── tests
├── usecase # application layer
If you want to separate command and query in domain layer, you can add CQRS pattern in usecase layer.
this is a ariticle about CQRS pattern.
git clone
cd app
run container following app/README .