jawwad-ali/claude-code-skills
Overview
This skill provides practical, opinionated guidance for building and maintaining FastAPI applications. It focuses on project structure, request/response validation with Pydantic, routing, dependency injection, authentication, middleware, error handling, and async best practices. Use it whenever you read, edit, or create Python files that involve FastAPI, Starlette, or Pydantic models for web APIs.
How this skill works
The skill inspects FastAPI-related code patterns and suggests improvements across structure, typing, and runtime behavior. It checks for proper use of Pydantic models, APIRouters, dependency injection, async/await for I/O, and common middleware and error-handler patterns. It also guides implementing OAuth2/JWT authentication, background tasks, WebSocket endpoints, and clear response models with appropriate status codes.
When to use it
- Creating a new FastAPI app or project layout
- Adding or reviewing API endpoints or APIRouters
- Designing Pydantic request/response models and validation
- Implementing authentication (OAuth2/JWT) or protected routes
- Adding middleware, background tasks, WebSockets, or error handlers
- Refactoring sync I/O to async and improving dependency injection
Best practices
- Organize code into app/, routers/, models/, services/, and db/ for separation of concerns
- Use Pydantic models for all input/output and set model_config for ORM compatibility
- Keep route handlers thin; move business logic to service modules
- Prefer async/await for database and HTTP I/O; use TestClient for synchronous tests
- Use FastAPI dependencies for shared resources (DB sessions, auth) and close them cleanly
- Add clear error handlers and return proper HTTP status codes and JSON error shapes
Example use cases
- Scaffold a new API with routers for users and items and include them in main.py
- Add OAuth2PasswordBearer token endpoint and secure /users/me with dependency injection
- Replace ad-hoc validation with Pydantic models and descriptive Field constraints
- Add a CORS middleware and a request timing middleware for observability
- Implement background email sending with BackgroundTasks and a file-based log task
FAQ
Use APIRouter to group related endpoints, keep main.py small, and enable prefixing, tagging, and easier testing and reuse.
How do I protect endpoints with JWT tokens?
Use OAuth2PasswordBearer to extract tokens, verify them with jose.jwt, load the user in a dependency, and raise 401/403 errors for invalid or inactive users.
5 skills
This skill guides building high-performance FastAPI applications by structuring code, validating data with Pydantic, and implementing secure, scalable APIs.
This skill helps you write modern production Python code by applying best practices, typing, testing, and packaging across projects.
This skill helps you design and deploy OpenAI Agents SDK powered multi-agent systems with handoffs, guardrails, tools, and tracing.
This skill decides when to route questions between curated skills and Context7 to optimize documentation lookups for frameworks, libraries, and APIs.
This skill guides you through Next.js App Router patterns, server/client components, and routing files to read, review, or create app directory files.