# `Logistiki.Audit.AuditEvent`
[🔗](https://github.com/thanos/logistiki/blob/v0.1.0/lib/logistiki/audit/audit_event.ex#L1)

A persisted audit event.

Every important action in the accounting pipeline records an audit event so
that, later, one can answer *why* a posting exists, which business event
caused it, which rules fired, which policy was selected, which template was
used, which accounts were selected, who initiated it, and how the balance was
derived.

## Fields

  * `id` — `integer()` — primary key (e.g. `1`)
  * `actor_id` — `String.t() | nil` — who initiated the action (e.g. `"user_789"`)
  * `event_id` — `String.t() | nil` — the originating business event id (e.g. `"evt_001"`)
  * `journal_id` — `integer() | nil` — the related journal id (e.g. `5`)
  * `action` — `String.t()` — the pipeline stage action (e.g. `"journal_posted"`, `"business_event_received"`)
  * `resource_type` — `String.t() | nil` — the type of resource (e.g. `"journal"`, `"event"`)
  * `resource_id` — `String.t() | nil` — the resource id (e.g. `"1"`)
  * `before` — `map() | nil` — state before the action (for updates)
  * `after` — `map() | nil` — state after the action (for updates)
  * `explanation` — `map() | nil` — structured explanation (e.g. `%{policy: :cash_deposit}`)
  * `metadata` — `map()` — extensible metadata (default `%{}`)
  * `inserted_at` — `DateTime.t() | nil` — set on insert (no `updated_at`; e.g. `~U[2026-07-07 12:00:00Z]`)

## Captured actions

`business_event_received`, `event_normalized`, `facts_generated`,
`business_rules_evaluated`, `no_accounting_impact`, `policy_selected`,
`template_selected`, `journal_built`, `invariant_validation_succeeded`,
`invariant_validation_failed`, `journal_posted`, `journal_reversed`,
`projection_generated`, `audit_event_written`.

## Example

    %Logistiki.Audit.AuditEvent{
      id: 1,
      event_id: "evt_001",
      journal_id: 5,
      action: "journal_posted",
      resource_type: "journal",
      resource_id: "5",
      explanation: %{policy: :cash_deposit, backend: Logistiki.Ledger.Simulation},
      inserted_at: ~U[2026-07-07 12:00:00Z]
    }

# `t`

```elixir
@type t() :: %Logistiki.Audit.AuditEvent{
  __meta__: term(),
  action: String.t() | nil,
  actor_id: String.t() | nil,
  after: map() | nil,
  before: map() | nil,
  event_id: String.t() | nil,
  explanation: map() | nil,
  id: integer() | nil,
  inserted_at: DateTime.t() | nil,
  journal_id: integer() | nil,
  metadata: map() | nil,
  resource_id: String.t() | nil,
  resource_type: String.t() | nil
}
```

The `AuditEvent` struct type — a persisted record of a pipeline stage.

## Fields

  * `id` — `integer() | nil` — primary key
  * `actor_id` — `String.t() | nil` — e.g. `"user_789"`
  * `event_id` — `String.t() | nil` — originating event id (e.g. `"evt_001"`)
  * `journal_id` — `integer() | nil` — related journal id
  * `action` — `String.t() | nil` — e.g. `"journal_posted"`
  * `resource_type` — `String.t() | nil` — e.g. `"journal"`, `"event"`
  * `resource_id` — `String.t() | nil` — e.g. `"5"`
  * `before` — `map() | nil` — state before the action
  * `after` — `map() | nil` — state after the action
  * `explanation` — `map() | nil` — structured explanation
  * `metadata` — `map() | nil` — extensible metadata
  * `inserted_at` — `DateTime.t() | nil` — set on insert (no `updated_at`)

## Example

    %Logistiki.Audit.AuditEvent{
      id: 1, event_id: "evt_001", action: "journal_posted",
      explanation: %{policy: :cash_deposit}
    }

---

*Consult [api-reference.md](api-reference.md) for complete listing*
