Explorar el Código

Render the doc tree as a book so its diagrams and nav are usable

C hace 1 semana
padre
commit
ca752e859f
Se han modificado 9 ficheros con 205 adiciones y 8 borrados
  1. 30 0
      .github/workflows/ci.yml
  2. 12 7
      README.md
  3. 32 0
      book.toml
  4. 37 0
      doc/README.md
  5. 51 0
      doc/SUMMARY.md
  6. 1 1
      doc/accounts.md
  7. 1 0
      doc/changelog.md
  8. 39 0
      theme/mermaid-init.js
  9. 2 0
      theme/mermaid.min.js

+ 30 - 0
.github/workflows/ci.yml

@@ -42,6 +42,36 @@ jobs:
       - uses: Swatinem/rust-cache@v2
       - run: cargo doc --workspace --all-features --no-deps
 
+  # `mdbook build` and not `mdbook test`: the rust samples in `doc/` are
+  # fragments naming types the surrounding prose never defines. With
+  # `create-missing` off in book.toml, a SUMMARY entry pointing at nothing
+  # fails here.
+  book:
+    name: Book
+    runs-on: ubuntu-latest
+    env:
+      MDBOOK: 0.5.4
+      MDBOOK_MERMAID: 0.17.1
+    steps:
+      - uses: actions/checkout@v4
+
+      # Prebuilt, because building mdBook from source costs more than the rest
+      # of this workflow and nothing here needs a toolchain.
+      - name: Install mdBook
+        run: |
+          mkdir -p "$HOME/.local/bin"
+          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
+          base=https://github.com/rust-lang/mdBook/releases/download
+          curl -sSfL \
+            "$base/v$MDBOOK/mdbook-v$MDBOOK-x86_64-unknown-linux-gnu.tar.gz" \
+            | tar -xz -C "$HOME/.local/bin"
+          base=https://github.com/badboy/mdbook-mermaid/releases/download
+          curl -sSfL \
+            "$base/v$MDBOOK_MERMAID/mdbook-mermaid-v$MDBOOK_MERMAID-x86_64-unknown-linux-gnu.tar.gz" \
+            | tar -xz -C "$HOME/.local/bin"
+
+      - run: mdbook build
+
   test:
     name: Test (SQLite, i64)
     runs-on: ubuntu-latest

+ 12 - 7
README.md

@@ -75,13 +75,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
 
 ## Documentation
 
-- [Architecture Decisions](doc/architecture.md) — why the ledger works the way it does
-- [Crate Reference](doc/crates.md) — modules, types, and APIs per crate
-- [Accounts](doc/accounts.md) — account model, policies, and lifecycle
-- [Transfers](doc/transfers.md) — Movement struct, resolve algorithm, and TransferBuilder API
-- [Journaling](doc/journaling.md) — transfers as journal entries, compound and multi-asset entries, the transfer log as the journal
-- [Glossary](doc/glossary.md) — terms, book scoping, and worked examples
-- [Accounting Mapping](doc/accounting-mapping.md) — how classical double-entry concepts map onto kuatia
+[`doc/`](doc/README.md) holds the full documentation: the model, the accounting
+mapping, the crate and SQL schema reference, and the ADR log.
+
+It is also an mdbook, so the same files render with a table of contents,
+search, and the mermaid diagrams drawn rather than printed. That needs `mdbook`
+and `mdbook-mermaid`.
+
+```sh
+cargo install mdbook mdbook-mermaid
+mdbook serve                       # localhost:3000
+mdbook build                       # into target/book
+```
 
 ## License
 

+ 32 - 0
book.toml

