- docker
- docker compose
- poetry
- Naming conventions
- Every file should have a unique name
- Add type to file name outside of models. I believe it helps with search-ability/readability
order_controller, order_service, order_repository
- Set custom exception_handler in
main.py
to better format error responsesapplication.add_exception_handler(HTTPException, exh.http_exception_handler)
- Use
@cbv
decorator to initialize shared dependencies.@cbv(order_router) class OrderController: def __init__(self): self.order_service = OrderService()
- Model files has ORM and pydantic classes for easier updates (Might not be the best solution for all)
- Schema - request/response object. It uses
BaseSchema.to_orm
to convert to ORM - ORM - DB object
- Schema - request/response object. It uses
- Here is the commit before switching to async
fast-api-docker-poetry
├── app
│ ├── config -- app configs
│ │ ├── exception_handlers.py
│ │ ├── settings.py
│ ├── controllers -- api routes by objects
│ │ ├── order_controller.py
│ └── models -- orm and pydantic models
│ │ ├── order.py
│ │ ├── address.py
│ │ ├── base.py
│ │ ├── pageable.py
│ └── repository -- database queries
│ │ ├── order_repository.py
│ └── services -- business logic / data transformation
│ │ ├── order_service.py
│ └── utils
│ │ ├── db.py
│ └── main.py
├── migrations/ -- alembic migrations
├── tests/
│ ├── integrations -- test api routes by using TestClient
├── .env
├── .gitignore
├── docker-compose.yml
├── Makefile
├── pyproject.toml
└── alembic.ini
- Start with jaeger tracing using docker
make startd
- Start with no tracing using docker
make startslimd
- Test with docker
make testd
- Start with poetry
make startp
- Test with poetry
make testp