python-fastapi-architecture
Use when the user asks about FastAPI, setting up a FastAPI project with dependency injection and Pydantic models, Depends(), APIRouter structure, lifespan…
от j4flmao★ 47 звёзд на GitHub
Установить python-fastapi-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Python FastAPI Architecture
Purpose
Structure FastAPI applications with Clean Architecture. Pydantic at boundaries only. Domain entities are pure Python dataclasses. FastAPI routers are thin. Dependency injection via Depends.
Agent Protocol
Trigger
Exact user phrases: "FastAPI structure", "FastAPI architecture", "FastAPI folder", "FastAPI clean arch", "FastAPI router", "FastAPI dependency injection", "Python backend structure".
Input Context
Before activating, verify:
- requirements.txt or pyproject.toml has fastapi dependency.
- The feature or module being created is known.
Output Artifact
No file output. Produces folder structure and code examples as text.
Response Format
Folder structure:
src/
main.py
api/v1/endpoints/
core/
domain/
application/use_cases/
infrastructure/database/
schemas/
Code: module-level only. No import statements.
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- src/ directory structure follows Clean Architecture.
- Domain entities are pure Python (dataclasses). No Pydantic. No SQLAlchemy.
- Pydantic schemas exist only in src/schemas/ (API boundary).
- Repository interfaces are ABCs in domain/.
- Repository implementations use SQLAlchemy in infrastructure/.
- FastAPI routers use Depends() for DI.
- One endpoint file per resource in api/v1/endpoints/.
Max Response Length
Folder structure: unlimited. Code: 15 lines per example.
Architecture Decision Trees
FastAPI vs Django vs Flask
| Criterion | FastAPI | Django | Flask |
|---|---|---|---|
| Async | Native (async def) | Partial (3.1+ async) | Limited (async extra) |
| Validation | Pydantic (built-in) | DRF Serializers | Manual / Flask-Marshmallow |
| Performance | High (Starlette + Uvicorn) | Moderate | Low |
| DI system | Depends() | No built-in | Flask-Injector |
| Ecosystem | Growing | Largest | Large |
| Auto-docs | OpenAPI (built-in) | DRF-YASG | Flask-Smorest |
Decision: Async + type safety + auto-docs → FastAPI. Full framework ecosystem → Django. Microservice/simple → FastAPI. Legacy or simple → Flask.
Clean Architecture vs Simple Router Structure
| Criterion | Clean Architecture | Simple Router |
|---|---|---|
| Project size | Large (5+ modules) | Small (1-3 modules) |
| Team size | 3+ developers | 1-2 developers |
| Testability | High (isolated layers) | Moderate |
| Boilerplate | More files per module | Less files per module |
| Domain complexity | Complex business rules | Simple CRUD |
Decision: Complex domain with business rules → Clean Architecture. Simple CRUD or small project → Simple Router with services.
Workflow
Step 1: Create Folder Structure
src/
main.py -- FastAPI app creation, middleware, startup
api/
v1/
__init__.py
router.py -- Include all v1 routers
endpoints/
users.py -- One file per resource
orders.py
core/
config.py -- Pydantic Settings
security.py -- Auth dependencies
dependencies.py -- Shared dependencies
domain/
entities.py -- Pure dataclasses. No framework code.
repositories.py -- ABC classes (interfaces)
services.py -- Domain services
application/
use_cases/
create_user.py -- One use case per file
get_user.py
infrastructure/
database/
models.py -- SQLAlchemy ORM models
repositories.py -- Implement domain ABCs
session.py -- Session factory
external/
email_service.py
schemas/
user.py -- Pydantic request/response schemas
common.py -- Shared schemas (pagination, error)
order.py
tests/
test_api/
test_users.py
test_application/
test_create_user.py
Step 2: Domain Entity (Pure Python)
from dataclasses import dataclass, field
from uuid import uuid4, UUID
from datetime import datetime, timezone
@dataclass
class User:
id: UUID = field(default_factory=uuid4)
email: str = ""
name: str = ""
is_active: bool = True
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
@classmethod
def create(cls, email: str, name: str) -> "User":
if not email or "@" not in email:
raise ValueError("Invalid email")
return cls(email=email, name=name)
def deactivate(self) -> None:
self.is_active = False
@dataclass
class Order:
id: UUID = field(default_factory=uuid4)
user_id: UUID = field(default_factory=uuid4)
status: str = "pending"
total: float = 0.
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/dependency-injection-patterns.md
- references/fastapi-advanced.md
- references/fastapi-background.md
- references/fastapi-dependency-injection.md
- references/fastapi-routing-patterns.md
- references/fastapi-structure.md
- references/fastapi-testing.md
- references/fastapi-websocket.md
- references/middleware-background.md
- references/testing-debugging.md
FAQ
Что делает скилл python-fastapi-architecture?
Use when the user asks about FastAPI, setting up a FastAPI project with dependency injection and Pydantic models, Depends(), APIRouter structure, lifespan events or async SQLAlchemy. Produces a layered FastAPI project. Not for Django (use python-django-architecture) or Flask (use flask-backend).
Как установить скилл python-fastapi-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл python-fastapi-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…