2.5 KiB
2.5 KiB
Backend Domain Rules
This file governs backend/** only. Keep it minimal, enforceable, and non-duplicative.
Scope & Precedence
- Inherits root
AGENTS.mdand workspace runtime rules. - If rules conflict, apply the stricter one.
- Keep backend-only constraints here; do not duplicate root routing logic.
Runtime & Commands
- Python commands must use
uv(uv run,uv add). - Backend startup/shutdown must use
./infra/scripts/app.sh. - Check runtime logs from
./logs/*.log.
Code Quality Baseline
- Do not bypass lint/type gates (
ruff,basedpyright). - Use project logging (
core.logging), neverprint()in runtime code. - HTTP errors must follow RFC 7807 (
application/problem+json).
HTTP Error Contract (Must)
- Backend must construct error payload using RFC7807 fields plus stable extension fields:
codeand optionalparams. codemust be machine-readableUPPER_SNAKE_CASE; do not use free-textdetailas the only contract.- Error code registry source of truth:
docs/protocols/common/http-error-codes.md. - Any create/modify/deprecate of error codes must update
docs/protocols/common/http-error-codes.mdin the same change. - Keep response media type as
application/problem+json. - Long-term layering target: HTTP transport details stay in routers/global handlers; service/repository/dependencies should raise domain errors (
ApiProblemErroror domain-specific exceptions), notHTTPException. - When refactoring existing code, prefer replacing
HTTPExceptionin service/repository/dependencies withApiProblemErrorwhile preserving status/code semantics.
Configuration & Secrets
- Read env only through
core.config.settings(Settings/config). - Do not use
os.getenv/manual env parsing in backend runtime. - Never hardcode keys/tokens/passwords.
Architecture Rules
- Use
schema -> repository -> servicelayering. - Repository: CRUD + query composition only; no auth decisions, no transaction boundary.
- Service: authz + business logic + transaction boundary.
owner_idmust come from verified JWT (sub), never from client payload.
Schema & Contract Rules
- Schema-first for new/changed data contracts.
- Strong typing required at boundaries (Pydantic/dataclass); avoid weak untyped payload contracts.
- Protocol/data contract changes must stay aligned with
docs/protocols/.
Testing
- Follow TDD for feature/bugfix work when practical.
- Prioritize regression tests for changed logic/contracts.
- Real DB tests must use
settings.test.*; never hardcode test credentials.