fastapi-backend-guidelines

Automate FastAPI backend development with layered architecture and Domain-Driven Design.

1|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/eykissvrino/project --skill fastapi-backend-guidelines-eykissvrino
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-backend-guidelines
Source: https://github.com/eykissvrino/project/tree/main/_core/skills/fastapi-backend-guidelines
Command: npx skills add https://github.com/eykissvrino/project --skill fastapi-backend-guidelines-eykissvrino

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This set of backend guidelines codifies best practices for building scalable FastAPI applications using Domain-Driven Design, layered architecture, and modern Python tooling.

Core Features & Use Cases

  • Layered Architecture: Router → Service → Repository to ensure clean separation of concerns.
  • API Route Patterns: Consistent router structures, DI for sessions, and async handlers.
  • Data/ORM & DTOs: SQLModel/SQLAlchemy usage, asynchronous patterns, and Pydantic v2 DTOs with field_validator.
  • Domain-Driven Design: Domain-focused organization with clear boundaries and reusable primitives.

Quick Start

Create a new API domain by following the three-layer structure (domain/models, repositories, services) and register its router in the API.

Frequently Asked Questions about fastapi-backend-guidelines

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

FAQPage Schema
How do I structure a FastAPI backend using Domain-Driven Design?

Structure a FastAPI backend using a layered Router → Service → Repository architecture to ensure clean separation of concerns. Organize code by domain with clear boundaries, creating models, repositories, and services for each API domain.

How to prevent N+1 query problems in FastAPI with async SQLAlchemy?

Prevent N+1 query problems in FastAPI by applying DataLoader patterns within your repository layer. This async approach batches database queries, avoiding redundant fetches when accessing related ORM models.

What is the best way to separate read and write database sessions in FastAPI?

The best way to separate read and write database sessions in FastAPI is through Dependency Injection for asynchronous sessions. This pattern enforces clear boundaries between query and persistence operations within the repository layer.

How do I use ULID for primary keys in SQLModel and FastAPI?

Use ULID for primary keys in SQLModel by defining reusable domain primitives within your ORM models. This provides sortable, unique identifiers for your entities while maintaining async database operations.

Does this FastAPI guideline support Pydantic v2 for DTOs and validation?

Yes, these FastAPI guidelines support Pydantic v2 for Data Transfer Objects. They specify using field_validator within your DTOs to ensure strict data validation before it reaches the service and repository layers.

Why use async/await in FastAPI repository patterns?

Use async/await in FastAPI repository patterns to achieve non-blocking database I/O. This satisfies scalability requirements by ensuring concurrent request handling when the repository layer queries SQLModel or SQLAlchemy ORM models.