# AuditableEntity

## Description

AuditableEntity represents a registration record for an entity that is eligible for audit tracking. Other modules register their entities at initialization time by declaring the entityName, entityScope (COMPANY_BOUND or GLOBAL), and the list of auditableFields eligible for capture. The audit module validates incoming audit events against registered entities — events referencing an unregistered entityType are rejected. Entity scope is immutable once registered and determines whether policies and audit entries for this entity must be company-scoped or global.

Examples: "SalesOrder registered as COMPANY_BOUND with fields [{fieldName: 'amount', fieldType: 'scalar'}, {fieldName: 'status', fieldType: 'scalar'}, {fieldName: 'customerId', fieldType: 'relation'}]", "User registered as GLOBAL with fields [{fieldName: 'email', fieldType: 'scalar'}, {fieldName: 'role', fieldType: 'scalar'}, {fieldName: 'isActive', fieldType: 'scalar'}]".

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [registerAuditableEntity](../commands/RegisterAuditableEntity.md) - Register a new entity for audit tracking

### Query Definitions

None. AuditableEntity registrations are referenced internally by the audit module during policy creation and event ingestion for validation purposes.

### Models

- AuditableEntity

### Invariants

- entityName is required, must be non-empty, and must be unique across all registrations
- entityScope must be one of COMPANY_BOUND or GLOBAL and is immutable once registered
- auditableFields is a JSON-serialized array of field definitions (`{fieldName: string, fieldType?: string}`) eligible for audit capture; must contain at least one entry
- Only the following fieldType values are eligible for inclusion in auditableFields: `scalar`, `richtext`, `array`, `relation`, `file`. Any other fieldType (e.g. `binary`, `computed`) is rejected

### Relationships

- **Referenced By AuditEntry**: AuditEntry.entityType must match a registered AuditableEntity.entityName
- **Referenced By AuditPolicy**: AuditPolicy.entityName must match a registered AuditableEntity.entityName
- **Referenced By emitting modules (reverse dependency)**: Other ERP modules register their auditable entities at initialization time
