backend-dev
バックエンド開発(FastAPI/Python)のベストプラクティスと規約
When & Why to Use This Skill
This Claude skill serves as a comprehensive guide for backend development using FastAPI and Python, focusing on industry-standard best practices. It helps developers implement a robust layered architecture, enforce dependency injection, and maintain high code quality through structured conventions and a rigorous implementation checklist.
Use Cases
- Designing a scalable FastAPI backend using a layered architecture (API, Service, and Repository layers) to ensure clear separation of concerns.
- Implementing Dependency Injection (DI) patterns to create decoupled, testable, and maintainable Python codebases.
- Conducting automated code reviews or manual audits using the provided checklist to verify Pydantic validation, async/await usage, and type hinting.
- Establishing standardized logging and error-handling protocols to improve system observability while preventing sensitive data leaks.
- Optimizing database interactions and API performance by identifying and resolving N+1 problems and ensuring proper status code usage.
| name | backend-dev |
|---|---|
| description | バックエンド開発(FastAPI/Python)のベストプラクティスと規約 |
バックエンドのコーディング規約
- 依存性注入 (DI): 依存性注入を徹底し、上位層は抽象化に依存する。
- レイヤーアーキテクチャ:
- サービス層の責任を明確化する。
- API 層は通信処理のみ。
- ビジネスロジックはサービス層。
- データ処理はリポジトリ層に分離する。
- モジュール構成: モジュールは機能単位で整理し、ルーティングやサービスを肥大化させない。
- サービス統合: 複数サービスの統合はコーディネーションサービスを用いて抽象化し、API 層では複雑な処理を記述しない。
- ログ出力:
- ログは目的と対象を明確にする。
- INFO は主要操作の開始・完了。
- DEBUG は開発者向けの詳細追跡に限定する。
- 禁止事項: 機密データを含む内容を出力してはならない。
実装チェックリスト
- 入力バリデーションは適切か(Pydantic モデルの使用)
- エラーハンドリングは適切か(HTTPException の使用、適切なステータスコード)
- 認証・認可は適切に実装されているか
- N+1 問題などのパフォーマンス問題はないか
- 非同期処理(async/await)は適切に使用されているか
- 型ヒントは全ての関数・メソッドに付与されているか