# msdkool/auditor architecture

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

- Interactive diagram: https://gitdiagram.com/msdkool/auditor
- Repository: https://github.com/msdkool/auditor

## Overview

SimpleAuditor is a small Entity Framework Core auditing library. A consumer marks DbSet properties with [Audit] and calls SaveChanges; AuditContext finds changes to marked entities, extracts property values and action details, then persists audit records with the entity changes. Consumers can override GetUserName; the default implementation attempts to read the HTTP identity. The console project is a usage sample, not a separate product workflow. Relationships reflect the sampled runtime code and README; no broader integration wiring is assumed.

Main entry points: [`Src/Auditor/Data/AuditContext.cs`](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Data/AuditContext.cs) (AuditContext), [`Src/Auditor/Helper/AuditHelper.cs`](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditHelper.cs) (Change extractor), [`Src/Auditor/Helper/AttributesHelper.cs`](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AttributesHelper.cs) (Attribute scan), [`Src/Auditor/Helper/AuditAttribute.cs`](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditAttribute.cs) (Audit attribute)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Audit runtime"]
  node_context["AuditContext<br/>[AuditContext.cs]"]
  node_attributes["Audit attribute<br/>[AuditAttribute.cs]"]
  node_attribute_scan["Attribute scan"]
  node_extractor["Change extractor<br/>[AuditHelper.cs]"]
  node_type_helper["Type helper<br/>[TypeHelper.cs]"]
end

subgraph group_records["Audit records"]
  node_trail["Audit trail<br/>[AuditTrail.cs]"]
  node_detail["Change detail"]
  node_change_type["Change type<br/>[ChangeType.cs]"]
end

subgraph group_integration["Persistence and identity"]
  node_ef["EF Core"]
  node_database[("Application database")]
  node_http_identity["HTTP identity"]
end

node_consumer(("Consumer app"))

node_consumer -->|"calls SaveChanges"| node_context
node_consumer -->|"marks DbSets"| node_attributes
node_context -->|"finds marked entities"| node_attribute_scan
node_attribute_scan -->|"checks attributes"| node_attributes
node_context -->|"reads tracked changes"| node_ef
node_context -->|"extracts change details"| node_extractor
node_extractor -->|"checks property type"| node_type_helper
node_extractor -->|"sets action"| node_change_type
node_context -->|"creates audit record"| node_trail
node_extractor -->|"fills record"| node_trail
node_extractor -->|"creates property details"| node_detail
node_context -.->|"reads default identity"| node_http_identity
node_context -->|"saves records"| node_ef
node_ef -->|"persists changes"| node_database

click node_context "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Data/AuditContext.cs"
click node_attributes "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditAttribute.cs"
click node_attribute_scan "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AttributesHelper.cs"
click node_extractor "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditHelper.cs"
click node_type_helper "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/TypeHelper.cs"
click node_trail "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Entities/AuditTrail.cs"
click node_detail "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Entities/AuditTrailDetail.cs"
click node_change_type "https://github.com/msdkool/auditor/blob/master/Src/Auditor/Enums/ChangeType.cs"

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_context,node_attributes,node_attribute_scan,node_extractor,node_type_helper toneBlue
class node_trail,node_detail,node_change_type toneAmber
class node_ef,node_database,node_http_identity toneMint
class node_consumer toneIndigo
```

## Components

### Audit runtime

- [AuditContext](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Data/AuditContext.cs): `Src/Auditor/Data/AuditContext.cs`
- [Audit attribute](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditAttribute.cs): `Src/Auditor/Helper/AuditAttribute.cs`
- [Attribute scan](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AttributesHelper.cs): `Src/Auditor/Helper/AttributesHelper.cs`
- [Change extractor](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/AuditHelper.cs): `Src/Auditor/Helper/AuditHelper.cs`
- [Type helper](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Helper/TypeHelper.cs): `Src/Auditor/Helper/TypeHelper.cs`

### Audit records

- [Audit trail](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Entities/AuditTrail.cs): `Src/Auditor/Entities/AuditTrail.cs`
- [Change detail](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Entities/AuditTrailDetail.cs): `Src/Auditor/Entities/AuditTrailDetail.cs`
- [Change type](https://github.com/msdkool/auditor/blob/master/Src/Auditor/Enums/ChangeType.cs): `Src/Auditor/Enums/ChangeType.cs`

### Persistence and identity

- **EF Core**
- **Application database**
- **HTTP identity**

### Other components

- **Consumer app**

## Connections

- Consumer app → AuditContext: calls SaveChanges
- Consumer app → Audit attribute: marks DbSets
- AuditContext → Attribute scan: finds marked entities
- Attribute scan → Audit attribute: checks attributes
- AuditContext → EF Core: reads tracked changes
- AuditContext → Change extractor: extracts change details
- Change extractor → Type helper: checks property type
- Change extractor → Change type: sets action
- AuditContext → Audit trail: creates audit record
- Change extractor → Audit trail: fills record
- Change extractor → Change detail: creates property details
- AuditContext → HTTP identity: reads default identity
- AuditContext → EF Core: saves records
- EF Core → Application database: persists changes
