
Fastapi Patterns
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-codeInstalls 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- Frontend Design1.8K
- Mysql Patterns1.8K
- Pubmed Database1.8K
- Windows Desktop E2e1.8K
- Agent Architecture Audit1.7K
- Agentic Os1.7K
- Angular Developer1.7K
- Cisco Ios Patterns1.7K
- Django Celery1.7K
- Ecc Guide1.7K
- Error Handling1.7K
- Flox Environments1.7K
- Frontend Design Direction1.7K
- Homelab Network Readiness1.7K
- Homelab Network Setup1.7K
- Ios Icon Gen1.7K
- Make Interfaces Feel Better1.7K
- Motion Advanced1.7K
- Motion Ui1.7K
- Netmiko Ssh Automation1.7K
- Network Bgp Diagnostics1.7K
- Network Config Validation1.7K
- Network Interface Health1.7K
- Plan Orchestrate1.7K