# @garuda/event-log — canonical log + projections

The **in-repo model of the lift target** (tag-mgmt `movement_events` + `idempotency_keys`), and the
projections that derive read-models from it. Built to prove the **ratified event envelope (ADR-0014)**
against real writes *before* we touch i-TEK's code.

## Why it exists (get-it-right-first-time)

The event log is the one **one-way door** (append-only, immutable). So we prove the schema here, in our
sandbox, then lift onto it. This package embodies four properties the real log has:

| Property | Here | Real log (tag-mgmt) |
|---|---|---|
| **Append-only** | no `update/delete/upsert` exists | insert-only; mutations hit rebuildable projections |
| **Tenant-partitioned** | stored per `tenant` | RANGE(month) × HASH(tenant_id) |
| **Idempotent** | pre-append side-table (`_idem`) | `idempotency_keys` checked before the insert tx |
| **Projections = fold** | `rebuildStock(log.read(t))` | `tags`/`cartons` rebuildable (their ADR-0023) |

## Files
- `src/event-log.js` — `EventLog`: `append(event)` (idempotent, append-only) · `read(tenant)` · `size(tenant)`.
- `src/projections.js` — `rebuildStock(events)` (deterministic fold; stock is derived, never mutated) · `interleave(streams)` (models concurrent HUs).

## Run
Driven by the engine harness: `cd ../engine && npm run demo`. It asserts (19 checks): the engine emits
full-envelope events, stock is a projection = +50 once, envelope/identity-triple conformance (ADR-0014),
short→no-stock, **replay deduped at the log**, 6-HU shipment → 300, **interleaved HUs → identical projection**
(ADR-0014 D14.4), append-only, and no per-customer literals across all four platform files.