@@ -0,0 +1,32 @@
+[book]
+title = "Kuatia"
+description = "An append-only, auditable, multi-asset UTXO-style ledger."
+language = "en"
+src = "doc"
+
+# `create-missing` off because the default quietly writes an empty chapter for a
+# SUMMARY entry that names nothing, which is the one mistake a build check
+# exists to catch.
+[build]
+build-dir = "target/book"
+create-missing = false
+
+[output.html]
+git-repository-url = "https://github.com/crodas/kuatia"
+# `{path}` already carries the source directory, so it is not repeated here.
+edit-url-template = "https://github.com/crodas/kuatia/edit/master/{path}"
+additional-js = ["theme/mermaid.min.js", "theme/mermaid-init.js"]
+
+[output.html.fold]
+enable = true
+level = 1
+
+[preprocessor.mermaid]
+command = "mdbook-mermaid"
+
+# mdBook renders a chapter sourced from `README.md` as its directory's
+# `index.html`, but rewrites a link naming that file to `README.html`. The
+# source has to keep the name GitHub renders for a directory, so the book
+# redirects the path the rewrite produces.
+[output.html.redirect]
+"/adr/README.html" = "index.html"

+ 37 - 0
doc/README.md

@@ -0,0 +1,37 @@
+# Kuatia
+
+> **kuatia** (kuatiʼa) is Guaraní for *paper*, *document*, *writing*.
+
+An append-only, auditable, multi-asset UTXO-style ledger library in Rust.
+
+Kuatia models value as **postings**: signed amounts of one asset owned by
+exactly one account. A transfer atomically consumes existing postings and
+creates new ones, enforcing per-asset conservation (`sum(consumed) ==
+sum(created)`). That is the same safety guarantee as double-entry bookkeeping,
+`Σ debits = Σ credits`, expressed over signed postings. There are no mutable
+balance fields, so an account's balance is always the sum of its live postings.
+
+A committed transfer is a journal entry. A transfer with several movements is a
+compound entry, one balanced event touching many accounts and, since each asset
+balances independently, many assets. The append-only transfer log is the
+accounting journal: replaying it reconstructs every balance, so the ledger is
+auditable by construction.
+
+## How this book is laid out
+
+**Concepts** covers the model: the [architecture](architecture.md) and why it
+is shaped that way, [accounts](accounts.md), [transfers](transfers.md) and the
+resolve algorithm, and [inflight holds](inflight.md).
+
+**Accounting** maps the model onto practice, both as
+[journaling](journaling.md) and as a term-by-term
+[mapping](accounting-mapping.md) from classical double-entry.
+
+**Reference** is the [crate reference](crates.md) and the
+[SQL storage schema](storage-schema.md). The [glossary](glossary.md) defines
+every term and carries two worked examples, a currency exchange and a retail
+point of sale.
+
+**Decisions** is the [ADR log](adr/README.md): every significant, hard-to-reverse
+design decision, with the options that were rejected and why. An ADR is never
+edited to reverse a decision; a later one supersedes it.

+ 51 - 0
doc/SUMMARY.md

