Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Part of a 72-plugin marketplace with 112 AI agents and 146 skills for Claude Code development automation.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: fastapi-templates3description: Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.4---56# FastAPI Project Templates78Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs.910## When to Use This Skill1112- Starting new FastAPI projects from scratch13- Implementing async REST APIs with Python14- Building high-performance web services and microservices15- Creating async applications with PostgreSQL, MongoDB16- Setting up API projects with proper structure and testing1718## Core Concepts1920### 1. Project Structure2122**Recommended Layout:**2324```25app/26├── api/ # API routes27│ ├── v1/28│ │ ├── endpoints/29│ │ │ ├── users.py30│ │ │ ├── auth.py31│ │ │ └── items.py32│ │ └── router.py33│ └── dependencies.py # Shared dependencies34├── core/ # Core configuration35│ ├── config.py36│ ├── security.py37│ └── database.py38├── models/ # Database models39│ ├── user.py40│ └── item.py41├── schemas/ # Pydantic schemas42│ ├── user.py43│ └── item.py44├── services/ # Business logic45│ ├── user_service.py46│ └── auth_service.py47├── repositories/ # Data access48│ ├── user_repository.py49│ └── item_repository.py50└── main.py # Application entry51```5253### 2. Dependency Injection5455FastAPI's built-in DI system using `Depends`:5657- Database session management58- Authentication/authorization59- Shared business logic60- Configuration injection6162### 3. Async Patterns6364Proper async/await usage:6566- Async route handlers67- Async database operations68- Async background tasks69- Async middleware7071## Detailed worked examples and patterns7273Detailed sections (starting with `## Implementation Patterns`) live in `references/details.md`. Read that file when the navigation summary above is insufficient.7475## Testing7677```python78# tests/conftest.py79import pytest80import asyncio81from httpx import AsyncClient82from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession83from sqlalchemy.orm import sessionmaker8485from app.main import app86from app.core.database import get_db, Base8788TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"8990@pytest.fixture(scope="session")91def event_loop():92loop = asyncio.get_event_loop_policy().new_event_loop()93yield loop94loop.close()9596@pytest.fixture97async def db_session():98engine = create_async_engine(TEST_DATABASE_URL, echo=True)99async with engine.begin() as conn:100await conn.run_sync(Base.metadata.create_all)101102AsyncSessionLocal = sessionmaker(103engine, class_=AsyncSession, expire_on_commit=False104)105106async with AsyncSessionLocal() as session:107yield session108109@pytest.fixture110async def client(db_session):111async def override_get_db():112yield db_session113114app.dependency_overrides[get_db] = override_get_db115116async with AsyncClient(app=app, base_url="http://test") as client:117yield client118119# tests/test_users.py120import pytest121122@pytest.mark.asyncio123async def test_create_user(client):124response = await client.post(125"/api/v1/users/",126json={127"email": "[email protected]",128"password": "testpass123",129"name": "Test User"130}131)132assert response.status_code == 201133data = response.json()134assert data["email"] == "[email protected]"135assert "id" in data136```137