agentleFS
vndeevndee/engineering-skills/.claude/skills/py-scaffold/SKILL.md

py-scaffold

Skill3 starsChanged 9 months agoMITView on GitHub

Use when starting a new Python/FastAPI backend, API, or microservice with SQLAlchemy, Alembic, and clean architecture

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Core principle: Start fully typed. mypy strict from the first file.

    line 12
  2. Very specific:

    REQUIRED: Update CLAUDE.md with stack, commands, directories, and conventions (claude-md)

    line 202
  3. Very specific:

    Use docker-build for production Dockerfile

    line 204
  4. Very specific:

    Use ci-pipeline for GitHub Actions

    line 205

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Project Scaffold

Overview

Bootstrap a new FastAPI backend with clean architecture, SQLAlchemy 2.0 async, Alembic, uv, and strict typing from day one.

Core principle: Start fully typed. mypy strict from the first file. No Any unless justified.

Directory Structure

project/
  src/
    domain/                  # Entities, value objects, repository protocols
    application/             # Use cases, DTOs, service protocols
    infrastructure/
      postgres/              # SQLAlchemy models, repository implementations
      redis/                 # Cache implementations
      config.py              # Settings with pydantic-settings
    interfaces/
      http/                  # FastAPI routers, dependencies, middleware
        dependencies.py
        routes.py
    main.py                  # App factory with lifespan
  alembic/
    versions/
    env.py
  tests/
    unit/
    integration/
    conftest.py
  alembic.ini
  pyproject.toml
  Makefile
  Dockerfile
  docker-compose.yml
  CLAUDE.md

Bootstrap Files

main.py (App Factory)

from contextlib import asynccontextmanager
from collections.abc import AsyncGenerator
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker

@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
    # Startup
    engine = create_async_engine(settings.database_url)
    app.state.session_factory = async_sessionmaker(engine, expire_on_commit=False)
    yield
    # Shutdown
    await engine.dispose()

def create_app() -> FastAPI:
    app = FastAPI(lifespan=lifespan)
    app.include_router(api_router, prefix="/api/v1")
    return app

pyproject.toml

[project]
name = "project-name"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
    "fastapi>=0.115",
    "uvicorn[standard]>=0.34",
    "sqlalchemy[asyncio]>=2.0",
    "asyncpg>=0.30",
    "alembic>=1.14",
    "pydantic-settings>=2.0",
]

[project.optional-dependencies]
dev = [
    "pytest>=8.0",
    "pytest-asyncio>=0.24",
    "httpx>=0.28",
    "testcontainers[postgres]>=4.0",
    "mypy>=1.13",
    "ruff>=0.8",
]

[tool.mypy]
strict = true
plugins = ["pydantic.mypy"]

[tool.ruff]
target-version = "py312"
line-length = 100

[tool.ruff.lint]
select = ["E", "F", "I", "N", "UP", "B", "SIM", "TCH", "RUF"]

[tool.pytest.ini_options]
asyncio_mode = "auto"
markers = ["integration: requires external services"]

Makefile

.PHONY: run test lint type-check migrate migrate-create

run:
	uvicorn src.main:create_app --factory --reload --port 8000

test:
	pytest tests/ -m "not integration"

test-integration:
	pytest tests/ -m integration

test-all:
	pytest tests/

lint:
	ruff check . && ruff format --check .

type-check:
	mypy src/

migrate:
	alembic upgrade head

migrate-create:
	alembic revision --autogenerate -m "$(msg)"

docker-compose.yml

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
    ports: ["5432:5432"]
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck:
      test: pg_isready -U app
      interval: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    ports: ["6379:6379"]

volumes:
  pgdata:

Initial Health Check (TDD)

REQUIRED: Invoke superpowers:test-driven-development to write /health endpoint.

# Test first
async def test_health(client: AsyncClient) -> None:
    resp = await client.get("/health")
    assert resp.status_code == 200
    assert resp.json() == {"status": "ok"}

CLAUDE.md Template

# Project Name

## Stack
- Python 3.12+ / FastAPI
- SQLAlchemy 2.0 async + Alembic
- PostgreSQL + Redis
- uv for dependency management

## Commands
- `make run` — start with hot reload
- `make test` — unit tests
- `make test-integration` — integration tests
- `make lint` — ruff check + format
- `make type-check` — mypy strict
- `make migrate` — apply migrations
- `make migrate-create msg="description"` — new migration

## Architecture
Clean architecture: domain → application → infrastructure → interfaces
All code fully typed. mypy strict. No untyped defs.

Chains

  • REQUIRED: Update CLAUDE.md with stack, commands, directories, and conventions (claude-md)
  • Pairs with react-scaffold for full-stack
  • Use docker-build for production Dockerfile
  • Use ci-pipeline for GitHub Actions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.