ADR 0009 — Relationship with drizzle-audit: Capture Layer vs Control Plane
Status: Accepted
Context
Section titled “Context”drizzle-audit (0.1.13, same author) captures row-level database changes made through Drizzle
(insert/update/delete diffs, trackAction for custom actions), with an AsyncLocalStorage context,
transforms (redact/mask/hash/omit), sampling, framework middleware, and sinks (drizzleTableStorage,
httpStorage, consoleStorage, multiStorage, callbackStorage) behind a one-method
AuditStorage { write(entries) } interface.
@xtandard/audit is a different layer: the customer-facing, tenant-scoped, tamper-evident log of
business actions — storage drivers, query, viewer, export, verification, streaming.
Decision
Section titled “Decision”- They stay separate packages with no dependency in either direction.
drizzle-auditis a capture layer (what changed in which row);@xtandard/auditis a control plane (who did what to which resource in which tenant, provably). @xtandard/audit/drizzle-auditships a bridge:createDrizzleAuditStorage(core, { tenant, action, actor, include })returns an object that structurally satisfies drizzle-audit’sAuditStorage, mapping eachAuditEntryto an audit event (action=db.<table>.<op>or the custom action,targets=[{ type: table, id: rowId }],actor.id=userId,metadata={ changes, oldData, newData }). Typed structurally, so drizzle-audit is not a peer.- Reused ideas (re-implemented, not imported): transform helpers (
redact,mask,hash,omit), the AsyncLocalStorage context pattern (ADR 0013), the batching HTTP sink design. - Migration path: existing
drizzle-audittables can be imported withimportDrizzleAuditEntries(core, rows, mapping)(chained inoccurredAtorder). - Proposed (not applied — the repo is not ours to modify here) improvements for drizzle-audit are
sent to the coordinator: a first-class
tenantIdin the context, and a documented “send to @xtandard/audit” recipe in its README.
Consequences
Section titled “Consequences”- Teams can capture DB-level diffs with drizzle-audit and still give customers a verified, browsable log, without either library growing into the other.