Opinionated agent skills for typed Python backend services.
PyStack is a repo-owned skill set for AI coding agents such as Claude Code, Codex, Cursor, OpenCode, and GitHub Copilot. It encodes one practical backend shape for a common modern Python service stack so agents, reviewers, and teams know what kind of code to expect.
If your style differs, install the subset that matches yours and skip the rest.
Why This Exists
Style guides are written for humans. AI coding agents need smaller, triggerable rules that load only when relevant: how repos behave, where transactions live, when Pydantic is allowed, how external clients retry, and what tests should prove.
Generic prompts like "follow DDD" or "use clean architecture" help a little, but they leave too much room for agents to drift. In real codebases that drift shows up as repos committing their own transactions, routes growing business logic, services becoming god classes, Pydantic leaking into persistence, SQLAlchemy tests using mocks, and retries duplicating side effects.
PyStack turns team taste into repo-owned, reviewable guidance. The goal is not to make every prompt longer. The goal is to define the relationships between the pieces once so agents can do better work without every request restating the architecture.
The useful part is that this guidance is yours. Fork it, delete what you disagree with, rewrite the trade-offs, add your own examples, and keep the resulting agent behavior visible in the same place as the code it shapes.
Architecture Stance
PyStack is pragmatic tactical DDD for one Python backend service.
SQLAlchemy models carry aggregate behavior by default.
Pydantic stays at boundaries: API schemas, commands, responses, config, and external payloads.
Repositories load and save aggregates; they do not own transactions.
Top-level application services own write transactions with async with session.begin().
Pure domain classes are opt-in for invariant-dense systems where mapper cost pays back.
Domain services and policies are extraction tools, not a mandatory layer.
External systems are wrapped in clients with explicit retry/error behavior.
Tests use real Postgres for persistence and purpose-built doubles for external systems.
Protocols/interfaces are added when they earn their keep, not for every repo/client by default.
See ARCHITECTURE.md for the locked decisions and trade-offs.
DDD Mapping
Strategic DDD concepts like context maps and upstream/downstream relationships matter when designing multiple services or team boundaries. Inside one service, the useful surface is usually tactical: aggregates, value objects, repositories, application services, invariants, events, transactions, and adapters.