{"id":"fastapi-templates","name":"fastapi-templates","summary":"非同期パターン、依存性注入、包括的なエラー処理を備えた本番対応のFastAPIプロジェクトを作成してください。","body":"# FastAPI Project Templates\n\nProduction-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs.\n\n## When to Use This Skill\n\n- Starting new FastAPI projects from scratch\n- Implementing async REST APIs with Python\n- Building high-performance web services and microservices\n- Creating async applications with PostgreSQL, MongoDB\n- Setting up API projects with proper structure and testing\n\n## Core Concepts\n\n### 1. Project Structure\n\n**Recommended Layout:**\n\n```\napp/\n├── api/                    # API routes\n│   ├── v1/\n│   │   ├── endpoints/\n│   │   │   ├── users.py\n│   │   │   ├── auth.py\n│   │   │   └── items.py\n│   │   └── router.py\n│   └── dependencies.py     # Shared dependencies\n├── core/                   # Core configuration\n│   ├── config.py\n│   ├── security.py\n│   └── database.py\n├── models/                 # Database models\n│   ├── user.py\n│   └── item.py\n├── schemas/                # Pydantic schemas\n│   ├── user.py\n│   └── item.py\n├── services/               # Business logic\n│   ├── user_service.py\n│   └── auth_service.py\n├── repositories/           # Data access\n│   ├── user_repository.py\n│   └── item_repository.py\n└── main.py                 # Application entry\n```\n\n### 2. Dependency Injection\n\nFastAPI's built-in DI system using `Depends`:\n\n- Database session management\n- Authentication/authorization\n- Shared business logic\n- Configuration injection\n\n### 3. Async Patterns\n\nProper async/await usage:\n\n- Async route handlers\n- Async database operations\n- Async background tasks\n- Async middleware\n\n## Detailed worked examples and patterns\n\nDetailed sections (starting with `## Implementation Patterns`) live in `references/details.md`. Read that file when the navigation summary above is insufficient.\n\n## Testing\n\n```python\n# tests/conftest.py\nimport pytest\nimport asyncio\nfrom httpx import AsyncClient\nfrom sqlalchemy.ext.asyncio import create_async_engine, AsyncSession\nfrom sqlalchemy.orm import sessionmaker\n\nfrom app.main import app\nfrom app.core.database import get_db, Base\n\nTEST_DATABASE_URL = \"sqlite+aiosqlite:///:memory:\"\n\n@pytest.fixture(scope=\"session\")\ndef event_loop():\n    loop = asyncio.get_event_loop_policy().new_event_loop()\n    yield loop\n    loop.close()\n\n@pytest.fixture\nasync def db_session():\n    engine = create_async_engine(TEST_DATABASE_URL, echo=True)\n    async with engine.begin() as conn:\n        await conn.run_sync(Base.metadata.create_all)\n\n    AsyncSessionLocal = sessionmaker(\n        engine, class_=AsyncSession, expire_on_commit=False\n    )\n\n    async with AsyncSessionLocal() as session:\n        yield session\n\n@pytest.fixture\nasync def client(db_session):\n    async def override_get_db():\n        yield db_session\n\n    app.dependency_overrides[get_db] = override_get_db\n\n    async with AsyncClient(app=app, base_url=\"http://test\") as client:\n        yield client\n\n# tests/test_users.py\nimport pytest\n\n@pytest.mark.asyncio\nasync def test_create_user(client):\n    response = await client.post(\n        \"/api/v1/users/\",\n        json={\n            \"email\": \"test@example.com\",\n            \"password\": \"testpass123\",\n            \"name\": \"Test User\"\n        }\n    )\n    assert response.status_code == 201\n    data = response.json()\n    assert data[\"email\"] == \"test@example.com\"\n    assert \"id\" in data\n```","author":"@wshobson","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/wshobson/agents/tree/main/plugins/api-scaffolding/skills/fastapi-templates","license":"MIT","category":"coding","lang":"en","tokens":795,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/details.md","size":11627,"sha256":"23bf5358c43675a10e26cb1f949e183d53f17e54118bca45d10a08bb8b218b31"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}