

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345## Context67This instruction file applies to FastAPI application files — routers, schemas, dependencies, middleware, and the application factory. The project uses FastAPI 0.111+ with Pydantic v2 for request/response validation. All routes must be `async def`, return typed Pydantic models, and use RFC 7807 `ProblemDetail` for error responses. OpenAPI documentation is auto-generated; keep schema names meaningful and descriptions accurate.89---1011## Coding Standards1213- **All routes `async def`:** Never `def` (synchronous) for route handlers — use `async def` with `await`14- **Explicit `response_model=`:** Every route declares `response_model=` and `status_code=`15- **Pydantic v2 schemas:** Request and response models inherit from `pydantic.BaseModel`; use `model_config` for settings16- **`Annotated[T, Depends()]` injection:** Prefer `Annotated` dependency aliases over bare `Depends()` in signatures17- **RFC 7807 errors:** Domain errors translate to `ProblemDetail` (type, title, status, detail, instance); never return raw strings18- **Router organisation:** One `APIRouter` per bounded context; mount routers in `app.py` — no routes in `main.py`19- **Versioned paths:** All routes under `/v{n}/` prefix — e.g. `/v1/orders`20- **`BaseSettings` for config:** No hardcoded URLs, credentials, or feature flags in route code21- **Lifespan events:** Use `@asynccontextmanager` `lifespan` parameter — never deprecated `on_startup`/`on_shutdown`2223---2425## Preferred Patterns2627### Router with Typed Response2829```python30# ✅ CORRECT31from typing import Annotated32from fastapi import APIRouter, Depends, HTTPException, status33from app.dependencies import get_order_service34from app.schemas.orders import CreateOrderRequest, OrderResponse35from app.services.orders import OrderService3637router = APIRouter(prefix="/v1/orders", tags=["orders"])3839OrderServiceDep = Annotated[OrderService, Depends(get_order_service)]4041@router.post("/", response_model=OrderResponse, status_code=status.HTTP_201_CREATED)42async def create_order(body: CreateOrderRequest, service: OrderServiceDep) -> OrderResponse:43 result = await service.place_order(body.to_command())44 return OrderResponse.from_domain(result)4546# ❌ WRONG — synchronous, no response_model, raw dict return47@router.post("/orders")48def create_order(body: dict):49 return {"id": "123"}50```5152### RFC 7807 Error Handler5354```python55# ✅ CORRECT — global exception handler in app.py56from fastapi import Request57from fastapi.responses import JSONResponse5859class DomainError(Exception):60 def __init__(self, message: str, status_code: int = 400) -> None:61 self.message = message62 self.status_code = status_code6364@app.exception_handler(DomainError)65async def domain_error_handler(request: Request, exc: DomainError) -> JSONResponse:66 return JSONResponse(67 status_code=exc.status_code,68 content={69 "type": "https://api.example.com/errors/domain-error",70 "title": "Domain Error",71 "status": exc.status_code,72 "detail": exc.message,73 "instance": str(request.url),74 },75 media_type="application/problem+json",76 )77```7879### Pydantic v2 Request/Response Schema8081```python82# ✅ CORRECT — Pydantic v2 with model_config83from datetime import datetime84from pydantic import BaseModel, ConfigDict, field_validator8586class CreateOrderRequest(BaseModel):87 model_config = ConfigDict(str_strip_whitespace=True)8889 customer_id: str90 items: list[OrderLineItem]91 currency: str = "GBP"9293 @field_validator("currency")94 @classmethod95 def validate_currency(cls, v: str) -> str:96 if v not in {"GBP", "USD", "EUR"}:97 raise ValueError(f"Unsupported currency: {v}")98 return v99100class OrderResponse(BaseModel):101 model_config = ConfigDict(from_attributes=True)102103 order_id: str104 status: str105 created_at: datetime106107 @classmethod108 def from_domain(cls, order: Order) -> "OrderResponse":109 return cls(order_id=str(order.id), status=order.status.value, created_at=order.created_at)110```111112### Dependency Injection with Lifespan113114```python115# ✅ CORRECT — lifespan manages resource setup/teardown116from contextlib import asynccontextmanager117from fastapi import FastAPI118119@asynccontextmanager120async def lifespan(app: FastAPI):121 # startup122 await database.connect()123 yield124 # shutdown125 await database.disconnect()126127app = FastAPI(lifespan=lifespan)128129# ❌ WRONG — deprecated startup/shutdown events130@app.on_event("startup")131async def startup():132 await database.connect()133```134135---136137## Anti-Patterns — Do NOT Generate138139```python140# WRONG: synchronous route handler [BLOCKER]141@router.get("/orders/{order_id}")142def get_order(order_id: str):143 return order_repo.find(order_id)144145# WRONG: missing response_model [MAJOR]146@router.post("/orders")147async def create_order(body: dict) -> dict:148 return {"status": "ok"}149150# WRONG: returning raw dict from route [MAJOR]151@router.get("/health")152async def health():153 return {"status": "up"} # Use a typed HealthResponse model154155# WRONG: raise HTTPException with plain string detail [MAJOR]156raise HTTPException(status_code=400, detail="Invalid order") # Use ProblemDetail157158# WRONG: global mutable state [MAJOR]159db = AsyncSession() # module-level; not thread/request safe160161# WRONG: hardcoded config [MAJOR]162DATABASE_URL = "postgresql://localhost/orders"163164# WRONG: deprecated on_event [MINOR]165@app.on_event("startup")166async def init():167 ...168```169170---171172## Dependencies & Versions173174| Technology | Version | Notes |175|-----------|---------|-------|176| FastAPI | 0.111+ | Annotated dependencies, lifespan parameter |177| Pydantic | 2.x | `model_config = ConfigDict(...)` replaces `class Config:` |178| uvicorn | 0.29+ | ASGI server; run with `--workers` in production |179| SQLAlchemy | 2.x | `async_sessionmaker`; always `await` sessions |180| alembic | 1.13+ | Database migrations; `async` env configuration |181| httpx | 0.27+ | Async HTTP client for downstream calls |182| python-jose | 3.x | JWT decoding; verify `alg`, `aud`, `iss`, `exp` |183184---185186## Test Conventions187188- Use `httpx.AsyncClient` with FastAPI `app` as transport for integration tests — not `TestClient` (synchronous)189- Override dependencies in tests via `app.dependency_overrides`190- Test the full HTTP layer (router → service → repo) in integration tests with `Testcontainers`191- Unit test service logic with mocked repositories using `unittest.mock.AsyncMock`192- Use `pytest.mark.parametrize` for status code boundary tests (200, 201, 400, 404, 422, 500)193- Verify `Content-Type: application/problem+json` on all error responses194
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| doubts-suplab/eeik-bootstrap.clinerules/golden-rules.md · 1 | Cline rules | gitsecuritydo-not | 61/100 | today | |
| doubts-suplab/eeik-bootstrap.clinerules/project.md · 1 | Cline rules | teststylegit | 63/100 | today | |
| doubts-suplab/eeik-bootstrap.cursor/rules/architecture.mdc · 1 | Cursor rules | do-not | 52/100 | today | |
| doubts-suplab/eeik-bootstrap.cursor/rules/capabilities.mdc · 1 | Cursor rules | teststylegit | 58/100 | today | |
| doubts-suplab/eeik-bootstrap.cursor/rules/golden-rules.mdc · 1 | Cursor rules | gitsecuritydo-not | 61/100 | today | |
| doubts-suplab/eeik-bootstrap.cursor/rules/python.mdc · 1 | Cursor rules | lint-formatstyletypesapi+1 | 77/100 | today | |
| doubts-suplab/eeik-bootstrap.cursor/rules/security.mdc · 1 | Cursor rules | security | 39/100 | today | |
| doubts-suplab/eeik-bootstrap.github/copilot-instructions.md · 1 | Copilot instructions | lint-formatstyletesting-strategygit+2 | 54/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/a2a-protocol.instructions.md · 1 | Copilot instructions | styleagent-behaviour | 48/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/ai-governance.instructions.md · 1 | Copilot instructions | stylearchdo-notagent-behaviour | 61/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/angular.instructions.md · 1 | Copilot instructions | teststyletypestesting-strategy+4 | 69/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/architecture-governance.instructions.md · 1 | Copilot instructions | testlint-formatstylegit+4 | 65/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/autogen.instructions.md · 1 | Copilot instructions | typessecurityagent-behaviour | 50/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/aws-architecture.instructions.md · 1 | Copilot instructions | styletypessecurityperformance | 58/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/aws-data-ml-ai.instructions.md · 1 | Copilot instructions | deployment | 54/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/cdk-terraform.instructions.md · 1 | Copilot instructions | teststylearchtypes+2 | 96/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/cicd.instructions.md · 1 | Copilot instructions | stylesecuritydeploymentdo-not+1 | 65/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/containerisation.instructions.md · 1 | Copilot instructions | buildstylesecuritydo-not | 77/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/crewai.instructions.md · 1 | Copilot instructions | styleagent-behaviour | 48/100 | today | |
| doubts-suplab/eeik-bootstrap.github/instructions/data-engineering.instructions.md · 1 | Copilot instructions | teststyletypesgit+5 | 69/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| HerringtonDarkholme/megarepo.github/copilot-instructions.md · 17 | Copilot instructions | setupbuildtestlint-format+7 | 100/100 | 14 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 14 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 65 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 14 days ago | |
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 14 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 32k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 7 days ago | |
| bagisto/bagisto.github/copilot-instructions.md · 28k | Copilot instructions | setupbuildteststyle+5 | 97/100 | 14 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 13 days ago | |
| darkmatter/nixmac.github/copilot-instructions.md · 25 | Copilot instructions | setupbuildtestlint-format+8 | 96/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/doubts-suplab-eeik-bootstrap-github-instructions-fastapi-instructions)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.