python-samples-fastapi-restful
CLAUDE.md141 starsChanged 7 months agoMITView on GitHub
- Run /pre-commit to execute the full pre-commit checklist for this project. - Run /pre-release before tagging a release. - See .claude/skills/create-issue/SKILL.md for the SDD issue workflow, and .claude/skills/add-endpoint/SKILL.md for the endpoint/schema workflows. Layer rule: Routes → Services → SQLAlchemy → SQLite. Routes handle HTTP concerns only; business logic belongs in services. Never skip a layer. tools/ is legacy (superseded by Alembic migrations); gunicorn.conf.py is used by the Docker entrypoint. - Naming: snake_case (files, functions, variables), PascalCase (classes) - Type…
- Reads credentials
- Installs packages
In this repository2 other files it gives its agents.
- add-endpointSkill
- create-issueSkill
The file
We split this CLAUDE.md into the rules it gives an agent
7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 5
Run /pre-commit to execute the full pre-commit checklist for this project.
- Very specific: line 6
Run /pre-release before tagging a release.
- Very specific: line 21
Async: All routes and service functions must be async def.
- Distinctive: line 37
DELETE) and preferred for all external consumers
- Very specific: line 104
Add/modify routes in routes/player_route.py and routes/health_route.py
- Very specific: line 105
Add/modify service methods in services/player_service.py
- Very specific: line 106
Add/modify Pydantic models in models/player_model.py (field additions or docstring updates that don't change the API contract)
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
Claude Code
- Run
/pre-committo execute the full pre-commit checklist for this project. - Run
/pre-releasebefore tagging a release. - See
.claude/skills/create-issue/SKILL.mdfor the SDD issue workflow, and.claude/skills/add-endpoint/SKILL.mdfor the endpoint/schema workflows.
Structure
Layer rule: Routes → Services → SQLAlchemy → SQLite. Routes handle HTTP
concerns only; business logic belongs in services. Never skip a layer.
tools/ is legacy (superseded by Alembic migrations); gunicorn.conf.py is
used by the Docker entrypoint.
Coding Guidelines
- Naming: snake_case (files, functions, variables), PascalCase (classes)
- Type hints: Required everywhere — functions, variables, return types
- Async: All routes and service functions must be
async def; useAsyncSession(neverSession); useaiosqlite(neversqlite3); use SQLAlchemy 2.0select()(neversession.query()) - API contract: camelCase JSON via Pydantic
alias_generator=to_camel; Python internals stay snake_case - Models:
PlayerRequestModel(noid, used for POST/PUT) andPlayerResponseModel(includesid: UUID, used for GET/POST responses). One request model intentionally covers both POST and PUT — per-operation differences (conflict check on POST, mismatch guard on PUT) are handled at the route layer, not by duplicating the model. Never reintroduce the removedPlayerModel; it was removed because a single flat model conflated ORM, request, and response concerns. - Primary key: UUID surrogate key (
id) — opaque, internal, used for GET by id only. UUID v4 for API-created records; UUID v5 (deterministic) for migration-seeded records.squad_numberis the natural key — human-readable, domain-meaningful, used for all mutation endpoints (PUT, DELETE) and preferred for all external consumers - Caching: cache key
"players"(hardcoded); clear on POST/PUT/DELETE;X-Cacheheader (HIT/MISS) - Errors: Catch specific exceptions with rollback in services; Pydantic validation returns 422 (not 400); squad number mismatch on PUT returns 400 (not 422 — it is a semantic error, not a validation failure)
- Logging:
loggingmodule only; neverprint() - Tests: integration tests against the real SQLite DB (seeded via
Alembic migrations) via
TestClient— no mocking. Naming patterntest_request_{method}_{resource}_{context}_response_{outcome}; docstrings single-line, concise;tests/player_fake.pyfor test data;tests/conftest.pyprovides afunction-scopedclientfixture for isolation;tests/test_main.pyexcluded from Black;tests/test_migrations.pycovers Alembic downgrade paths - Decisions: justify every decision on its own technical merits; never use "another project does it this way" as a reason — that explains nothing and may mean replicating a mistake
- Avoid: sync DB access, mixing sync/async,
print(), missing type hints, unhandled exceptions
Commands
Quick Start
# Setup (using uv)
uv venv
source .venv/bin/activate # Linux/macOS; use .venv\Scripts\activate on Windows
uv pip install --group dev
# Apply migrations (required once before first run, and after down -v)
uv run alembic upgrade head
# Run application
uv run uvicorn main:app --reload --port 9000 # http://localhost:9000/docs
# Run tests
uv run pytest # run tests
uv run pytest --cov=./ --cov-report=term # with coverage (target >=80%)
# Migration workflow
uv run alembic upgrade head # apply all pending migrations
uv run alembic downgrade -1 # roll back last migration
uv run alembic revision --autogenerate -m "desc" # generate migration from schema
# Docker
docker compose up
docker compose down -vCommits
Format: type(scope): description (#issue) — max 80 chars
Types: feat fix chore docs test refactor ci perf
Example: feat(api): add player stats endpoint (#42)
Releases
Tags follow the format v{MAJOR}.{MINOR}.{PATCH}-{COACH} (e.g.
v2.0.0-capello). Valid coach names (A–Z) are maintained in CHANGELOG.md's
naming-convention table — the same table /pre-release reads. Never suggest
a release tag with a coach name not in that table.
Agent Mode
Proceed freely
- Add/modify routes in
routes/player_route.pyandroutes/health_route.py - Add/modify service methods in
services/player_service.py - Add/modify Pydantic models in
models/player_model.py(field additions or docstring updates that don't change the API contract) - Tests in
tests/— maintain async patterns, naming convention, and integration-test approach (no mocking) - Documentation and docstring updates
- Lint/format fixes
- Refactoring within existing architectural patterns
Ask before changing
- Database schema (
schemas/player_schema.py) and Alembic migrations (alembic/versions/) — schema changes require a new migration file; seed data changes require updating the relevant migration and any test fixtures that reference specific UUIDs models/player_model.pydesign decisions — especially splitting or merging request/response models; discuss the rationale before restructuring- Dependencies (
pyproject.tomlwith PEP 735 dependency groups) - CI/CD configuration (
.github/workflows/) - Docker setup (
Dockerfile,compose.yaml,scripts/) - Breaking API contract changes (field renames, type changes, removing fields)
- Global error handling middleware
- HTTP status codes assigned to existing error conditions
Never modify
.envfiles (secrets)alembic/versions/migration files once merged tomaster— migrations are append-only; fix forward with a new migration, never edit history- Production configurations
Creating Issues
Spec-Driven Development (SDD): discuss in Plan mode first, create a GitHub
Issue as the spec artifact, then implement. Always offer to draft an issue
before writing code. See .claude/skills/create-issue/SKILL.md for the
feature/bug issue templates.
Key workflows
See .claude/skills/add-endpoint/SKILL.md for the "add an endpoint" and
"modify schema" recipes.
After completing work: Propose a branch name and commit message for user approval. Do not create a branch, commit, or push until the user explicitly confirms.
Invariants (never change without explicit discussion)
- Port: 9000
- API contract: endpoints, HTTP status codes, and response shapes are fixed; do not change them without explicit discussion
- Commit format:
type(scope): description (#issue)— max 80 chars - Conventional Commits types:
featfixchoredocstestrefactorciperf - CHANGELOG.md:
[Unreleased]section must be updated before every commit
Architecture Decision Records
Significant architectural decisions are documented in docs/adr/ (ADR-0001–0013).
Load these before proposing structural changes. When a proposal would change an
accepted decision, create a new ADR rather than editing the existing one.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

