Performance: Folder structure patterns
This affects the initial load time and runtime efficiency by influencing import times and module resolution speed.
app/
main.py
api/
__init__.py
routes/
__init__.py
user.py
item.py
core/
config.py
database.py
models/
user.py
item.py
services/
user_service.py
item_service.pyapp/ main.py models.py routes.py utils.py services.py controllers.py database.py config.py
| Pattern | Module Imports | Import Depth | Startup Delay | Verdict |
|---|---|---|---|---|
| Flat folder with many files | Loads all modules at once | High | Blocks startup for 150-200ms | [X] Bad |
| Modular folder with focused subfolders | Loads only needed modules | Low to medium | Blocks startup for 50-80ms | [OK] Good |
routes folder is typically used to store API endpoint definitions, organizing the paths and HTTP methods.models is for data models, services for business logic, and database for database connection code.models folder for clarity and separation.services is for business logic, mixing models with routes or root folder reduces clarity and maintainability.app/
routes/
user.py
models/
user.py
services/
user_service.py
routes handles API endpoints, models defines data structures, and services contains business logic like fetching data.services/user_service.py.app/ routes.py models.py services.py database.py
app/ is okay for small projects but becomes cluttered and hard to maintain as code grows.routes/, models/, and services/ helps organize code by purpose and improves maintainability.Pass the test and this pattern moves unknown