fastapi-best-practices
FastAPIを活用し、スケーラブルで高性能なWeb APIを構築するための、プロジェクト構成、非同期処理、データ検証、依存性注入、データベース設計など、実践的なノウハウを提供するSkill。
📜 元の英語説明(参考)
FastAPI production-grade best practices and guidelines for building scalable, high-performance web APIs. Covers project structure, async concurrency, Pydantic validation, dependency injection, and database patterns.
🇯🇵 日本人クリエイター向け解説
FastAPIを活用し、スケーラブルで高性能なWeb APIを構築するための、プロジェクト構成、非同期処理、データ検証、依存性注入、データベース設計など、実践的なノウハウを提供するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o fastapi-best-practices.zip https://jpskill.com/download/10685.zip && unzip -o fastapi-best-practices.zip && rm fastapi-best-practices.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10685.zip -OutFile "$d\fastapi-best-practices.zip"; Expand-Archive "$d\fastapi-best-practices.zip" -DestinationPath $d -Force; ri "$d\fastapi-best-practices.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
fastapi-best-practices.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
fastapi-best-practicesフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
FastAPI ベストプラクティス
FastAPI アプリケーション向けの包括的なプロダクショングレードのベストプラクティスです。自動リファクタリングとコード生成を導くための、7つのカテゴリにわたるルールが含まれています。
適用するタイミング
以下の状況でこれらのガイドラインを参照してください。
- 新しい FastAPI プロジェクト構造をセットアップするとき
- 非同期ルートを実装し、ブロッキング I/O を処理するとき
- Pydantic モデルとバリデーションロジックを設計するとき
- 再利用可能なバリデーションとインジェクションのために依存関係を構造化するとき
- SQLAlchemy と Alembic を使用してデータベースを統合するとき
- テストを記述し、CI/CD ツールを構成するとき
優先度別のルールカテゴリ
| 優先度 | カテゴリ | 影響 | プレフィックス |
|---|---|---|---|
| 1 | Async & Concurrency | CRITICAL | async- |
| 2 | Project Structure | HIGH | structure- |
| 3 | Pydantic Patterns | HIGH | pydantic- |
| 4 | Dependency Injection | MEDIUM-HIGH | dependency- |
| 5 | Database & Storage | MEDIUM | db- |
| 6 | REST & API Design | MEDIUM | api- |
| 7 | Testing & Tooling | LOW-MEDIUM | tooling- |
| 8 | Code Maintenance | LOW | maintenance- |
| 9 | Performance Optimization | MEDIUM | performance- |
| 10 | TDD Strategy | HIGH | tdd- |
クイックリファレンス
1. Async & Concurrency (CRITICAL)
async-io-intensive- awaitable にはasync defを、ブロッキング I/O にはdefを使用するasync-cpu-intensive- CPU 負荷の高い処理を multiprocessing/Celery にオフロードするasync-sync-sdk- 非同期ルートで同期 SDK を使用する場合はrun_in_threadpoolを使用する
2. Project Structure (HIGH)
structure-domain-driven- ファイルタイプではなく、ドメイン (src/{domain}) で整理する
3. Pydantic Patterns (HIGH)
pydantic-validation- 組み込みの regex、enums などを使用するpydantic-custom-base- グローバルなシリアライゼーションにはカスタムのベースモデルを使用するpydantic-config- ドメインごとに BaseSettings を分割するpydantic-value-error- バリデーションエラーには ValueError を発生させる
4. Dependency Injection (MEDIUM-HIGH)
dependency-validation- DB をバックエンドとするバリデーションには Depends を使用するdependency-chaining- 再利用のために依存関係をチェーンするdependency-decoupling- 小さな再利用可能なユニットに分離するdependency-async- 非同期の依存関係を優先する
5. Database & Storage (MEDIUM)
db-naming-conventions- 厳密な命名規則 (snake_case、単数形など)db-index-naming- 明示的なインデックス命名規則db-sql-first- 複雑なデータロジックには SQL を優先するdb-migrations- 静的で、記述的で、可逆的なマイグレーション
6. REST & API Design (MEDIUM)
api-path-naming- 依存関係の再利用のために一貫したパス変数を使用するapi-response-serialization- シリアライゼーションのオーバーヘッドを最小限に抑えるapi-docs-hiding- 本番環境ではドキュメントを非表示にするapi-docs-customization- 詳細な OpenAPI メタデータ
7. Testing & Tooling (LOW-MEDIUM)
tooling-test-client- テストには AsyncClient/httpx を使用するtooling-linter- すべての linting に Ruff を使用する
8. 新しい機能 (マージ済み)
- Scripts: ヘルパースクリプトは
scripts/で利用可能です (例:run_ruff.py)。 - References: 追加のガイドは
references/にあります (例:quad_strategy.md)。 - TDD: 明示的なテスト戦略は
rules/tdd-strategy.mdにあります。
使い方
詳細な説明とコード例については、個々のルールファイルをお読みください。
rules/async-io-intensive.md
rules/structure-domain-driven.md
完全なコンパイル済みドキュメント
すべてのルールが展開された完全なガイドについては、AGENTS.md を参照してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
FastAPI Best Practices
Comprehensive production-grade best practices for FastAPI applications. Contains rules across 7 categories to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Setting up a new FastAPI project structure
- Implementing async routes and handling blocking I/O
- Designing Pydantic models and validation logic
- Structuring dependencies for reusable validation and injection
- Integrating databases with SQLAlchemy and Alembic
- Writing tests and configuring CI/CD tooling
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Async & Concurrency | CRITICAL | async- |
| 2 | Project Structure | HIGH | structure- |
| 3 | Pydantic Patterns | HIGH | pydantic- |
| 4 | Dependency Injection | MEDIUM-HIGH | dependency- |
| 5 | Database & Storage | MEDIUM | db- |
| 6 | REST & API Design | MEDIUM | api- |
| 7 | Testing & Tooling | LOW-MEDIUM | tooling- |
| 8 | Code Maintenance | LOW | maintenance- |
| 9 | Performance Optimization | MEDIUM | performance- |
| 10 | TDD Strategy | HIGH | tdd- |
Quick Reference
1. Async & Concurrency (CRITICAL)
async-io-intensive- Useasync deffor awaitables,deffor blocking I/Oasync-cpu-intensive- Offload CPU work to multiprocessing/Celeryasync-sync-sdk- Userun_in_threadpoolfor sync SDKs in async routes
2. Project Structure (HIGH)
structure-domain-driven- Organize by domain (src/{domain}), not file type
3. Pydantic Patterns (HIGH)
pydantic-validation- Use built-in regex, enums, etc.pydantic-custom-base- Use custom base model for global serializationpydantic-config- Split BaseSettings by domainpydantic-value-error- Raise ValueError for validation errors
4. Dependency Injection (MEDIUM-HIGH)
dependency-validation- Use Depends for DB-backed validationdependency-chaining- Chain dependencies for reusedependency-decoupling- Decouple into small reusable unitsdependency-async- Prefer async dependencies
5. Database & Storage (MEDIUM)
db-naming-conventions- Strict naming (snake_case, singular, etc.)db-index-naming- Explicit index naming conventionsdb-sql-first- Prefer SQL for complex data logicdb-migrations- Static, descriptive, reversible migrations
6. REST & API Design (MEDIUM)
api-path-naming- Consistent path vars for dependency reuseapi-response-serialization- Minimize serialization overheadapi-docs-hiding- Hide docs in productionapi-docs-customization- Detailed OpenAPI metadata
7. Testing & Tooling (LOW-MEDIUM)
tooling-test-client- Use AsyncClient/httpx for teststooling-linter- Use Ruff for all linting
8. New Capabilities (Merged)
- Scripts: Helper scripts available in
scripts/(e.g.,run_ruff.py). - References: Additional guides in
references/(e.g.,quad_strategy.md). - TDD: Explicit testing strategies in
rules/tdd-strategy.md.
How to Use
Read individual rule files for detailed explanations and code examples:
rules/async-io-intensive.md
rules/structure-domain-driven.md
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md