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
- fpindej/netrocktheir own version, first seen Oct 8, 2026
- flntfnd/claude-skillstheir own version, first seen Aug 20, 2026
- ryokkon624/scrum-agent-basetheir own version, first seen Jul 9, 2026
- getsentry/sentrytheir own version, first seen Jun 30, 2026
- sefaertunc/anthropic-watchtheir own version, first seen Apr 30, 2026
- sefaertunc/Worclaudetheir own version, first seen Apr 28, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- getsentry/sentry★ 46ksame name
- fpindej/netrock★ 234same name
- sefaertunc/Worclaude★ 4same name
- sefaertunc/anthropic-watch★ 1same name
- flntfnd/claude-skills★ 0same name
- ryokkon624/scrum-agent-base★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- a11y-auditSkill
- decision-deckSkill
- frontend-conventionsSkill
- github-issueSkill
- k8s-conventionsSkill
- new-nebari-appSkill
- new-projectSkill
- pr-reviewSkill
- start-devSkill
- talk-deckSkill
- tool-evalSkill
- web-app-auditSkill
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
- Distinctive: line 31
Before writing code, confirm what the project actually uses — conventions below are the org default, but a given repo may differ.
- Distinctive: line 83
Read the relevant reference before doing that kind of work — they hold the canonical patterns:
“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.
Files
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
| Layer | Choice |
| Language | Python 3.11+ (support 3.11–3.14) |
| Framework | FastAPI + Starlette |
| Server | Uvicorn (+ uvloop off-Windows) |
| Validation / settings | Pydantic v2 + pydantic-settings ([yaml]) |
| DB | PostgreSQL + SQLAlchemy 2 (async) + psycopg 3 |
| Migrations | Alembic |
| Logging | structlog |
| Observability | OpenTelemetry (api, sdk, otlp exporter, FastAPI + SQLAlchemy instrumentation) |
| CLI | Typer |
| Lint + format | Ruff (line-length 120) |
| Types | mypy (strict) |
| Tests | pytest + pytest-asyncio (asyncio_mode = auto) |
| Package manager | uv |
| Build backend | hatchling + 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:
pyproject.toml— deps, optional-extras,[dependency-groups], the[tool.ruff]/[tool.mypy]/[tool.pytest]config, build backend.- The package layout —
src/vsapp/(see below). Mirror whichever is present. AGENTS.md/README.md— repo-specific commands and conventions.alembic.ini+migrations/— whether the project uses migrations.docker-compose.yml— local Postgres (and its ports).- 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()/Configclass. - Config via pydantic-settings, never
os.environ[...]scattered through code. OneSettingsobject, env-prefixed, loaded once. - Separate ORM models from API schemas. SQLAlchemy models ≠ Pydantic schemas. Map between them explicitly.
- Structured logging via structlog, not
printor barelogging. Bind context, log events aslogger.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 anapp/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't | Do instead |
Convert src/ ↔ app/ layout | Detect which is present and mirror it |
Hand-edit a version string in a src/ package | It's git-derived via uv-dynamic-versioning |
Put new logic in the public <pkg>/ package | Implement in _<pkg>/, re-export only when exposing API |
os.getenv sprinkled through modules | One pydantic-settings Settings, injected |
| Sync DB call inside an async path | await session.execute(...) on AsyncSession |
| Return a SQLAlchemy model from a route | Map to a Pydantic response schema |
print() / bare logging | structlog with bound context |
| Edit a model without a migration | alembic revision --autogenerate then review |
pip install / requirements.txt | uv add / uv sync; deps live in pyproject |
| Reach for black/isort/flake8 | Ruff does format + lint + import sort |
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
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.

