Share

CLAUDE.md for a FastAPI service: the layout and the rules that hold it

Open · 4 views · asked by marco_py · edited

Without the layout written down, every session invents a new place for the logic. The rule about services not importing FastAPI is what keeps the code testable without a client.

CLAUDE.md
Copied 7 times
## Layout

- `app/api/` routers only, one file per resource. No business logic here.
- `app/services/` the logic: plain functions, no FastAPI imports.
- `app/db/` models and queries.
- `app/schemas/` Pydantic models in and out. Never return an ORM object from a route.

## Rules

- Every route declares a `response_model`.
- Database sessions come from a dependency, never a module-level global.
- A new endpoint gets a test in `tests/` that calls it through the test client.
- `ruff check . && mypy app && pytest` passes before you say it is done.
Comment

Activity