agentleFS
jbouderjbouder/skills/backend-conventions/SKILL.md

backend-conventions

Skill1 starsChanged 25 days agoMITView on GitHub

OpenTeams backend conventions for Python + FastAPI + async SQLAlchemy + uv projects. Use when writing, modifying, or reviewing backend code — routes, models, schemas, services, config, migrations, or tests — in any project with a pyproject.toml and a src/ or app/ layout. Covers package layout, Pydantic v2 + pydantic-settings, async SQLAlchemy 2, structlog, and the ruff + mypy + pytest quality gate.

  • Installs packages

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before writing code, confirm what the project actually uses — conventions below are the org default, but a given repo may differ.

    line 31
  2. Distinctive:

    Read the relevant reference before doing that kind of work — they hold the canonical patterns:

    line 83

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “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

OpenTeams Backend Development

Conventions and patterns for the OpenTeams Python backend stack. Follow these when building or changing any FastAPI backend in this org. To scaffold a brand-new project, use the new-project skill instead — this skill governs ongoing development.

The Stack

LayerChoice
LanguagePython 3.11+ (support 3.11–3.14)
FrameworkFastAPI + Starlette
ServerUvicorn (+ uvloop off-Windows)
Validation / settingsPydantic v2 + pydantic-settings ([yaml])
DBPostgreSQL + SQLAlchemy 2 (async) + psycopg 3
MigrationsAlembic
Loggingstructlog
ObservabilityOpenTelemetry (api, sdk, otlp exporter, FastAPI + SQLAlchemy instrumentation)
CLITyper
Lint + formatRuff (line-length 120)
Typesmypy (strict)
Testspytest + pytest-asyncio (asyncio_mode = auto)
Package manageruv
Build backendhatchling + uv-dynamic-versioning (for publishable packages)

First Moves In Any Project

Before writing code, confirm what the project actually uses — conventions below are the org default, but a given repo may differ. Check, in order:

  1. pyproject.toml — deps, optional-extras, [dependency-groups], the [tool.ruff]/[tool.mypy]/[tool.pytest] config, build backend.
  2. The package layout — src/ vs app/ (see below). Mirror whichever is present.
  3. AGENTS.md / README.md — repo-specific commands and conventions.
  4. alembic.ini + migrations/ — whether the project uses migrations.
  5. docker-compose.yml — local Postgres (and its ports).
  6. The surrounding code's idioms — match them over these defaults when they conflict.

Two Layouts — Identify Which You're In

The org runs two layouts. Detect, then mirror — never convert one to the other unasked.

app/ — deployable service (scaffolded by new-project --backend). Flat application package, layered by responsibility:

app/
├── main.py            # FastAPI app + router includes
├── config.py          # pydantic-settings Settings
├── database.py        # async engine + sessionmaker
├── deps.py            # FastAPI dependencies (get_db, ...)
├── models/            # SQLAlchemy models (import each in __init__.py)
├── schemas/           # Pydantic request/response models
├── repositories/      # DB queries — ThingRepository
├── services/          # business logic — ThingService
└── routers/           # route handlers (include in main.py)

Per-resource, you add five files: models/thing.py, schemas/thing.py, repositories/thing.py, services/thing.py, routers/thing.py. Routers call services, services call repositories, repositories touch the DB. Keep the layers one-directional.

src/ — publishable package (e.g. ravnar, hrafnar). Uses the org's public/private split:

src/
├── <pkg>/             # PUBLIC API — thin re-exports, py.typed, __main__.py (Typer)
└── _<pkg>/            # PRIVATE impl — config.py, orm.py, core.py, database.py, ...

<pkg>/__init__.py re-exports the supported surface from _<pkg>/; everything in _<pkg>/ is internal and may change. When editing one of these repos, put implementation in _<pkg>/ and only widen <pkg>/ when intentionally exposing API. Version comes from git via uv-dynamic-versioning — never hand-edit a version string.

Non-Negotiables

  • Async all the way down. Async route → async service → async repository → AsyncSession. Never block the event loop with sync DB/HTTP calls.
  • Pydantic v2 only. model_config = ConfigDict(...), model_validate, model_dump. No v1 .dict()/Config class.
  • Config via pydantic-settings, never os.environ[...] scattered through code. One Settings object, env-prefixed, loaded once.
  • Separate ORM models from API schemas. SQLAlchemy models ≠ Pydantic schemas. Map between them explicitly.
  • Structured logging via structlog, not print or bare logging. Bind context, log events as logger.info("event_name", key=value).
  • Full type annotations. mypy runs strict (disallow_untyped_defs, disallow_untyped_calls). No untyped public functions.
  • Migrations for every model change (in app/ services): edit model → uv run alembic revision --autogenerate -m "..." → review the generated SQL → uv run alembic upgrade head. Never hand-write schema drift.
  • Run the quality gate before declaring done (see references/quality.md): uv run ruff format . && uv run ruff check . && uv run mypy <pkg-or-src> && uv run pytest

Reference Files

Read the relevant reference before doing that kind of work — they hold the canonical patterns:

  • references/structure.md — both layouts in detail, the public/private split, adding a resource to an app/ service, config + database + deps patterns, Typer CLI entrypoints.
  • references/quality.md — the exact ruff rule set + mypy strictness + pytest config used across the org, the quality-gate commands, and async test patterns (asyncio_mode=auto, xfail_strict, filterwarnings=error).

What NOT To Do

Don'tDo instead
Convert src/ ↔ app/ layoutDetect which is present and mirror it
Hand-edit a version string in a src/ packageIt's git-derived via uv-dynamic-versioning
Put new logic in the public <pkg>/ packageImplement in _<pkg>/, re-export only when exposing API
os.getenv sprinkled through modulesOne pydantic-settings Settings, injected
Sync DB call inside an async pathawait session.execute(...) on AsyncSession
Return a SQLAlchemy model from a routeMap to a Pydantic response schema
print() / bare loggingstructlog with bound context
Edit a model without a migrationalembic revision --autogenerate then review
pip install / requirements.txtuv add / uv sync; deps live in pyproject
Reach for black/isort/flake8Ruff does format + lint + import sort

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.