r/FastAPI • • Mar 04 '23

Tutorial Clean Architecture with FastAPI

24 Upvotes

2 comments sorted by

View all comments

6

u/ezersilva Mar 04 '23

I have used a clean architecture style with FastAPI and some parts of it were worth it. In general, in my experience:

The Good:

  • The Repository pattern (but without creating a general repo class and a general domain class); I use it to mock data depending on the environment where it is running; good for unit tests and especially running tests using CICD;

  • Dependency injection of the Settings object;

The Bad:

  • UseCase classes: most of the time, I just put the code in the route;

  • Using inheritance everywhere;

The Ugly:

  • Trying to abstract away every implementation detail.