Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    FastAPI Production Rules

    1

    Agent skill for production-grade FastAPI: layering, transactions, multi-tenancy, auth, SQLAlchemy async, ArdiQ background tasks, testing and deployment.

    Free

    1 useSecurity scanned
    FastAPI Production Rules

    FastAPI Production Rules

    Example session with this skill installed

    Review my FastAPI ticket endpoint: it loads tickets by ID only, trusts organization_id from the body, and logs full request bodies. Give me a prioritized fix plan.

    • Read your context and instructions
    • Compiled the fastapi production rules

    Based on your description, the endpoint has two customer-data access risks and one logging risk. This is a fix plan, not a verified code audit.

    Prioritized Fix Plan

    PriorityFindingRiskRecommended change
    HighTicket lookup uses only the ticket IDA signed-in customer could retrieve another customer's ticket if they obtain its ID.Restrict the lookup to tickets belonging to the authenticated customer's organization.
    HighThe body supplies organization_idA caller could substitute another organization's ID.Remove this field from client input and derive the organization from the authenticated account.
    HighLogs contain full request bodiesTicket text and other private details may be retained in logs.Replace body logging with event names, request IDs, and safe diagnostic fields.

    Verification Before Release

    • Create tickets for two organizations. Confirm neither account can access the other's tickets.
    • Submit an unexpected organization_id and confirm validation rejects it.
    • Send a ticket containing private text and confirm the text does not appear in logs.

    Next steps

    • Share the router, service, input schema, and logging middleware for a code-level review.
    • Apply the fixes and run the access-isolation and logging checks before release.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    FastAPI Production Rules

    A set of conventions, patterns, and hard rules for building production-grade FastAPI projects.

    Structure

    SKILL.md                               # all rules, short examples, checklists
    references/
    ├── toolchain.md                       # uv, ruff, ty, pyproject.toml, CI
    ├── app-setup.md                       # settings, app factory, lifespan, middleware, CORS, OpenAPI
    ├── errors-and-responses.md            # exceptions, handlers, response wrappers, schemas, pagination
    ├── database.md                        # SQLAlchemy async, models, transactions, locking, Alembic
    ├── auth-and-security.md               # passwords, JWT, refresh tokens, magic links, roles, rate limits, uploads
    ├── logging-and-observability.md       # structlog, request context, Sentry, OpenTelemetry, health checks
    ├── background-tasks.md                # ArdiQ tasks, idempotency, retries, cron, outbox
    ├── api-patterns.md                    # idempotency keys, webhooks, streaming, outbound HTTP, SSRF, caching, audit
    ├── testing.md                         # testcontainers, fixtures, tenant-isolation and architecture tests
    ├── deployment.md                      # Dockerfile, uvicorn, migrations in the pipeline, probes
    └── crud-example.md                    # a complete domain: model → schemas → service → router → tests
    

    What it covers

    • Toolchain: uv, ruff (including FastAPI-specific rules), ty, CI
    • Project structure and app factory with lifespan
    • Router → Service → Model separation
    • One transaction per use case
    • Dependency injection with Annotated
    • Custom exceptions and one error format for every error
    • Typed response wrappers and correct status codes
    • Pydantic v2 schemas that prevent mass assignment
    • Offset and cursor pagination with stable ordering
    • Multi-tenancy and IDOR prevention
    • SQLAlchemy 2.0 async: sessions, explicit loading, integrity, locking
    • Zero-downtime Alembic migrations
    • Configuration with pydantic-settings
    • Structured logging with structlog and request IDs
    • Auth: argon2, JWT, rotating refresh tokens with reuse detection, magic links
    • Role-based authorization
    • Rate limiting
    • HTTP security: CORS, security headers, SSRF
    • File upload validation
    • Background tasks with ArdiQ: idempotency, retries, priorities, cron, transactional outbox
    • Idempotency keys and webhooks
    • Native SSE and JSON Lines streaming (FastAPI ≥ 0.135)
    • Testing with real Postgres, tenant-isolation and architecture tests
    • Health checks, Sentry, OpenTelemetry
    • Docker and deployment
    • Naming conventions
    • FastAPI gotchas
    • Security and code review checklists

    Stack

    Examples use PostgreSQL + SQLAlchemy 2.0 async + Pydantic v2 + ArdiQ + Redis, but every principle applies to any ORM or task queue.

    Related

    How I structure FastAPI projects in production — and why — the post explaining the reasoning behind these rules.

    The Python Toolchain I Use in Production: uv, ruff, and ty - another post explaining why i use all the astral stack (uv, ruff and ty)

    Targets Python 3.13+, async SQLAlchemy, and Pydantic v2. Uses PostgreSQL and ArdiQ rather than SQLite or Celery.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    1 use

    Times used to date

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    • Free with an Agensi account

    Requires

    Node.js
    Python
    pip-audit
    uv (Python tool runner)

    Permissions

    Terminal / Shell
    Read Files
    Environment Variables
    Listed1 month ago

    What's inside

    Frequently Asked Questions

    This skill provides a comprehensive framework of production-grade conventions and patterns, covering everything from multi-tenancy and transactional integrity to ArdiQ background tasks and zero-downtime migrations.

    The skill is designed to work with any modern LLM-based agent capable of processing Markdown-based rule sets and code references, allowing the agent to generate, refactor, or audit code according to these strict standards.

    You will receive a complete SKILL.md file containing the core rules and checklists, along with a suite of detailed reference documents covering the full stack from database architecture to deployment.

    While the examples utilize a high-performance stack (SQLAlchemy 2.0, Pydantic v2, ArdiQ, and PostgreSQL), the underlying architectural principles and security patterns are adaptable to other ORMs or task queues.

    Yes, the skill includes specialized patterns for multi-tenancy and IDOR prevention, ensuring your agent builds applications that maintain strict data isolation between users.

    Setup is straightforward: you provide the SKILL.md and reference directory to your AI agent's knowledge base or context window, enabling it to immediately apply these 'hard rules' to your project.

    New in APIs & Backend