FastAPI, PostgreSQL & Supabase Production (.cursorrules)
Eliminates common Python AI code generation traps: synchronous database calls in async routes, outdated Pydantic v1 syntax, and missing transaction rollbacks.
Parametric Customizer & Compiler Live Tool
Adjust the variables below. The prompt code and API payload update dynamically in real time.
Specifies how asynchronous worker queues should be constructed.
Tells Cursor which authentication middlewares to scaffold.
# CURSOR RULES FOR FASTAPI & SUPABASE BACKEND You are a Principal Python Architect specializing in FastAPI, Pydantic v2, async SQLAlchemy 2.0, and Supabase PostgreSQL. ### TECH STACK REQUIREMENTS: - Python: 3.12+ with strict type hints throughout - Web Framework: FastAPI (modern APIRouter modular architecture) - Schema Validation: Pydantic v2 (use model_config = ConfigDict(...), never v1 class Config) - Database: PostgreSQL on Supabase managed via asyncpg & SQLAlchemy 2.0 async engine - Background Jobs: FastAPI native BackgroundTasks (for lightweight webhooks & emails) - Authentication: Supabase Auth JWT verification with FastAPI dependency injection ### ARCHITECTURAL CONSTRAINTS: 1. **Pure Asynchronous Execution**: - ALL database queries must use `await session.execute(...)` and async session context managers. - Never introduce synchronous blocking operations (`time.sleep()`, synchronous `requests.get()`) into route handlers. 2. **Security & Row-Level Security (RLS)**: - All Supabase tables MUST enforce Row-Level Security. - Route dependencies must validate JWT claims before touching ORM models. 3. **API Design Standards**: - Return strict Pydantic response models using `response_model=...` - Handle errors with explicit `HTTPException(status_code=..., detail=...)` and custom domain exception handlers. - Paginate all list endpoints using cursor-based or limit-offset structures.
Code with full codebase indexing and instant multi-file generation.
Leonardo Phoenix & Flux: Generate photorealistic studio assets with 150 daily free credits. Zero setup required.
πΈ Real Sample Outputs & Verified Results
Visual evidence and benchmark responses generated using this exact prompt formula.
π¬ Prompt Engineering Anatomy
Why this prompt consistently delivers high-tier results: technical parameter breakdown.
Pydantic v2 Migration Constraint Cursor often mixes Pydantic v1 (`.dict()`, `class Config`) and v2 (`.model_dump()`, `model_config`). Explicitly pinning v2 removes dozens of deprecation warnings.
Async SQLAlchemy 2.0 scalar_one_or_none() syntax Legacy SQLAlchemy 1.4 syntax like `query.first()` breaks under modern async sessions. Pinning 2.0 standardizes execution queries.
π¬ Frequently Asked Questions
Troubleshooting common edge cases, model incompatibilities, and best practices.
Where should I save this file in my FastAPI repository?
Save it as `.cursorrules` in the root folder of your project, right next to your `pyproject.toml` or `requirements.txt`.
Does this work with Windsurf or GitHub Copilot?
Yes! Windsurf automatically reads `.windsurfrules` (you can create a symlink or rename it).
Explore Related AI Coding & Rulesets Prompts View all β
DeepSeek R1 Architecture & Security Vulnerability Code Auditor
Engineered specifically for DeepSeek R1 and reasoning models. Directs the thinking tokens (<think>) to rigorously stress-test edge cases before proposing optimized refactors.
cursorCursor AI (.cursorrules) for Next.js 15, React 19 & Tailwind CSS
Stops Cursor from writing outdated Next.js 13 patterns, Pages Router syntax, or deprecated React hooks. Enforces strict TypeScript, Server Actions, and modular clean architecture.
cursorReact Native & Expo Router Mobile App Production (.cursorrules)
Stops Cursor from generating legacy class components, obsolete React Navigation boilerplate, or memory-leaking animation loops on iOS and Android.