MATIH Platform is in active MVP development. Documentation reflects current implementation status.
8. Platform Services
Audit Events

Audit Events

Audit events are the core data model of the Audit Service. Every action performed on the platform -- user logins, data access, configuration changes, administrative operations -- is captured as an audit event with full context including actor, resource, state changes, and request metadata.


AuditEvent Entity

FieldTypeDescription
idUUIDAuto-generated event ID
tenantIdUUIDTenant that owns the event
eventTypeEventTypeCategorized event type (e.g., LOGIN, CREATE, DATA_ACCESS)
actionStringSpecific action performed (e.g., user.login, dashboard.create)
actorIdUUIDWho performed the action
actorTypeActorTypeUSER, SERVICE, SYSTEM, ANONYMOUS, or API_KEY
actorEmailStringHuman-readable actor identity
resourceTypeStringType of resource affected (e.g., dashboard, query)
resourceIdStringIdentifier of the affected resource
resourceNameStringHuman-readable resource name
previousStateJSONResource state before the change
newStateJSONResource state after the change
ipAddressStringClient IP address
userAgentStringClient user agent string
correlationIdStringRequest trace correlation ID
requestIdStringUnique request identifier
requestMethodStringHTTP method (GET, POST, etc.)
requestPathStringHTTP request path
responseStatusIntegerHTTP response status code
durationMsLongRequest duration in milliseconds
severitySeverityDEBUG, INFO, WARNING, ERROR, or CRITICAL
successBooleanWhether the operation succeeded
errorMessageStringError details if the operation failed
metadataJSONAdditional context as key-value pairs
createdAtInstantTimestamp when the event was created

Create an Audit Event (Synchronous)

Endpoint: POST /api/v1/audit/events

curl -X POST http://localhost:8086/api/v1/audit/events \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "tenantId": "550e8400-e29b-41d4-a716-446655440000",
    "eventType": "CREATE",
    "action": "dashboard.create",
    "actorId": "660e8400-e29b-41d4-a716-446655440000",
    "actorType": "USER",
    "actorEmail": "admin@acme.com",
    "resourceType": "dashboard",
    "resourceId": "dash-001",
    "resourceName": "Sales Overview",
    "severity": "INFO",
    "success": true,
    "metadata": {
      "source": "bi-workbench",
      "dashboardType": "analytical"
    }
  }'

Returns 201 Created with the full event response.


Create an Audit Event (Asynchronous)

Endpoint: POST /api/v1/audit/events/async

Queues the event via Kafka for asynchronous processing. Returns 202 Accepted immediately.

curl -X POST http://localhost:8086/api/v1/audit/events/async \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "tenantId": "550e8400-e29b-41d4-a716-446655440000",
    "eventType": "DATA_ACCESS",
    "action": "query.execute",
    "actorId": "660e8400-e29b-41d4-a716-446655440000",
    "actorType": "USER",
    "resourceType": "query",
    "resourceId": "q-12345"
  }'

Query Events

Get Event by ID

Endpoint: GET /api/v1/audit/events/:eventId

List Tenant Events (Paginated)

Endpoint: GET /api/v1/audit/tenants/:tenantId/events

ParameterTypeDefaultDescription
pageint0Page number (0-based)
sizeint50Page size

List Events by Time Range

Endpoint: GET /api/v1/audit/tenants/:tenantId/events/time-range

ParameterTypeDescription
startTimeInstantStart time (ISO-8601)
endTimeInstantEnd time (ISO-8601)

List Events by Actor

Endpoint: GET /api/v1/audit/tenants/:tenantId/actors/:actorId/events

List Events by Resource

Endpoint: GET /api/v1/audit/tenants/:tenantId/resources/:resourceType/:resourceId/events

Get Events by Correlation ID

Endpoint: GET /api/v1/audit/correlation/:correlationId

Returns all events that share a correlation ID, useful for tracing a request across services.

List Failed Events

Endpoint: GET /api/v1/audit/tenants/:tenantId/events/failed


Database Indexes

The audit_events table includes the following indexes for query performance:

IndexColumnsPurpose
idx_audit_tenant_createdtenant_id, created_at DESCTenant event listing sorted by time
idx_audit_actoractor_idActor-based queries
idx_audit_resourceresource_type, resource_idResource-based queries
idx_audit_correlationcorrelation_idRequest trace correlation