Skip to main content

Auditing App

The auditing app tracks every change in the Maybern system, providing a complete audit trail for compliance, debugging, and rollback capabilities.

Overview

Auditing operates at two levels:
  1. API Layer - Captures which API endpoint was called
  2. Database Layer - Captures what data changed

API Layer Auditing

The shared API decorators (@api_get, @api_post, etc.) automatically create APIAuditLogEntry records:
@api_post(
    operation_id=OperationIds.CREATE_ENTITY,
    request=CreateEntityRequest,
    response=EntityResponse,
)
def post(self, *, ctx, request_data):
    # APIAuditLogEntry is automatically created
    # The api_audit_log_entry_id is added to ctx
    return MyService.create_entity(ctx=ctx, data=request_data)
GET requests do not generate audit entries since they don’t modify data.

Database Layer Auditing

Changes to models are tracked via custom managers. When a model is saved, updated, or deleted, a ModelAuditLogEntry is created with a diff.

Enabling Auditing

All models inheriting from CustomerTimeStampedModel or TimeStampedModel are audited by default. To disable:
class MyModel(CustomerTimeStampedModel):
    _enable_audit_log = False  # Disable auditing for this model

Diff Examples

{
  "model_changes": {
    "Name": {
      "type": "string",
      "diff_type": "string",
      "before": "",
      "after": "Uncalled",
      "audit_type": "create"
    },
    "Classification": {
      "type": "string",
      "diff_type": "string",
      "before": "",
      "after": "Uncalled",
      "audit_type": "create"
    }
  },
  "action_type": "create",
  "model_name": "TransactionCalculation",
  "model_id": "TRCY_k8dQjgiqwGcEjYZJcfodrq"
}

Internationalization (i18n)

Audit data is stored with i18n keys so it can be displayed in any language:

User-Generated Data

Stored as-is (names, descriptions, comments)

System-Generated Data

Stored as i18n keys:
  • API Operation IDs
  • Model field names
  • Enum values
{
  "field_name": "audit.fields.entity.jurisdiction_country",
  "value": "audit.enums.country.usa"
}
Never delete keys from the i18n files without approval from the auditing team. Deletions can break historical audit record display.

Validation

Tests ensure all auditable fields, operation IDs, and enums have corresponding i18n keys:
# Run auditing validation tests
just test server/apps/auditing/tests/
If a key is missing, the test suggests where to add it in the i18n files.

Models

ModelDescription
APIAuditLogEntryRecords API endpoint calls
ModelAuditLogEntryRecords model changes with diffs

Use Cases

Trace what happened:
  1. Find the API request that caused an issue
  2. See all model changes from that request
  3. Compare before/after states
Answer auditor questions:
  • Who made this change?
  • When was it made?
  • What was the previous value?
Help customers understand changes:
  • Show change history in the UI
  • Explain what happened and when