Skip to content

docs: Closing the Books pattern guide + runnable contrast (#139)#199

Merged
joeldsouzax merged 8 commits into
mainfrom
docs/closing-the-books-139
Jun 18, 2026
Merged

docs: Closing the Books pattern guide + runnable contrast (#139)#199
joeldsouzax merged 8 commits into
mainfrom
docs/closing-the-books-139

Conversation

@joeldsouzax

Copy link
Copy Markdown
Contributor

Summary

Closes #139 — the final card in the Tier 1: Table Stakes milestone. Documents the "Closing the Books" event-sourcing pattern as the preferred alternative to aggregate snapshots, with an executable contrast to back the prose.

  • Kernel guide module (crates/nexus/src/closing_the_books.rs) — a doc-only //! module shipped on docs.rs next to aggregate/events. Explains the pattern (bounded streams + a first-class summary event carrying minimum state forward), contrasts it with snapshots grounded in nexus's real behaviour (schema_version is a cache key, not a migration engine — no upcasting path for snapshot bytes), and gives honest "when NOT to use it" caveats.
  • Runnable example (examples/closing-the-books/) — builds the same cash-register domain two ways and prints the contrast:
    • long-lived CashRegister: one stream, replays all 5001 events to read the current float;
    • bounded CashierShift streams: the current shift replays only 11 events, with final_float (110) carried forward into a brand-new shift stream.
    • Both aggregates reuse the same generic record / replay_stream helpers; 4 AggregateFixture tests cover the CloseShift overage/shortage/guard logic.
  • Discoverability — a clickable intra-doc pointer from nexus-store's Snapshotting decorator down to nexus::closing_the_books (the kernel can't link up to the store), and the older 2026-04-10-snapshot-design.md now points at the shipped guide instead of the bare issue number.

Design intent: nexus ships no "close stream"/"archive"/"delete" API — Closing the Books is a modeling discipline (a new stream is just AggregateRoot::new(new_id); the summary is an ordinary DomainEvent).

Test Plan

  • nix flake check green on every commit (pre-commit hook)
  • cargo test -p nexus-example-closing-the-books — 4/4 fixture tests pass
  • cargo run -p nexus-example-closing-the-books — prints 5001-vs-11 event contrast; carried float 110 → recovered float 5100
  • cargo doc resolves the nexus::closing_the_books intra-doc link from the snapshot decorator
  • cargo clippy --all-targets on the example is warning-clean (reasoned allow for the project-banned saturating_sub nudge)
  • All three snapshot-behaviour claims in the guide independently verified against nexus-store source

🤖 Generated with Claude Code

joeldsouzax and others added 8 commits June 18, 2026 12:52
Design spec for the Tier 1 #139 card: a doc-only kernel rustdoc module
documenting the Closing the Books pattern as the preferred alternative to
snapshots, plus a runnable examples/closing-the-books crate that builds the
cash-register domain as a long-lived aggregate vs bounded CashierShift
streams and prints the difference in events replayed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Five-task TDD plan: scaffold example crate, CashierShift bounded-stream
aggregate + AggregateFixture tests, CashRegister anti-pattern with executable
replay-count contrast, kernel closing_the_books rustdoc guide module, and the
snapshot.rs cross-link + snapshot-design doc refresh.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…139)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…#139)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a prominent intra-doc pointer on the Snapshotting decorator to the
nexus::closing_the_books guide module so readers land on the preferred
alternative before adopting snapshots. Update the snapshot design doc to
replace bare #139 issue references with concrete links to the now-shipped
guide module and examples/closing-the-books example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The CloseShift compare-then-subtract trips clippy's default
implicit_saturating_sub, which suggests .saturating_sub() — the construct
CLAUDE.md rule 2 bans. The flake gate misses it (clippy runs --lib, excluding
examples), but a learner running cargo clippy --all-targets would be nudged
toward the banned API in a teaching example. Add a reasoned allow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@joeldsouzax joeldsouzax merged commit 2b495a0 into main Jun 18, 2026
2 checks passed
@joeldsouzax joeldsouzax deleted the docs/closing-the-books-139 branch June 18, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document "Closing the Books" pattern as alternative to snapshots

1 participant