Source controller:
apps/erp-backend/src/audit/audit.controller.tsList audit trail
GET /api/entities/:entityId/audit-trail
Returns a paginated page of audit envelopes for the entity, plus the named resources needed to render them without extra lookups.
Query params (from listAuditTrailQuerySchema)
Response:
auditTrailPageSchema (paginated: { envelopes, namedResources, nextCursor })
What the trail captures
Per ADR 0028, the audit trail is row-level and automatic via Postgres triggers. Every mutating request produces one Audit Envelope grouping its Audit Changes:- Actor:
actorUserIdplus name and role of the authenticated user - Credential type:
sessionfor browser sessions,api_keyfor API key requests - Declared actor: the value of the
x-audit-actorheader on API-key mutations (stored as a claim, not a verified identity) - Request id: a server-generated unique id grouping all changes in one request
- Route and HTTP method: the endpoint that triggered the mutation
- Entity id: the entity scope the change occurred within
- Diff: for inserts and deletes, the full row image; for updates, only the columns that moved with before and after values