# atk4/audit architecture

> Architecture diagram of the GitHub repository atk4/audit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atk4/audit
- Repository: https://github.com/atk4/audit

## Overview

Agile Data Audit is a PHP extension that records model creates, updates, deletes, and reactive hook-driven changes. The principal flow is model persistence hooks into the audit controller, which applies model/field policies, computes requested and reactive diffs, and saves audit records; a stack tracks in-progress records. For inspection, the audit grid opens a detail view that presents diffs and causal links. The excerpts establish these core links; the README also identifies policy and UI capabilities, while application setup and the underlying Agile Data persistence wiring are not fully shown.

Main entry points: [`src/AuditController.php`](https://github.com/atk4/audit/blob/develop/src/AuditController.php) (Audit controller), [`src/Model/AuditLog.php`](https://github.com/atk4/audit/blob/develop/src/Model/AuditLog.php) (Audit log model), [`src/View/AuditDetail.php`](https://github.com/atk4/audit/blob/develop/src/View/AuditDetail.php) (Audit detail), [`src/View/AuditGrid.php`](https://github.com/atk4/audit/blob/develop/src/View/AuditGrid.php) (Audit grid)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Change capture"]
  node_controller["Audit controller"]
  node_policy["Audit policies<br/>[AuditPolicy.php]"]
  node_stack["Record stack<br/>[Stack.php]"]
end

subgraph group_records["Audit records"]
  node_auditlog[("Audit log model<br/>[AuditLog.php]")]
end

subgraph group_inspection["Audit UI"]
  node_grid["Audit grid<br/>[AuditGrid.php]"]
  node_detail["Audit detail<br/>[AuditDetail.php]"]
  node_action["Action column<br/>[Action.php]"]
end

node_caller(("Application user"))
node_models["Agile Data models"]
node_store[("Persistence store")]

node_caller -.->|"changes data"| node_models
node_models -->|"triggers hooks"| node_controller
node_controller -->|"checks policy"| node_policy
node_controller -->|"tracks records"| node_stack
node_controller -->|"creates and saves"| node_auditlog
node_auditlog -.->|"persists records"| node_store
node_grid -->|"opens details"| node_detail
node_detail -->|"reads audit data"| node_auditlog
node_auditlog -->|"configures column"| node_action
node_detail -->|"uses action constants"| node_controller

click node_controller "https://github.com/atk4/audit/blob/develop/src/AuditController.php"
click node_policy "https://github.com/atk4/audit/blob/develop/src/AuditPolicy.php"
click node_stack "https://github.com/atk4/audit/blob/develop/src/Stack.php"
click node_auditlog "https://github.com/atk4/audit/blob/develop/src/Model/AuditLog.php"
click node_grid "https://github.com/atk4/audit/blob/develop/src/View/AuditGrid.php"
click node_detail "https://github.com/atk4/audit/blob/develop/src/View/AuditDetail.php"
click node_action "https://github.com/atk4/audit/blob/develop/src/View/Table/Column/Action.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_controller,node_policy,node_stack,node_caller toneBlue
class node_auditlog,node_store toneAmber
class node_grid,node_detail,node_action toneMint
class node_models toneIndigo
```

## Components

### Change capture

- [Audit controller](https://github.com/atk4/audit/blob/develop/src/AuditController.php): `src/AuditController.php`
- [Audit policies](https://github.com/atk4/audit/blob/develop/src/AuditPolicy.php): `src/AuditPolicy.php`
- [Record stack](https://github.com/atk4/audit/blob/develop/src/Stack.php): `src/Stack.php`

### Audit records

- [Audit log model](https://github.com/atk4/audit/blob/develop/src/Model/AuditLog.php): `src/Model/AuditLog.php`

### Audit UI

- [Audit grid](https://github.com/atk4/audit/blob/develop/src/View/AuditGrid.php): `src/View/AuditGrid.php`
- [Audit detail](https://github.com/atk4/audit/blob/develop/src/View/AuditDetail.php): `src/View/AuditDetail.php`
- [Action column](https://github.com/atk4/audit/blob/develop/src/View/Table/Column/Action.php): `src/View/Table/Column/Action.php`

### Other components

- **Application user**
- **Agile Data models**
- **Persistence store**

## Connections

- Application user → Agile Data models: changes data (evidence: `README.md`)
- Agile Data models → Audit controller: triggers hooks (evidence: `src/AuditController.php`)
- Audit controller → Audit policies: checks policy (evidence: `src/AuditController.php`)
- Audit controller → Record stack: tracks records (evidence: `src/AuditController.php`)
- Audit controller → Audit log model: creates and saves (evidence: `src/AuditController.php`)
- Audit log model → Persistence store: persists records
- Audit grid → Audit detail: opens details (evidence: `src/View/AuditGrid.php`)
- Audit detail → Audit log model: reads audit data (evidence: `src/View/AuditDetail.php`)
- Audit log model → Action column: configures column (evidence: `src/Model/AuditLog.php`)
- Audit detail → Audit controller: uses action constants (evidence: `src/View/AuditDetail.php`)
