CLAUDE.md¶
to match your codebase. -->
Project¶
One-paragraph description of what this service does.
- Framework: FastAPI / Django / Flask / library (no framework)
- Python: 3.11+
- Package manager:
uv/poetry/pip-tools - Formatter + linter:
ruff(format and check) - Type checker:
mypy --strict/pyright - Tests:
pytest
Commands¶
ruff format .— formatruff check .— lintmypy .— type-checkpytest— run testspytest -x --ff— stop at first failure, reorder to re-run last failures first-
uvicorn app.main:app --reload— dev server
Before opening a PR: ruff format ., ruff check ., mypy ., pytest.
CI runs the same four commands in that order.
Architecture¶
Describe your layout. Example for a FastAPI service:
app/api/— route handlers. Thin; no business logic.app/services/— business logic. Pure functions where possible.app/models/— SQLAlchemy ORM models.app/schemas/— Pydantic request/response schemas.app/db/— database session, migrations (Alembic).tests/— mirrorsapp/structure.tests/api/test_users.pycoversapp/api/users.py.
Testing¶
- One test module per source module. Same relative path under
tests/. - Use
pytestfixtures for setup. NosetUp/tearDown. - Factory functions for test data live in
tests/factories/. Don't inline a 15-line dict to build a user — add auser_factory. - Database tests use the
transactional_dbfixture. It rolls back after each test, so test order doesn't matter. - Don't mock what you own. Mock external HTTP (
respx,httpx_mock).
Conventions¶
- Type hints on every public function signature. Private helpers can skip them if the function is obviously trivial.
pydantic.BaseModelfor request/response bodies. Never return raw ORM objects from an endpoint.- SQL via the ORM or
sqlalchemy.text()— no f-string SQL, ever. - Exceptions: raise domain exceptions in services (
app/errors.py), catch them at the API boundary and map to HTTP codes.
Do NOT¶
- Add dependencies without asking. Lockfile is reviewed.
except Exception:without re-raising or a specific reason comment.- Put business logic in route handlers.
- Commit
.envfiles or anything under.venv/,__pycache__/,.pytest_cache/.
Available skills¶
/api-endpoint— scaffold a new endpoint: route + Pydantic schemas + service function + test, following the project layout.
See also¶
- starters/index.md — kit contents and install
- ../../guides/claude-md-guide.md — how to write a good CLAUDE.md