Split endpoints into modules with APIRouter (with prefix, tags and shared dependencies) and include them in the main app; separate concerns into folders for routers, schemas (Pydantic models), services (business logic), database models, dependencies and configuration.
# app/routers/users.py
from fastapi import APIRouter
router = APIRouter(prefix="/users", tags=["users"])
@router.get("/")
def list_users():
return []
# app/main.py
from fastapi import FastAPI
from app.routers import users
app = FastAPI()
app.include_router(users.router)A typical layout: app/main.py, app/routers/, app/schemas/, app/models/, app/services/, app/core/config.py and tests/.