ADR 0005: Data access — Drizzle behind repositories, PGlite for tests
Status: Accepted
Date: 2026-07-19
Context
We need SQL visibility, module-owned schemas, RLS, and tests that run without Docker.
Decision
- Drizzle ORM is the default data-access library. Each module owns its schema files under
modules/<id>/src/dband its migrations undermodules/<id>/migrations.
- Repositories hide Drizzle from domain services; ORM entities never cross module boundaries (ports return domain types).
- Every repository method takes
TenantContextand setsapp.tenant_idon the transaction so RLS policies apply.
- Tests use PGlite (in-process Postgres) via
@vercia/testing, so RLS, constraints and JSONB behavior are tested against real Postgres semantics without Docker. Production/dev uses the Postgres fromdocker-compose.ymlor managed Postgres through the same Drizzle dialect contract.
Consequences
pnpm testneeds no services.
- Raw SQL is allowed inside repositories only, reviewed and covered by tests.