如果你今天就要开一个新项目,我会建议最小先长这样:
app/
├── main.py
├── dependencies.py
├── schemas.py
├── routers/
│ ├── permits.py
│ └── auth.py
├── services/
│ └── permit_service.py
└── tests/
└── test_permits.py职责划分:
main.py:应用装配,挂路由、middleware、lifespanrouters/:只放接口层,尽量薄schemas.py:Pydantic 输入输出模型dependencies.py:认证、分页、数据库会话等公共依赖services/:业务逻辑tests/:接口测试和关键业务测试