Skip to content
affaan-m avatar

Fastapi Patterns

Production FastAPI patterns covering project layout, Pydantic v2 schemas, dependency injection, auth, and testing.

CCM score
73 of 100
skills.sh installs
9.4K
GitHub stars
312.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers project layout, app factory and lifespan, pydantic-settings configuration, Pydantic v2 schemas, dependency injection, routers, and testing with httpx and pytest
  • Includes sample code for main.py, config.py, dependencies.py, schemas/user.py, and routers/users.py, with JWT-based get_current_user and active-user checks
  • Enforces password confirmation through a model validator and blocks unauthorized updates by comparing the current user's ID to the target user
  • Designed for teams building or reviewing FastAPI apps with SQLAlchemy async sessions and Pydantic schemas

Install

$ npx -y skills add affaan-m/ecc --skill fastapi-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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

Details

Repository
github.com/affaan-m/ecc
Categories
Python, Backend & APIs
First seen
Jul 14, 2026

Questions

What does the fastapi-patterns skill do for my FastAPI app?

The fastapi-patterns skill gives best practices for FastAPI development, covering project structure, Pydantic v2 schemas, dependency injection, async handlers, authentication, authorization, transactional service layers, and testing with httpx and pytest. It applies when you are building or reviewing FastAPI apps that use Pydantic schemas, dependencies, async handlers, auth, or tests.

How do I install the fastapi-patterns skill?

Run npx -y skills add affaan-m/ecc --skill fastapi-patterns -y in your project. Once installed, the agent gets the FastAPI guidance for project layout, schemas, dependencies, auth and tests.

Where does fastapi-patterns rank among Python skills?

On the Python category page, fastapi-patterns ranks in the top 25. Other skills in that category include python-performance-optimization and python-design-patterns.

Which patterns for FastAPI apps does this skill cover?

The skill shows an app factory with lifespan handling, configuration through pydantic-settings, and Pydantic v2 request and response schemas. It also covers router design, database session dependencies, and JWT-based current-user checks for protected endpoints.

More from affaan-m/ecc

All 257

Similar to Fastapi Patterns

More Python