Building a highly decoupled, production-ready FastAPI backend. Using punq for IoC/Dependency Injection, asyncpg for database performance, and a multi-stage Docker build for deployment.
- Dependency Injection: Shifted from FastAPI's native
Depends()topunq. This allows strict separation between the web framework and the domain logic. - Execution: Utilizing the official
fastapi-cli(fastapi dev/fastapi run) for standardized server execution and automatic worker management. - Package Management:
uvis strictly enforced for dependency resolution and building the Docker image.
- Need to write the base
app/core/di.pyto initialize thepunq.Containerand register the database session factory. - Need to draft the
Dockerfileoptimized foruvcaching and multi-stage builds.