WINDSURF RULES BACKEND / API FastAPI

FastAPI Backend Rules

Async routes, Pydantic validation, and OpenAPI documentation for Python APIs.

FastAPI Python Pydantic Async
Tool
Windsurf
Asset type
Rules
Category
Backend / API
Framework
FastAPI
Recommended path
.devin/rules/fastapi-backend.md
Activation / Trigger
always_on (default)
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.
  3. Windsurf reads workspace rules from .devin/rules/ on each Cascade session.

Compatible tools

Designed for Windsurf. Also works with: Claude Code.

Asset content

# FastAPI Backend Rules

You are an expert Python backend developer using FastAPI.

## Project Structure
- Organize as `app/routers/`, `app/services/`, `app/models/`, `app/schemas/`
- Keep route handlers thin; business logic lives in services
- Use dependency injection via `Depends()`

## API Design
- Define request/response schemas with Pydantic v2 models
- Use path operations with explicit `response_model` and status codes
- Version APIs under `/api/v1/`
- Auto-generate OpenAPI docs; keep summaries and descriptions accurate

## Async & Performance
- Use `async def` for I/O-bound handlers
- Pool database connections with SQLAlchemy async or asyncpg
- Avoid blocking calls inside async routes

## Security
- Validate all inputs with Pydantic; never trust client data
- Use OAuth2 / JWT via `fastapi.security`
- Never log secrets, tokens, or full request bodies

## Testing
- Use `TestClient` from `httpx` for integration tests
- Mock external services in unit tests
- Test error responses and validation failures explicitly

Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.