# ADR-0004: Use EventStore, Domain Tables, And ProjectionStore

- Status: Accepted
- Date: 2026-05-27

## Context

AirCoding needs live TUI/HUD updates, crash recovery, scheduling queries, tool/run evidence, and resumable session state. Raw message storage alone is insufficient for scheduling and recovery.

## Decision

Use an event-driven runtime with:

```text
EventBus        # live ephemeral/durable event publication
EventStore      # durable event validation and transactional persistence
Domain tables   # scheduling/recovery/query source of truth
ProjectionStore # derived TUI/HUD view model
```

Canonical messages are stored as Anthropic content JSON. Domain tables store tasks, agents, tool runs, command runs, artifacts, diagnostics, evidence, workspaces, summaries, and UI state.

## Consequences

- Scheduler and recovery query domain tables instead of parsing message history.
- TUI/HUD consumes ProjectionStore, not DB/EventBus directly.
- Durable event insert and corresponding domain table update happen in one SQLite transaction.
- Event payloads and persistence policy are governed by `event-registry-v1.md`.
