Entity Forms & Audit System
Entity Forms & Audit System
Relevant source files
The following files were used as context for generating this wiki page:
- src/lib/components/FormPageLayout.svelte
- src/lib/components/entity-list-table/utils/auditable-fields.ts
- src/lib/components/entity-list-table/utils/cell-formatting.ts
- src/lib/components/ui/metadata-loading/MetadataLoading.svelte
- src/lib/composables/useAuditBox.ts
- src/lib/composables/useEntityMetadata.svelte.ts
- src/lib/entity-list/sheets/panels/ColumnsPanel.svelte
- src/lib/entity-list/sheets/panels/SearchInPanel.svelte
- src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte
- src/lib/shell/sheets/SheetHeader.svelte
- src/lib/shell/sheets/SheetHost.svelte
- src/lib/shell/sheets/sheet-manager.svelte.ts
The Entity Form and Audit system provides a standardized architecture for viewing and editing records while maintaining a comprehensive trail of changes. It centers around a unified layout component that integrates record metadata with a reactive audit display and a version history explorer.
System Overview
The system is built on three main pillars:
- Standardized Layout: The
FormPageLayout.sveltecomponent provides a consistent UI for create/edit views, including header actions and the footer-based Audit Box. - Audit Metadata: Managed via
useAuditBoxanduseEntityMetadata, this layer handles the extraction and formatting of system fields likecreated_at,updated_by, andversion. - Change Tracking: The
VersionHistoryPanelprovides a deep-dive timeline into every modification made to a record, utilizing a delta-parsing engine to show field-level changes.
High-Level Component Relationship
The following diagram illustrates how the form components interact with the audit composables and the global sheet system.
Form & Audit Architecture
Code
Sources: src/lib/components/FormPageLayout.svelte:5-7, src/lib/composables/useAuditBox.ts:3-5, src/lib/shell/sheets/sheet-manager.svelte.ts:74-84, src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte:2-5
Form Page Layout & Audit Box
The FormPageLayout.svelte component is the standard wrapper for all entity detail views. It manages the vertical distribution of the form content and houses the Audit Box in its footer.
- Audit Box Logic: Driven by the
useAuditBoxcomposable, it automatically categorizes metadata columns intocreated,updated,deleted, andsyncgroupings src/lib/composables/useAuditBox.ts:19-33. - Version Badge: If a
versionfield exists in the data, a clickable badge is rendered. Clicking this badge triggersopenVersionHistory, which opens the audit timeline in a side sheet src/lib/components/FormPageLayout.svelte:76-88. - Field Formatting: The system uses
getAuditableDisplayValueto handle "by" fields (e.g.,created_by). If a corresponding_namefield exists (e.g.,created_by_name), it is prioritized for display src/lib/entity-list/table/utils/auditable-fields.ts:43-65.
For implementation details on props and metadata validation, see Form Page Layout & Audit Box.
Sources: src/lib/components/FormPageLayout.svelte:38-44, src/lib/composables/useAuditBox.ts:83-85, src/lib/entity-list/table/utils/auditable-fields.ts:29-31
Version History Panel
The VersionHistoryPanel.svelte is a specialized side-sheet component that fetches and renders the audit log for a specific record.
- Data Retrieval: It communicates with the backend via
/api/v1/entities/{entity}/{uuid}/auditwith support for pagination src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte:60-69. - Visual Timeline: Uses a
Timelinecomponent to display changes chronologically. Each entry is color-coded based on the action:CREATE: EmeraldUPDATE: SkyRESTORE: AmberDELETE: Red
- Delta Parsing: The
formatAuditDeltafunction iterates through the changes in an audit entry, translating technical field keys into localized labels and formatting values (badges, dates, or booleans) for human readability src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte:165-200.
For details on the delta parsing pipeline and semantic coloring, see Version History Panel.
Sources: src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte:102-116, src/lib/entity-list/sheets/panels/VersionHistoryPanel.svelte:159-163, src/lib/shell/sheets/sheet-manager.svelte.ts:34-38
Entity Metadata Integration
The system relies on useEntityMetadata to understand which fields are considered "auditable" for a given entity.
| Feature | Code Entity | Description |
|---|---|---|
| Metadata Fetching | useEntityMetadata | Loads the EntityMetadata structure from the backend src/lib/composables/useEntityMetadata.svelte.ts:34-41. |
| Validation | auditingColumns check | Ensures the metadata contains the necessary audit column definitions to prevent UI breakage src/lib/composables/useEntityMetadata.svelte.ts:44-60. |
| Loading State | MetadataLoading.svelte | A specialized spinner component shown while entity metadata is being retrieved src/lib/components/ui/metadata-loading/MetadataLoading.svelte:22-32. |
Data Flow: Metadata to Audit UI
Code
Sources: src/lib/composables/useEntityMetadata.svelte.ts:5-12, src/lib/components/FormPageLayout.svelte:18-20, src/lib/composables/useAuditBox.ts:16-33