fastapi-patterns

Organize FastAPI projects with DI wiring and DTO layering.

4|1|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/ruslan-korneev/claude-plugins --skill fastapi-patterns-ruslan-korneev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-patterns
Source: https://github.com/ruslan-korneev/claude-plugins/tree/main/plugins/fastapi/skills/fastapi-patterns
Command: npx skills add https://github.com/ruslan-korneev/claude-plugins --skill fastapi-patterns-ruslan-korneev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Align FastAPI projects to a proven architecture using Router → Service → Repository → Database with DI, reducing boilerplate and onboarding time.

Core Features & Use Cases

  • Modular architecture templates: Router → Service → Repository → Database with clear DTOs and models.
  • Dependency Injection: Wiring via dependency-injector to compose services and repositories.
  • DTOs and repositories: Pydantic v2 DTOs and a BaseRepository pattern for CRUD and transactions.
  • Use Case: Bootstrap a new module, generate endpoints, and implement a secure, testable backend.

Quick Start

Run the scaffold to generate a FastAPI module with DI wiring and DTO scaffolding.

Frequently Asked Questions about fastapi-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a FastAPI project with dependency injection and SQLAlchemy?

FastAPI project structure uses a Router → Service → Repository → Database pattern with dependency injection to reduce boilerplate. This modular architecture separates DTOs, business logic, and data access for scalable applications.

What is the best way to organize FastAPI modules for scalable applications?

Organize FastAPI modules by applying a modular architecture with clear Pydantic v2 DTOs and models. Using dependency-injector for DI container wiring composes services and repositories, accelerating development and onboarding.

How do I implement a BaseRepository pattern for CRUD operations in FastAPI?

Implement a BaseRepository pattern in FastAPI to handle CRUD operations and database transactions. This repository layer isolates SQLAlchemy database interactions from service logic, ensuring testable backend endpoints.

Does FastAPI dependency injection work with dependency-injector for service wiring?

FastAPI dependency injection works with dependency-injector for service wiring. DI container wiring composes services and repositories dynamically, reducing boilerplate and accelerating secure module bootstrapping.

Can I use Pydantic v2 DTOs with SQLAlchemy models in a FastAPI service layer?

Pydantic v2 DTOs work with SQLAlchemy models in a FastAPI service layer. DTOs structure data transfer at API boundaries, while the repository pattern manages database interactions and transactions securely.

When should I not use a layered architecture for FastAPI and SQLAlchemy applications?

Avoid a layered FastAPI architecture when building minimal endpoints or prototypes. The Router → Service → Repository overhead and dependency-injector wiring add unnecessary boilerplate for simple CRUD logic.