skill-everything / rules
Cursor rule20 starsChanged 7 months agoMITView on GitHub
Apply when building FastAPI endpoints, Pydantic models, or async APIs. Covers routing, dependency injection, error handling, testing, and OpenAPI hygiene.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/brainstorming.mdcCursor rule
- .cursor/rules/branch-finishing.mdcCursor rule
- .cursor/rules/code-quality.mdcCursor rule
- .cursor/rules/db-schema.mdcCursor rule
- .cursor/rules/debugging.mdcCursor rule
- .cursor/rules/docker.mdcCursor rule
- .cursor/rules/domain-template.mdcCursor rule
- .cursor/rules/drawio.mdcCursor rule
- .cursor/rules/error-log.mdcCursor rule
- .cursor/rules/git-conventions.mdcCursor rule
- .cursor/rules/github-cli.mdcCursor rule
- .cursor/rules/implementation-plan.mdcCursor rule
- .cursor/rules/langchain.mdcCursor rule
- .cursor/rules/python.mdcCursor rule
- .cursor/rules/react.mdcCursor rule
- .cursor/rules/review-deployment.mdcCursor rule
- .cursor/rules/security-review.mdcCursor rule
- .cursor/rules/self-extension-workflow.mdcCursor rule
- .cursor/rules/shell-scripting.mdcCursor rule
- .cursor/rules/svg-check.mdcCursor rule
- .cursor/rules/tdd.mdcCursor rule
- .cursor/rules/typescript.mdcCursor rule
- skill-everythingSkill
- brainstormingSkill
- branch-finishingSkill
- code-qualitySkill
- db-schemaSkill
- debuggingSkill
- dockerSkill
- domain-templateSkill
- drawioSkill
- error-logSkill
- fastapiSkill
- git-conventionsSkill
- github-cliSkill
- implementation-planSkill
- langchainSkill
- pythonSkill
- reactSkill
- review-deploymentSkill
- security-reviewSkill
- self-extension-workflowSkill
- shell-scriptingSkill
- svg-checkSkill
- tddSkill
- <kebab-case-name>Skill
- typescriptSkill
The file
We split this fastapi.mdc into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Always: use Pydantic v2 syntax (model_config, model_dump, model_validate) unless the project explicitly pins Pydantic v1 (pydantic<2 in …
- Very specific: line 22
Always: use status_code on the route decorator (@app.post("/items", status_code=201)) rather than constructing a Response object just to …
- Very specific: line 36
Always: use BackgroundTasks (injected via Depends or as a route parameter) for fire-and-forget work.
- Very specific: line 42
Always: test FastAPI routes with TestClient (sync) or AsyncClient from httpx (async).
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule 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
---
description: Apply when building FastAPI endpoints, Pydantic models, or async APIs. Covers routing, dependency injection, error handling, testing, and OpenAPI hygiene.
alwaysApply: false
---
# Sub-Skill: FastAPI
**Purpose:** Prevent common FastAPI and Pydantic mistakes. Apply these rules whenever writing or reviewing FastAPI route handlers, Pydantic schemas, or async API code.
---
## Rules
1. **Always** declare request and response bodies as Pydantic models — never use raw `dict` or `Any` for I/O. Reference: ERR-2026-025
2. **Always** use Pydantic v2 syntax (`model_config`, `model_dump`, `model_validate`) unless the project explicitly pins Pydantic v1 (`pydantic<2` in requirements). Reference: ERR-2026-025
3. **Always** declare route handlers as `async def` unless the handler calls blocking I/O that cannot be awaited; use `run_in_executor` for blocking calls inside async handlers.
4. **Always** specify an explicit `response_model` on every route decorator so FastAPI filters and validates the response shape.
5. **Always** use `status_code` on the route decorator (`@app.post("/items", status_code=201)`) rather than constructing a `Response` object just to set the status.
6. **Never** raise bare `Exception` in route handlers; raise `HTTPException` with a meaningful `status_code` and `detail` string, or define a custom exception with an exception handler.
7. **Always** register exception handlers via `@app.exception_handler(MyError)` for domain errors rather than catching them inside every route.
8. **Use** `Depends()` for shared logic (auth, DB sessions, pagination params) — never duplicate the same logic across multiple route functions.
9. **Prefer** `APIRouter` with a `prefix` and `tags` list to group related endpoints; register routers with `app.include_router()` rather than defining all routes on the app object.
10. **Always** configure CORS via `CORSMiddleware` with an explicit `allow_origins` list; never use `allow_origins=["*"]` in production.
11. **Use** the `lifespan` context manager (FastAPI ≥ 0.93) for startup/shutdown logic instead of the deprecated `@app.on_event("startup")` / `@app.on_event("shutdown")` decorators.
12. **Always** use `BackgroundTasks` (injected via `Depends` or as a route parameter) for fire-and-forget work; never `asyncio.create_task` inside a route without a lifecycle guard.
13. **Avoid** exposing internal field names in OpenAPI by setting `model_config = ConfigDict(populate_by_name=True)` and using `alias` or `alias_generator` when the wire format differs from the Python attribute name.
14. **Use** `pydantic-settings` (`BaseSettings`) for configuration; never read `os.environ` directly inside route handlers or dependency functions.
15. **Always** test FastAPI routes with `TestClient` (sync) or `AsyncClient` from `httpx` (async); never spin up a real server in unit tests.
16. **Ensure** path operation functions declare only the parameters they actually use; unused `Request` injections or stale `Depends` imports are dead code and confuse readers.
17. **Before** adding a new route, check whether an existing router already owns that resource prefix; adding routes to the wrong router breaks OpenAPI tag grouping.
18. **Never** store mutable state in module-level variables inside route modules; use dependency-injected singletons or `app.state` instead.
---
## See also
- `skills/python/SKILL.md`
- `skills/code-quality/SKILL.md`
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.

