Remote / foldkit-remote-domain
How a write flows from page to View and back
Each step of a write has one owner:
| Responsibility | Owner |
|---|---|
| Command decisions and recorded Events | Domain model (decide, evolve) |
| Row visibility and read authorization | Domain View (validate, middleware) |
| Cached rows, optimistic values, pending state, refusals | Remote.Model |
| Read-after receipt tokens and row revisions | Remote.Model |
| In-memory reply cache (last 1,024 replies to skip duplicate retries) | Adapter (rebuilt on reload) |
Tracing one write end to end:
- Page (
Remote):Data.mutate(model, RenameNote, input)applies the optimistic prediction and marks the write pending. - Adapter: derives a deterministic
commandIdand callsclient.Rename(target, input, { commandId }). - Aggregate:
decideappends Events and returns a receipt ({ stream, version }). - Adapter: queries
NoteRow.snapshot(target, { atLeast })at that receipt. - View: folds delivered Events and enforces read rules.
- Adapter: emits
MutationSucceededwith the updated row—or, if the View is still behind, the fields fromwritten(reply, input)plus the receipt as a read-after token. - 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.