Audit Service

Structured audit logging with event taxonomy, log retention policies, and query API

Audit Service (Port 8013)

The audit-service provides structured audit logging for compliance, security monitoring, and data access tracking.

Database

Database: audit_db

TablePurpose
audit_logsCore audit event log
data_access_logsData access records
consent_recordsConsent tracking for GDPR/regulatory compliance

API Endpoints

MethodPathPurpose
GET/logsQuery audit logs
GET/logs/exportExport logs
GET/complianceCompliance reports

Audit Event Schema

Each audit event contains:

{
  "event_id": "uuid",
  "event_type": "response.approved",
  "actor_id": "user-uuid",
  "tenant_id": "tenant-uuid",
  "resource_type": "response",
  "resource_id": "response-uuid",
  "action": "approve",
  "timestamp": "2026-05-13T10:30:00Z",
  "metadata": {
    "previous_status": "pending",
    "new_status": "approved",
    "ip_address": "192.168.1.1",
    "user_agent": "Mozilla/5.0..."
  }
}

Event Taxonomy

CategoryEvent Types
Authenticationuser.login, user.logout, user.login_failed
User Managementuser.created, user.updated, user.deleted
Surveysurvey.created, survey.published, survey.deleted
Responseresponse.submitted, response.approved, response.rejected
Tenanttenant.created, tenant.suspended, tenant.dormant
Billingsubscription.created, subscription.cancelled

Logging from Other Services

Services send audit events via HTTP:

async def log_audit_event(event_type, actor_id, resource_type, resource_id, metadata=None):
    async with httpx.AsyncClient() as client:
        await client.post(
            f"{AUDIT_SERVICE_URL}/logs",
            json={
                "event_type": event_type,
                "actor_id": actor_id,
                "tenant_id": request.state.tenant_id,
                "resource_type": resource_type,
                "resource_id": resource_id,
                "metadata": metadata or {}
            },
            headers={"X-Service-API-Key": SERVICE_API_KEY}
        )

Retention

Log retention policies are configurable per tenant:

RETENTION_POLICIES = {
    "audit_logs": timedelta(days=365),       # 1 year
    "data_access_logs": timedelta(days=90),  # 90 days
}

Integrity

Audit logs are append-only. Deletion is not permitted — only archival after the retention period.