vstorm-co/production-stack-skills/production-fastapi
Claude Code and agent skill by vstorm-co/production-stack-skills
- community
Checking that the SKILL.md file is still in the repository.
Production-grade FastAPI patterns — structured logging, health checks, graceful shutdown, middleware, Pydantic v2, async patterns, error handling, and security hardening. Use this skill when the user is building or modifying a FastAPI application, working with Pydantic models, configuring Starlette middleware, setting up Uvicorn/Gunicorn, or asks about FastAPI best practices. Triggers when importing fastapi, starlette, pydantic, or uvicorn. Also trigger when user says /production fastapi. DO NOT trigger for Django or Flask unless explicitly asked.
Install
npx vskill@latest install vstorm-co/production-stack-skills/production-fastapiSKILL.md
The same SKILL.md was published earlier as vstorm-co/production-stack-skills/production-fastapi.
Production FastAPI
This skill encodes battle-tested patterns for shipping FastAPI applications that survive real production traffic. Every recommendation here comes from outage post-mortems, not blog posts. The patterns are opinionated — this is a senior engineer review, not a tutorial.
See templates/ for copy-paste-ready implementations of every pattern below.
1. Application Lifecycle
Use `lifespan`, not `on_event`. The on_event decorator is deprecated and does not support shared state between startup and shutdown.
Why lifespan matters:
- Resources created in startup are guaranteed to be cleaned up in shutdown
- The
yieldpattern makes it impossible to forget cleanup app.stateshares resources across the request lifecycle without globals- If startup fails, the app never starts accepting traffic
Startup checklist:
- Database engine/connection pool
- HTTP client pool (reuse connections)
- Logging configuration
- Cache connections (Redis)
- Background task schedulers
Shutdown checklist (reverse order):
- Cancel background tasks
- Close HTTP client pools
- Dispose database engine (waits for active connections)
- Flush log buffers
2. Structured Logging
Use structlog with JSON output in production, pretty console in development. Never use print() or logging.basicConfig().
CRITICAL: Never use `BaseHTTPMiddleware` for logging or request ID injection. It breaks contextvars because it runs the endpoint in a different task than the middleware. Use pure ASGI middleware instead:
See templates/logging_config.py for the complete structlog setup and templates/middleware.py for all ASGI middleware implementations.
3. Health Checks
Every production service needs two health endpoints. No exceptions.
Health check rules:
/health/live— NEVER check dependencies. If the process is running, return 200. Used by load balancers to detect crashed processes./health/ready— Check every dependency with a 2-second timeout each. Used by Kubernetes readiness probes and orchestrators.- Exclude health endpoints from access logs (noise).
- Exclude health endpoints from authentication middleware.
- Return structured JSON, not just a status code — operators need to see which dependency is down.
See templates/health_checks.py for the complete implementation with timing, startup checks, and Kubernetes probe configuration.
4. Error Handling
Use RFC 7807 Problem Details format. Consistent error responses are non-negotiable in production.
Error handling rules:
- Every error response includes
request_id— this is the lifeline for debugging in production - Known errors (validation, auth, not found) return specific status codes and human-readable messages
- Unknown errors return 500 with a generic message — never expose tracebacks, SQL queries, or internal paths
- Log every error with full context (the log has the traceback; the response does not)
- Send unexpected errors to Sentry/error tracking with the request_id
See templates/error_handlers.py for the complete exception hierarchy and handler registration.
5. Middleware Stack
Order matters. Middleware executes in an onion model — first added is outermost. Design accordingly:
CORS: Never Wildcard With Credentials
Pure ASGI Middleware Template
Always use this pattern instead of BaseHTTPMiddleware:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/production-fastapi/SKILL.md
Popularity
- Repository stars
- 26
- Repository forks
- 7
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/vstorm-co/production-stack-skills/production-fastapi)