@@ -0,0 +1,51 @@
+# Summary
+
+[Kuatia](README.md)
+[Glossary](glossary.md)
+
+# Concepts
+
+- [Architecture](architecture.md)
+- [Accounts](accounts.md)
+- [Transfers](transfers.md)
+- [Inflight holds](inflight.md)
+
+# Accounting
+
+- [Journaling](journaling.md)
+- [Accounting mapping](accounting-mapping.md)
+
+# Reference
+
+- [Crate reference](crates.md)
+- [SQL storage schema](storage-schema.md)
+- [Changelog](changelog.md)
+
+# Decisions
+
+- [Architecture decision records](adr/README.md)
+  - [0001: Modified UTXO: value as signed postings](adr/0001-modified-utxo-signed-postings.md)
+  - [0002: Saga commit pipeline](adr/0002-saga-commit-pipeline.md)
+  - [0003: Dumb storage + durable saga recovery](adr/0003-dumb-storage-saga-recovery.md)
+  - [0004: Account policies & overdraft model](adr/0004-account-policies-overdraft-model.md)
+  - [0005: Intent API: movements vs. envelopes](adr/0005-intent-api-movements-vs-envelopes.md)
+  - [0006: Reservation protocol & posting lifecycle](adr/0006-reservation-protocol-posting-lifecycle.md)
+  - [0007: Reversal via compensating transfers](adr/0007-reversal-via-compensating-transfers.md)
+  - [0008: Conformance-tested storage](adr/0008-conformance-tested-storage.md)
+  - [0009: Monetary amounts as integer minor units](adr/0009-monetary-representation-integer-minor-units.md)
+  - [0010: Derived event stream vs. transfer log](adr/0010-event-stream-vs-transfer-log.md)
+  - [0011: Swappable integer backing for money, default i64](adr/0011-swappable-money-backing.md)
+  - [0012: Subaccount dimension on account identity](adr/0012-subaccounts.md)
+  - [0013: Journaling model: transfer as journal entry](adr/0013-journaling-model.md)
+  - [0014: Inflight holds via per-destination holding accounts](adr/0014-inflight-holds-via-holding-accounts.md)
+  - [0015: Fixed-width 20-character account code](adr/0015-fixed-width-account-code.md)
+  - [0016: Immutable postings with active/reserved index tables](adr/0016-immutable-postings-index-tables.md)
+  - [0017: Correctness-first storage: append-only value tables, disposable hot indexes](adr/0017-correctness-first-append-only-hot-indexes.md)
+  - [0018: Collapse account policy into a single debit-must-not-exceed-credit flag](adr/0018-single-debit-must-not-exceed-credit-flag.md)
+  - [0019: Cached balance projection via append-only cache points](adr/0019-cached-balance-projection.md)
+  - [0020: Crash-safe account-version transitions](adr/0020-account-transition-recovery.md)
+  - [0021: The commit-safety invariant and where each part is enforced](adr/0021-commit-safety-map.md)
+  - [0022: Merge the active/reserved hot indexes into one `live_postings` table](adr/0022-merged-live-postings-hot-index.md)
+  - [0023: Atomic storage commit, retiring the write-ahead saga and `legend`](adr/0023-atomic-storage-commit.md)
+  - [0024: Native money columns, and exact summation in the database](adr/0024-native-money-columns.md)
+  - [ADR template](adr/template.md)

+ 1 - 1
doc/accounts.md

@@ -136,7 +136,7 @@ preventing TOCTOU races where an account is mutated between load and apply.
 
 The saga `commit()` path auto-populates snapshots when none are provided.
 
-## Subaccounts
+## Subaccounts and balances
 
 An account is identified by a base id plus an `i64` **subaccount**, written
 `AccountId { id, sub }`; `sub = 0` is the main account. Each `(id,

+ 1 - 0
doc/changelog.md

@@ -0,0 +1 @@
+{{#include ../CHANGELOG.md}}

+ 39 - 0
theme/mermaid-init.js

@@ -0,0 +1,39 @@
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+(() => {
+    const darkThemes = ['ayu', 'navy', 'coal'];
+    const lightThemes = ['light', 'rust'];
+
+    const classList = document.getElementsByTagName('html')[0].classList;
+
+    let lastThemeWasLight = true;
+    for (const cssClass of classList) {
+        if (darkThemes.includes(cssClass)) {
+            lastThemeWasLight = false;
+            break;
+        }
+    }
+
+    const theme = lastThemeWasLight ? 'default' : 'dark';
+    mermaid.initialize({ startOnLoad: true, theme });
+
+    // Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
+
+    for (const darkTheme of darkThemes) {
+        document.getElementById('mdbook-theme-' + darkTheme).addEventListener('click', () => {
+            if (lastThemeWasLight) {
+                window.location.reload();
+            }
+        });
+    }
+
+    for (const lightTheme of lightThemes) {
+        document.getElementById('mdbook-theme-' + lightTheme).addEventListener('click', () => {
+            if (!lastThemeWasLight) {
+                window.location.reload();
+            }
+        });
+    }
+})();

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 0
theme/mermaid.min.js


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio