Audit Logs

Comprehensive audit trail for compliance and debugging. Tracks user actions, data changes, and access patterns across the entire system. Every significant operation is logged with who, what, when, where, and change details.

Source Files

LayerPath
Schemabackend/src/db/schema.ts
Routesbackend/src/routes/auditLogs.ts
Middlewarebackend/src/middleware/auditLogger.ts
Componentsfrontend/src/components/audit-log/ (8 files)
Queriesfrontend/src/lib/queries/activityQueries.ts

Database Tables

TablePurpose
auditLogsSystem-wide audit trail — every significant action with full context
activityLogsLightweight activity feed for UI display (recent actions per entity)

Log Entry Structure

Each audit log entry captures:

FieldPurpose
userIdWho performed the action (user reference)
actionWhat happened (e.g., create, update, delete, login, export)
entityTypeWhich entity type was affected (e.g., building, project, document)
entityIdUUID of the affected entity
timestampWhen the action occurred
detailsJSON payload with change data (before/after values)
requestIdUUID for correlating multiple log entries from a single HTTP request
ipAddressClient IP for security auditing

Middleware Integration

The auditLogger middleware (backend/src/middleware/auditLogger.ts) automatically captures:

  • Request tracking — assigns a UUID to each request for log correlation
  • Mutation logging — records create, update, and delete operations with change diffs
  • Auth events — login, logout, failed attempts, 2FA verification
  • Access patterns — sensitive data access (exports, bulk operations)

The middleware integrates into the Backend Architecture middleware stack and runs after RBAC Authorization checks.

Frontend Components

ComponentPurpose
AuditLogTablePaginated, filterable table of audit entries
AuditLogDetailExpanded view of a single log entry with change diff
AuditLogFiltersFilter by user, action, entity type, date range
ActivityFeedCompact recent-activity timeline shown on entity detail pages
ActivityItemSingle activity entry with icon, description, and timestamp

Query Patterns

  • Entity history — fetch all audit entries for a specific entity (entityType + entityId)
  • User activity — fetch all actions by a specific user
  • Request correlation — trace all side effects of a single request via requestId
  • Date-range queries — compliance reporting for specific time periods

Relationships

AuditLog *──1 Users (actor)
AuditLog ──> any entity (via entityType + entityId)
ActivityLog *──1 Users (actor)
ActivityLog ──> any entity (via entityType + entityId)

Users | RBAC Authorization | Admin Dashboard | Backend Architecture | Service Layer Pattern | Database Architecture