Skip to main content
FastAPI architecture recommended

Project Structure

Domain-driven project organization with routers, services, repositories, and models. Separation of concerns for maintainable FastAPI applications.

Difficulty
intermediate
Read time
1 min read
Version
v1.0.0
Confidence
established
Last updated

Quick Reference

Organize FastAPI with 3 layers: api/ (routers), services/ (business logic), db/repositories/ (data access). Group by domain (users/, items/). Use core/ for config, security, exceptions. Keep routers thin - they call services. Services call repositories. Use dependency injection for database sessions.

Use When

  • Starting a new FastAPI project
  • Refactoring FastAPI project structure
  • Scaling a FastAPI application

Skip When

  • Simple single-file scripts
  • Prototypes or POCs

Project Structure

Domain-driven project organization with routers, services, repositories, and models. Separation of concerns for maintainable FastAPI applications.

Tags

architecture project-structure domain-driven best-practices

Discussion