🏗️ Architecture

Audit Logging Architecture

How entity changes are tracked for compliance and traceability.

Overview

The audit logging system records:

  • Who changed what entity
  • What changed (old vs new values)
  • When it changed
  • IP address and request context

Activity Log Flow

Diagram; its source is available below
Diagram source
sequenceDiagram
    User->>API: PUT /api/task/:id
    API->>Guard: TenantPermissionGuard
    API->>Interceptor: ActivityLogInterceptor
    Interceptor->>Service: Get entity before update
    Service->>Database: Update entity
    Interceptor->>ActivityLog: Save change record
    ActivityLog->>Database: INSERT activity_log

ActivityLog Entity

ColumnTypeDescription
idUUIDLog entry ID
entitystringEntity name
entityIdUUIDID of changed entity
actionenumCREATED, UPDATED, DELETED
actorTypeenumUSER, SYSTEM
actorIdUUIDUser who made the change
dataJSONNew values
previousDataJSONOld values
ipAddressstringClient IP
createdAtdatetimeTimestamp

Using the Decorator

@ActivityLog('TASK_UPDATED')
@Put(':id')
async update(@Param('id') id: string, @Body() dto: UpdateTaskDTO) {
  return this.taskService.update(id, dto);
}

Querying Logs

GET /api/activity-log?entity=Task&entityId=uuid&action=UPDATED

Edit this page

Copyright © 2023-Present Ever Co. LTD.Docs by Sourcey