Back to articles
Restructuring a FastAPI Project, Migrating to Supabase, and Hitting 97% Test Coverage

Restructuring a FastAPI Project, Migrating to Supabase, and Hitting 97% Test Coverage

via Dev.to PythonChris Kechagias

Part 2 of building a retail inventory API from scratch. In Part 1 , I explained why I archived my first API and started over. I ended that post with a confession: the new version still had a flat structure and no tests. Not portfolio material yet. This is what happened next. The Flat Structure Problem The v2 codebase worked, but everything lived at the root level. products.py , variants.py , analytics.py , database.py — all siblings, all imports pointing everywhere. When I added a new router, I had to touch three files. When something broke, I had to search across the whole project. The fix: move everything into an app/ package with proper separation. app/ ├── __init__.py ├── config.py ├── database.py ├── controllers/ ├── models/ ├── routers/ ├── middleware/ └── utils/ └── errors/ Each folder has a clear responsibility. controllers/ is business logic. routers/ is just route definitions. models/ is data shapes. middleware/ handles logging and exception handling. utils/errors/ defines cu

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
2 views

Related Articles