スキル一覧に戻る
NaveedTechLab

fastapi-backend-builder

by NaveedTechLab

0🍴 0📅 2026年1月11日
GitHubで見るManusで実行

SKILL.md


name: fastapi-backend-builder description: Generate clean, production-ready FastAPI backends with RESTful API design, Pydantic models, SQLAlchemy database integration, and authentication-ready structure. Use when building new FastAPI projects, creating REST APIs, setting up backend services, implementing CRUD endpoints, or scaffolding Python web applications. Produces Kubernetes-ready, scalable project structures.

FastAPI Backend Builder

Generate production-ready FastAPI backends following clean architecture principles with proper separation of concerns.

Quick Start

Copy the template from assets/template/ to create a new project:

cp -r assets/template/ ./my-project
cd my-project
pip install -e ".[dev]"
uvicorn app.main:app --reload

Architecture Principles

  1. No business logic in endpoints - Routes delegate to services
  2. Services own business logic - All validation, queries, and mutations
  3. Schemas separate from models - Pydantic for API, SQLAlchemy for DB
  4. Dependencies for cross-cutting concerns - DB sessions, auth, pagination
  5. Clean folder structure - See project-structure.md reference

Project Structure

app/
├── main.py              # App factory, lifespan
├── config.py            # Settings (pydantic-settings)
├── dependencies.py      # get_db, get_current_user, pagination
├── api/v1/endpoints/    # Route handlers only
├── core/                # Security, exceptions, middleware
├── models/              # SQLAlchemy ORM models
├── schemas/             # Pydantic request/response models
├── services/            # Business logic layer
└── db/                  # Database session, migrations

Adding a New Resource

1. Create Model (app/models/{resource}.py)

from sqlalchemy import Column, String, ForeignKey, Integer
from app.models.base import BaseModel

class Todo(BaseModel):
    title = Column(String(255), nullable=False)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False)

2. Create Schemas (app/schemas/{resource}.py)

from app.schemas.base import CreateSchema, UpdateSchema, ResponseSchema

class TodoCreate(CreateSchema):
    title: str

class TodoUpdate(UpdateSchema):
    title: str | None = None

class TodoResponse(ResponseSchema):
    id: int
    title: str

3. Create Service (app/services/{resource}.py)

from sqlalchemy.orm import Session
from app.models.todo import Todo
from app.core.exceptions import NotFoundError

class TodoService:
    def __init__(self, db: Session):
        self.db = db

    def get_or_404(self, id: int) -> Todo:
        todo = self.db.query(Todo).filter(Todo.id == id).first()
        if not todo:
            raise NotFoundError(f"Todo {id} not found")
        return todo

4. Create Endpoint (app/api/v1/endpoints/{resource}.py)

from fastapi import APIRouter, status
from app.dependencies import DbSession
from app.schemas.todo import TodoCreate, TodoResponse
from app.services.todo import TodoService

router = APIRouter(prefix="/todos", tags=["todos"])

@router.post("", response_model=TodoResponse, status_code=status.HTTP_201_CREATED)
def create_todo(db: DbSession, data: TodoCreate):
    return TodoService(db).create(data)

5. Register Router (app/api/v1/router.py)

from app.api.v1.endpoints import todos
router.include_router(todos.router)

Key Patterns

Type-Annotated Dependencies

from typing import Annotated
from fastapi import Depends

DbSession = Annotated[Session, Depends(get_db)]
CurrentUser = Annotated[User, Depends(get_current_user)]

Response Models

from app.schemas.common import PaginatedResponse
TodoListResponse = PaginatedResponse[TodoResponse]

Exception Flow

Services raise domain exceptions → Exception handlers convert to HTTP responses

# In service
raise NotFoundError("Todo not found")

# Handled automatically → 404 JSON response

References

Kubernetes Readiness

The template includes:

  • Health endpoints (/health, /health/ready)
  • Dockerfile with non-root user
  • docker-compose for local development
  • Environment-based configuration
  • Connection pooling for databases

スコア

総合スコア

40/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です