feat(audit): comprehensive audit logging & compliance reporting - #36
Merged
Merged
Conversation
Adds an append-only audit module that captures system activity for compliance, security investigation and regulatory reporting. - AuditLog entity: append-only (no updatedAt), indexed for search by user, action, resource and date; captures actor, resource, before/ after state, status, duration and correlation id. - AuditInterceptor registered globally (APP_INTERCEPTOR) records every HTTP request on success and failure. Persistence is fire-and-forget so auditing stays off the request critical path and adds negligible latency; failures are logged, never thrown. - AuditService: append-only writes, paginated/filterable search, recent- activity feed for the security dashboard, GDPR per-user export, 7-year retention with archival candidate lookup, and compliance report generation (transactions, user activity, admin actions, security). - Compliance reports render to CSV (RFC 4180), JSON, or PDF via a self-contained writer, downloaded from POST /audit/reports. Read endpoints are admin-only. - Documentation in docs/audit-logging.md and unit tests covering the capture logic, search, report generation and writers (module coverage ~94%).
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25
Summary
Adds a comprehensive, immutable append-only audit logging module (
src/modules/audit) that captures all system activity for compliance, security investigation and regulatory reporting.What's included
AuditLogentity — append-only (deliberately no@UpdateDateColumn), indexed for search by user, action, resource type and date. Captures timestamp, actor + role, action, outcome, resource type/id, HTTP method/path/status, duration, IP/user-agent, correlation id, andbeforeState/afterStatesnapshots for data-change events.AuditInterceptor, registered viaAPP_INTERCEPTOR) — records every HTTP request/response on both success and failure, deriving category (user/admin/system/data-change/security), resource, and outcome. Persistence is fire-and-forget so audit capture stays off the request's critical path and adds negligible latency; a persistence failure is logged, never thrown.AuditService— append-only writes, paginated/filterable search (user, action, category, outcome, resource, date range), a recent-activity feed for the security dashboard, GDPR per-user export, a 7-year retention constant with archival-candidate lookup, and compliance report generation.POST /audit/reportsgenerates transaction / user-activity / admin-action / security reports and streams them as a download in CSV (RFC 4180), PDF, or JSON. The PDF is produced by a small self-contained writer, so no new runtime dependency is added.GET /audit/logs,GET /audit/logs/:id,GET /audit/dashboard/activities(last 100),GET /audit/export/:userId, guarded byJwtAuthGuard+RolesGuard+@Roles(ADMIN). There is intentionally no create/update/delete endpoint.docs/audit-logging.mdcovers capture, immutability (incl. DB-levelREVOKE), retention, the API, reports, and GDPR.Acceptance criteria
GET /audit/logsreturns paginated, filtered recordsPOST /audit/reportsgenerates compliance reports (PDF/CSV, plus JSON)AUDIT_RETENTION_YEARS) with cold-storage archival lookupVerification
Ran the repository's CI steps locally:
npx tsc --noEmitandnpm run buildboth pass,eslintis clean on the new files, and the audit unit suite passes (26 tests). GDPR data-export and deletion-tracking are covered as noted in the docs.