Skip to content

BE-022 — Implement Audit Logging & Compliance API - #321

Open
Sendi0011 wants to merge 1 commit into
DigiNodes:mainfrom
Sendi0011:feat/be-022-audit-logging-compliance-api
Open

BE-022 — Implement Audit Logging & Compliance API#321
Sendi0011 wants to merge 1 commit into
DigiNodes:mainfrom
Sendi0011:feat/be-022-audit-logging-compliance-api

Conversation

@Sendi0011

Copy link
Copy Markdown

Summary

Implements the Audit Logging & Compliance API (BE-022) — an immutable, searchable, and secure audit trail for every significant action across the TruthBounty platform.

Changes

Entity & Schema

  • Expanded AuditLog entity with 50+ action types, event categories, severity levels, actor role tracking, integrity hashing, and retention controls
  • Added UserRole enum (USER/MODERATOR/ADMIN/SUPER_ADMIN) and role field to User entity (both TypeORM and Prisma)

RBAC

  • Created Roles decorator and RolesGuard for declarative authorization

Services

  • AuditSearchService — 15+ filter dimensions, pagination, failed access & security event queries
  • AuditComplianceService — 8 report types with JSON and CSV export
  • AuditMetricsService — events, storage, latency, integrity health tracking
  • AuditRetentionService — per-event-type retention overrides, legal hold, cron purge
  • AuditTrailService — enhanced with SHA-256 integrity hashing, actor/event/resource capture

API Endpoints (17 total)

Method Path Description
GET /audit Advanced search
GET /audit/entity/:type/:id Entity logs
GET /audit/user/:id User logs
GET /audit/action/:type Action logs
GET /audit/changes/:type/:id Change history
GET /audit/summary Summary stats
GET /audit/correlation/:id Correlation ID
GET /audit/request/:id Request ID
GET /audit/failed-access Failed attempts
GET /audit/security-events Security events
GET /audit/integrity/:id Verify integrity
POST /audit/reports Generate report
GET /audit/reports/types Report types
GET /audit/metrics System metrics
GET /audit/retention Retention status
POST /audit/legal-hold/:entityId Place legal hold
PATCH /audit/legal-hold/:entityId/remove Remove hold

Security

  • RBAC on sensitive endpoints, immutable records (no update/delete), SHA-256 integrity hashing, GDPR-compliant IP masking

Closes

Closes #284

- Expanded AuditLog entity with 50+ action types, event categories, severity levels, actor role tracking, integrity hashing, and retention controls
- Added UserRole enum and role field to User entity for RBAC
- Created RolesGuard and Roles decorator for declarative authorization
- Created AuditSearchService with 15+ filter dimensions, pagination, and specialized queries (failed access, security events)
- Created AuditComplianceService with 8 report types and CSV/JSON export
- Created AuditMetricsService exposing event counts, storage utilization, search latency, integrity health
- Enhanced AuditRetentionService with configurable per-event-type retention overrides and legal hold support
- Added SHA-256 integrity hashing with verifyAuditIntegrity for tamper detection
- Created DTOs for search, compliance reports, and retention policies
- Expanded REST API with 15+ endpoints: advanced search, reports, metrics, retention, legal hold, integrity verification
- Updated JWT auth to include user role in tokens
- Added Swagger documentation tags
@dDevAhmed

Copy link
Copy Markdown
Contributor

resolve conflicts @Sendi0011

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.

BE-022 — Implement Audit Logging & Compliance API

2 participants