A solid reference for structuring production FastAPI services around dependency injection and explicit layers. You get patterns for app factories with lifespan hooks, separate Pydantic schemas for create/update/response, async database sessions, OAuth2 token dependencies, and test fixtures that override dependencies instead of hitting real resources. The security checklist covers the basics (Argon2, JWT validation, CORS credentials). Useful when you're reviewing a FastAPI PR and want concrete examples of where routers, schemas, and CRUD logic should live, or when you're tired of seeing password hashes leak into response models because someone skipped the response_model declaration.

skills.sh installs
1.8K
GitHub stars
229.1K
last updated
Jul 14, 2026

Install

$ npx -y skills add affaan-m/everything-claude-code --skill fastapi-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

FastAPI Patterns

Modern, production-grade FastAPI development: project layout, Pydantic v2 schemas, dependency injection, async patterns, auth, transactional service methods, and testing.

Project Structure

my_app/
|-- app/
|   |-- main.py               # App factory, lifespan, middleware
|   |-- config.py             # Settings via pydantic-settings
|   |-- dependencies.py       # Shared FastAPI dependencies
|   |-- database.py           # SQLAlchemy engine + session
|   |-- routers/
|   |   `-- users.py
|   |-- models/               # SQLAlchemy ORM models
|   |   `-- user.py
|   |-- schemas/              # Pydantic request/response schemas
|   |   `-- user.py
|   `-- services/             # Business logic layer
|       `-- user_service.py
|-- tests/
|   |-- conftest.py
|   `-- test_users.py
|-- pyproject.toml
`-- .env

App Factory and Lifespan

# app/main.py
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.config import settings
from app.database import engine, Base
from app.routers import users

Sponsors

Details

Repository
github.com/affaan-m/everything-claude-code
Category
Python
First seen
Jun 3, 2026

More from affaan-m/everything-claude-code

All 256

Recommended

More Python
1github avatarruff-recursive-fixgithub/awesome-copilotRun Ruff checks with optional scope and rule overrides, apply safe and unsafe autofixes iteratively, review each change, and resolve remaining findings with tar1.5Kskills.sh installs
2mindrally avatarpython-cybersecurity-tool-developmentmindrally/skillsGuidelines for building Python cybersecurity tools with secure coding practices, async scanning, and structured security testing.1Kskills.sh installs
3vintasoftware avatarcdrf-expertvintasoftware/django-ai-pluginsExpert guidance for Django REST Framework class-based views using Classy DRF (https://www.cdrf.co). Use when selecting or debugging APIView, GenericAPIView, con544skills.sh installs
4auth0 avatarauth0-fastapi-apiauth0/agent-skillsUse when protecting FastAPI endpoints with JWT Bearer token validation, scope checks, or DPoP binding. Integrates auth0-fastapi-api for stateless APIs receiving461skills.sh installs
5martinholovsky avatarcelery-expertmartinholovsky/claude-skills-generatorExpert Celery distributed task queue engineer specializing in async task processing, workflow orchestration, broker configuration (Redis/RabbitMQ), Celery Beat 458skills.sh installs
6sickn33 avatarpython-testing-patternssickn33/antigravity-awesome-skillspython testing patterns394skills.sh installs