Include Loyalty/Communication/Sports Center backends and registry updates alongside production nginx and compose wiring. Co-authored-by: Cursor <cursoragent@cursor.com>
1.9 KiB
1.9 KiB
Repository Template
Standards for the persistence layer.
Responsibility
Repositories:
- Load/save aggregates and rows
- Apply query filters (including mandatory
tenant_idfor tenant-owned entities) - Encapsulate SQLAlchemy queries
Repositories must not:
- Enforce entitlement or workflow decisions
- Call external HTTP APIs
- Publish events (services own outbox writes)
- Map HTTP status codes
- Contain business branching beyond trivial persistence concerns
Conventions
| Topic | Rule |
|---|---|
| Location | app/repositories/ |
| Naming | {Aggregate}Repository or grouped foundation repos matching service pattern |
| Constructor | Accept DB session (or unit-of-work) explicitly |
| Tenant | Methods that touch tenant data accept/filter tenant_id |
| Soft delete | Default reads exclude soft-deleted unless include_deleted=True |
| Return type | Models / rows; services map to DTOs |
| Transactions | Participate in caller-managed session/transaction; do not silently commit policy that breaks outbox atomicity |
Required Patterns
get_by_id(tenant_id, id) -> Model | None
list(tenant_id, *, filters, pagination) -> Sequence[Model]
add(entity) / save(entity)
# optional: soft_delete(tenant_id, id)
Follow existing service repository base classes when present (repositories/base.py).
Tenant Isolation
- Every query for tenant-owned tables includes
tenant_id. - Updates/deletes must be tenant-scoped (no id-only mutation).
- Repository tests must include cross-tenant denial cases.
Testing
See testing-template.md — Repository section.