Menu

1 / 3

Vertical Slices in FastAPI: One Folder per Use Case, One Shared Port Package

DEV Community: python·Gabriel Anhaia·about 6 hours ago
#pAlsLaJO
#devtopython#devto#dev#import#orders
Long article (2602 words) — no AI summary yet.
Reading 0:00
15s threshold

Book: Hexagonal Architecture in Python

Companion code: hexagonal-python-examples — every listing from the book, free on GitHub

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

You add "cancel an order" to a FastAPI service. The pull request touches routers/orders.py , services/order_service.py , repositories/order_repository.py , schemas/orders.py and tests/test_orders.py . That's five files in five folders for one feature, and the reviewer has to open every one of them to see what the feature does. The next feature touches the same five files again, so two branches working on orders collide in the same service class.

That layout starts in the docs. FastAPI's Bigger Applications guide splits code into an app/routers/ package with one module per resource, and plenty of teams carry that one step further into services/ and repositories/ folders. It works fine for small services.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.