Remote / foldkit-remote-domain

How a write flows from page to View and back

Each step of a write has one owner:

ResponsibilityOwner
Command decisions and recorded EventsDomain model (decide, evolve)
Row visibility and read authorizationDomain View (validate, middleware)
Cached rows, optimistic values, pending state, refusalsRemote.Model
Read-after receipt tokens and row revisionsRemote.Model
In-memory reply cache (last 1,024 replies to skip duplicate retries)Adapter (rebuilt on reload)

Tracing one write end to end:

  1. Page (Remote): Data.mutate(model, RenameNote, input) applies the optimistic prediction and marks the write pending.
  2. Adapter: derives a deterministic commandId and calls client.Rename(target, input, { commandId }).
  3. Aggregate: decide appends Events and returns a receipt ({ stream, version }).
  4. Adapter: queries NoteRow.snapshot(target, { atLeast }) at that receipt.
  5. View: folds delivered Events and enforces read rules.
  6. Adapter: emits MutationSucceeded with the updated row—or, if the View is still behind, the fields from written(reply, input) plus the receipt as a read-after token.
  7. Page (Remote): replaces the optimistic layer with the authoritative answer, recording the row's revision and any active read-after floor (stream@version).

Remote accepts an incoming row only when its revision is at least the revision already held. While a floor is active, subsequent reads pass { atLeast: floor(key) } until the View catches up.