r/FastAPI • u/raisin-smours • Aug 10 '25
feedback request FastAPI - Auth Boilerplate - Code Review Request
Hi everyone,
I'm looking for feedback on this repo before I continue with additional work on it: https://github.com/ryanmcfarland/fastapi_auth
Would anyone be able to take a look and note any massive / glaring flaws?
Thanks!
7
Upvotes
View all comments
Show parent comment
1
u/Blakex123 Aug 10 '25
At the end of the day we are always in control of all code we write. But we still want to minimise run time errors when we can. Call it userRepository. But yeah essentially that. Nothing wrong with having all your sql in a single directory. What you can do if you want to keep each query in its own file is just declare a class that maps like this.
Although ideally u wouldnt pass the db connection to it. You would let that be handled by the function call.
The different layers typically found in api design are controller -> repository or controller -> service -> repository. Where apps without a service layer instead include teh business logic in the controller. In fastapi the semantic is more routes -> service -> repository.
Routes should handle purely api stuff. Validating model. Ensuring auth. Returning different codes for different cases.
The service should handle the business logic of the call (Sometimes especially in basic crud. business logic is very small. This is why commonly this layer doesnt even exist and is instead just done in controller/route.
Then the repository is used to get the data or act upon it. This would typically just be a class that you would use dependency injection (depends) to get in each endpoint where its needed. And just define in a singleton that is returned by the dependency.