All examples

Python FastAPI service, .cursorrules

The FastAPI service rules as a legacy Cursor .cursorrules file: same content.

Composed from the python-fastapi rules pack. Same file from the CLI: aibysitter init --packs python-fastapi --format cursorrules

Written for this site, CC0, scored by this linter, not tested against any agent.

File
.cursorrules, 41 lines
Format
.cursorrules Legacy format
Save as
.cursorrules
Category
Python
Tags
License
CC0 1.0, public domain. No attribution needed.

Download .cursorrules Lint a copy

Aibysitter lint score

100 / 100 — A

Ruleset v4

No deductions.

Badge

Aibysitter lint score: A 100

Markdown for a README:

[![Aibysitter lint score: A 100](https://aibysitting.net/gallery/python-fastapi-cursorrules/badge.svg)](https://aibysitting.net/Gallery/python-fastapi-cursorrules)

.cursorrules

View rendered

  1. # Python FastAPI service
  2. Python 3.12, FastAPI, SQLAlchemy 2.0 (async), PostgreSQL, Alembic. Dependencies and commands run through uv.
  3. ## Commands
  4. - Install: `uv sync`
  5. - Run: `uv run fastapi dev src/<app>/main.py`
  6. - Test: `uv run pytest`
  7. - Lint: `uv run ruff check .`
  8. - Format: `uv run ruff format .`
  9. - Type check: `uv run mypy src`
  10. - New migration: `uv run alembic revision --autogenerate -m "<summary>"`, then read the generated file before committing it.
  11. ## Layout
  12. - `src/<app>/api/`: routers, one module per resource.
  13. - `src/<app>/services/`: business logic. No FastAPI imports.
  14. - `src/<app>/db/`: models, session, repositories.
  15. - `tests/` mirrors `src/<app>/`.
  16. ## API
  17. - Request and response bodies are Pydantic v2 models in `src/<app>/schemas/`. ORM models are never returned from a route.
  18. - Routes declare `response_model` and an explicit `status_code`.
  19. - `HTTPException` is raised only in routers. Services raise domain errors from `<app>.errors`, and `api/errors.py` maps them to status codes.
  20. - Database sessions come from the `get_session` dependency. Services do not open sessions.
  21. ## Money
  22. - Amounts are integers in minor units (cents). No floats for money.
  23. - Every amount is stored with an ISO 4217 currency code next to it.
  24. ## Code style
  25. - Every function signature has type hints. `mypy --strict` passes for `src/`.
  26. - Ruff rules live in `pyproject.toml`. A `# noqa` comment always names the rule code.
  27. - Timestamps use `datetime.now(tz=UTC)`. Naive datetimes are a bug.
  28. ## Tests
  29. - pytest with `pytest-asyncio`. Async tests use the `async_client` fixture from `tests/conftest.py`.
  30. - Database tests run against the Postgres container started by `docker compose up -d db`.
  31. - A bug fix starts with a failing test that reproduces the bug.
  32. ## Done
  33. - `ruff check`, `ruff format --check`, `mypy`, and `pytest` all pass.