S.
Home
AboutProjectsBlogLabGalleryContact
HomeProjectsBlogContact

© 2026 Shohjahon Rajabov. All rights reserved.

Back to blog
Engineering
September 15, 2025
1 min read
PythonFastAPI

How I structure large FastAPI projects

Routers, services, repositories, and the rules that keep a FastAPI codebase from becoming a mess as it grows.

Every FastAPI project starts clean. Then it grows. The first sign of trouble is a router file with five hundred lines and database queries embedded in the handler.

The structure I've landed on is three layers: routers (HTTP only), services (business logic), and repositories (data access). Each returns well-typed objects to the layer above - no raw ORM rows leaking up.

The rule that makes it work: dependency injection via Depends. The session is injected into the repository, the repository into the service, the service into the router. Nothing is global.

Share:Share on Telegram
More posts
Infrastructure

What three Telegram bots taught me about state

2 min · April 18, 2026
Engineering

The caching bug that made me stop trusting TTLs

1 min · February 10, 2026