원클릭으로
fastapi-backend-overview
Overview and guidelines for FastAPI 3-layer architecture with async SQLAlchemy, Pydantic v2, and best practices
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Overview and guidelines for FastAPI 3-layer architecture with async SQLAlchemy, Pydantic v2, and best practices
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
Configure Alembic for async SQLAlchemy migrations with PostgreSQL
Create FastAPI application factory with lifespan, middleware, pagination, and router configuration
Implement session-based authentication in FastAPI applications. Use when building login/logout flows, protecting endpoints with auth dependencies, creating user models with password hashing, managing sessions in database, or implementing auth exceptions. Covers HTTPBearer token validation, Argon2 password hashing, session repository/service patterns, and route protection with dependency injection.
Overview and guidelines for FastAPI 3-layer architecture with async SQLAlchemy, Pydantic v2, and best practices
Create SQLAlchemy base model with UUID, timestamp, and soft delete mixins for FastAPI
Create abstract base repository interface with CRUD, pagination, filtering, bulk operations, and soft delete
SOC 직업 분류 기준
| name | fastapi-backend-overview |
| description | Overview and guidelines for FastAPI 3-layer architecture with async SQLAlchemy, Pydantic v2, and best practices |
This stack follows a 3-layer architecture with strict separation of concerns:
Router (API Layer) → Service (Business Logic) → Repository (Data Access) → Database
| Layer | Responsibility | SQL Allowed | Imports |
|---|---|---|---|
| Router | HTTP handling, request validation, dependency injection | NO | Service, Schemas, Filters |
| Service | Business logic, orchestration, validation rules | NO | Repository, Schemas |
| Repository | Data access, SQL queries, database operations | YES | Models, SQLAlchemy |
project/
├── pyproject.toml
├── .env.example
├── .python-version # 3.12
├── ruff.toml
├── alembic.ini
├── alembic/
│ ├── env.py
│ ├── script.py.mako
│ └── versions/
├── src/
│ └── app/
│ ├── __init__.py
│ ├── main.py # App factory
│ ├── config.py # pydantic-settings
│ ├── database.py # Async SQLAlchemy
│ ├── dependencies.py # Shared dependencies (get_db)
│ ├── exceptions.py # Custom exceptions
│ ├── exception_handlers.py
│ ├── logging.py # Structured logging
│ ├── middleware/
│ │ ├── __init__.py
│ │ └── correlation_id.py
│ ├── core/ # Abstract base classes
│ │ ├── __init__.py
│ │ ├── models.py # Base model, mixins
│ │ ├── schemas.py # Base schemas
│ │ ├── repository.py # AbstractRepository
│ │ └── service.py # BaseService
│ ├── common/
│ │ ├── __init__.py
│ │ └── postgres_repository.py
│ ├── api/
│ │ ├── __init__.py
│ │ └── v1/
│ │ ├── __init__.py
│ │ └── router.py
│ └── {entity}/ # Per-entity folders
│ ├── __init__.py
│ ├── models.py
│ ├── schemas.py
│ ├── repository.py
│ ├── service.py
│ ├── router.py
│ ├── dependencies.py
│ └── filters.py
└── tests/
├── __init__.py
├── conftest.py
└── api/v1/
All models use UUID primary keys for distributed system compatibility.
All timestamps are timezone-aware UTC using DateTime(timezone=True).
Models support soft delete via deleted_at timestamp. Queries automatically filter deleted records.
Each entity (e.g., items, users) has its own folder containing all related files.
Type-safe repositories using Python generics: Repository[ModelType, CreateSchema, UpdateSchema]
Bulk operations use PostgreSQL's ON CONFLICT for upserts.
Request
↓
Middleware (Correlation ID)
↓
Router
├── Validates request (Pydantic)
├── Extracts filter params (fastapi-filter)
└── Calls Service
↓
Service
├── Applies business logic
└── Calls Repository
↓
Repository
├── Executes SQL (SQLAlchemy)
└── Returns model instances
↑
Database
All errors return a consistent JSON structure:
{
"detail": "Resource not found",
"error_code": "NOT_FOUND",
"correlation_id": "uuid",
"timestamp": "2025-01-05T12:00:00Z"
}
Load specific skills for detailed implementation:
| Skill | Purpose |
|---|---|
fastapi-project-setup | Initialize project with uv, dependencies, ruff |
fastapi-database-setup | Async SQLAlchemy engine and session |
fastapi-core-models | Base model and mixins |
fastapi-core-schemas | Base Pydantic schemas |
fastapi-core-repository | Abstract repository interface |
fastapi-postgres-repository | PostgreSQL repository implementation |
fastapi-core-service | Base service class |
fastapi-exceptions | Custom exceptions and handlers |
fastapi-logging | Structured logging with correlation IDs |
fastapi-app-factory | FastAPI app factory and main.py |
fastapi-alembic-setup | Async Alembic configuration |
fastapi-entity | Create a new entity with all files |
fastapi-testing | Test configuration and fixtures |
Depends() for all dependencies