Skip to content

feat(audit): comprehensive audit logging & compliance reporting - #36

Merged
akargi merged 1 commit into
Chulilee:mainfrom
walexjnr:feat/25-audit-logging-compliance
Aug 19, 2026
Merged

feat(audit): comprehensive audit logging & compliance reporting#36
akargi merged 1 commit into
Chulilee:mainfrom
walexjnr:feat/25-audit-logging-compliance

Conversation

@walexjnr

Copy link
Copy Markdown
Contributor

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

  • AuditLog entity — 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, and beforeState/afterState snapshots for data-change events.
  • Global interceptor (AuditInterceptor, registered via APP_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.
  • Compliance reportsPOST /audit/reports generates 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.
  • Admin-only read APIGET /audit/logs, GET /audit/logs/:id, GET /audit/dashboard/activities (last 100), GET /audit/export/:userId, guarded by JwtAuthGuard + RolesGuard + @Roles(ADMIN). There is intentionally no create/update/delete endpoint.
  • Docsdocs/audit-logging.md covers capture, immutability (incl. DB-level REVOKE), retention, the API, reports, and GDPR.

Acceptance criteria

  • Append-only audit log entity
  • Global interceptor captures all API requests/responses
  • GET /audit/logs returns paginated, filtered records
  • Records include timestamp, user, action, resource, before/after state
  • Search by user, action type, date range, resource type
  • POST /audit/reports generates compliance reports (PDF/CSV, plus JSON)
  • Immutability: no update/delete path (entity + service + API), DB hardening documented
  • Retention: 7-year minimum (AUDIT_RETENTION_YEARS) with cold-storage archival lookup
  • Unit tests for audit capture logic (module coverage ~94%, >80%)
  • Real-time dashboard endpoint returns the last 100 activities
  • Low overhead: audit write is off the request critical path (fire-and-forget)

Verification

Ran the repository's CI steps locally: npx tsc --noEmit and npm run build both pass, eslint is 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.

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%).
@akargi
akargi merged commit b2826c6 into Chulilee:main Aug 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Comprehensive Audit Logging & Compliance Reporting

2 participants