
I got mass of CRUD in my FastAPI project, so I fixed it
I've been working on a FastAPI project that grew to about 10 domains. At some point I realized I wasn't really building features anymore. I was just copying the same repository-service-router stack into a new folder, changing the model name, and praying I didn't forget to wire something up. The worst part was code reviews. Every developer on the team structured things slightly differently. One person puts DTOs in the service layer, another puts them in the router. Someone imports a repository directly from another domain. Nobody notices until it's already merged and tangled. I kept thinking there has to be a better way to do this. What was actually repeating Every single domain needed the same thing: @router.post ( " /user " ) async def create_user ( user : UserCreate ): db = get_db () new_user = User ( ** user . dict ()) db . add ( new_user ) db . commit () return new_user Then I'd write the same thing for products. And orders. And payments. Seven CRUD operations each, all nearly iden
Continue reading on Dev.to Python
Opens in a new tab


