Просмотр исходного кода

Give the book an examples section, its only ones being buried away

The two worked examples were headings inside a chapter titled "Glossary &
Usage Guide", and mdBook lists chapter titles only, so a reader scanning the
navigation found no examples at all. The runnable programs sat outside the
book's source directory and nothing referenced them.

Overdraft had no example anywhere, which is the one mechanic that most needs
one: a transfer succeeds and leaves the balance negative.
C 1 неделя назад
Родитель
Сommit
3066a87107

+ 1 - 0
book.toml

@@ -30,3 +30,4 @@ command = "mdbook-mermaid"
 # redirects the path the rewrite produces.
 [output.html.redirect]
 "/adr/README.html" = "index.html"
+"/examples/README.html" = "index.html"

+ 121 - 0
crates/kuatia/examples/overdraft.rs

@@ -0,0 +1,121 @@
+//! Overdraft: a shortfall becomes a negative posting on an account that permits
+//! it, and `InsufficientFunds` on an account that does not.
+//!
+//! Run with:
+//! ```sh
+//! cargo run -p kuatia --example overdraft
+//! ```
+
+use std::sync::Arc;
+
+use kuatia::error::LedgerError;
+use kuatia::ledger::Ledger;
+use kuatia_core::*;
+use kuatia_storage_sql::SqlStore;
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+    let ledger = connect().await?;
+
+    let treasury = AccountId::new(1);
+    let wallet = AccountId::new(2);
+    let merchant = AccountId::new(3);
+    let external = AccountId::new(99);
+    let usd = AssetId::new(1);
+    let money = Amount::new(2);
+
+    ledger.create_account(Account::new(treasury)).await?;
+    ledger
+        .create_account(Account::debit_must_not_exceed_credit(wallet))
+        .await?;
+    ledger
+        .create_account(Account::debit_must_not_exceed_credit(merchant))
+        .await?;
+    ledger.create_account(Account::new(external)).await?;
+
+    for account in [treasury, wallet] {
+        ledger
+            .commit(
+                TransferBuilder::new()
+                    .deposit(account, usd, money.parse("30.00")?, external)?
+                    .build(),
+            )
+            .await?;
+    }
+
+    println!("Both accounts hold 30.00 USD. Both now try to pay 70.00 USD.\n");
+
+    println!("treasury permits overdraft (Account::new):");
+    print_postings(&ledger, treasury, usd).await?;
+
+    ledger
+        .commit(
+            TransferBuilder::new()
+                .pay(treasury, merchant, usd, money.parse("70.00")?)
+                .build(),
+        )
+        .await?;
+
+    println!(
+        "  commit succeeded, balance {} USD",
+        money.format(ledger.balance(&treasury, &usd).await?)
+    );
+    println!("  the 30.00 posting was consumed and a 40.00 shortfall posting created:");
+    print_postings(&ledger, treasury, usd).await?;
+
+    println!("\nwallet forbids it (Account::debit_must_not_exceed_credit):");
+    print_postings(&ledger, wallet, usd).await?;
+
+    let refused = ledger
+        .commit(
+            TransferBuilder::new()
+                .pay(wallet, merchant, usd, money.parse("70.00")?)
+                .build(),
+        )
+        .await;
+
+    match refused {
+        Err(LedgerError::Selection(shortfall)) => println!(
+            "  commit refused: available {} USD, requested {} USD",
+            money.format(shortfall.available),
+            money.format(shortfall.requested),
+        ),
+        Err(other) => println!("  commit refused for another reason: {other}"),
+        Ok(_) => println!("  commit succeeded, which it should not have"),
+    }
+
+    println!(
+        "  balance unchanged at {} USD",
+        money.format(ledger.balance(&wallet, &usd).await?)
+    );
+
+    Ok(())
+}
+
+/// Prints each posting with its lifecycle state, so a consumed positive and a
+/// created negative are visible side by side rather than inferred from balances.
+async fn print_postings(
+    ledger: &Arc<Ledger>,
+    account: AccountId,
+    asset: AssetId,
+) -> Result<(), Box<dyn std::error::Error>> {
+    let money = Amount::new(2);
+    for (posting, state) in ledger.postings_with_state(&account).await? {
+        if posting.asset == asset {
+            println!("    {:>10} USD  {:?}", money.format(posting.value), state);
+        }
+    }
+    Ok(())
+}
+
+async fn connect() -> Result<Arc<Ledger>, Box<dyn std::error::Error>> {
+    kuatia_storage_sql::install_drivers()?;
+    let pool = sqlx::any::AnyPoolOptions::new()
+        .max_connections(1)
+        .connect("sqlite::memory:")
+        .await?;
+    let store = SqlStore::new(pool);
+    store.migrate().await?;
+    let ledger = Arc::new(Ledger::new(store));
+    Ok(ledger)
+}

+ 8 - 4
doc/README.md

@@ -23,14 +23,18 @@ auditable by construction.
 is shaped that way, [accounts](accounts.md), [transfers](transfers.md) and the
 resolve algorithm, and [inflight holds](inflight.md).
 
+**Examples** are worked walkthroughs: [overdraft](examples/overdraft.md) and the
+shortfall posting, a [currency exchange](examples/exchange.md), a
+[retail point of sale](examples/retail.md), and the
+[runnable programs](examples/runnable.md) you can `cargo run`.
+
 **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.
+**Reference** is the [crate reference](crates.md), the
+[SQL storage schema](storage-schema.md) and the [glossary](glossary.md), which
+defines every term.
 
 **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

+ 8 - 0
doc/SUMMARY.md

@@ -10,6 +10,14 @@
 - [Transfers](transfers.md)
 - [Inflight holds](inflight.md)
 
+# Examples
+
+- [Examples](examples/README.md)
+  - [Overdraft and the shortfall posting](examples/overdraft.md)
+  - [Currency exchange](examples/exchange.md)
+  - [Retail point of sale](examples/retail.md)
+  - [Runnable programs](examples/runnable.md)
+
 # Accounting
 
 - [Journaling](journaling.md)

+ 12 - 0
doc/examples/README.md

@@ -0,0 +1,12 @@
+# Examples
+
+| Example | Shows |
+|---|---|
+| [Overdraft and the shortfall posting](overdraft.md) | A debit larger than the balance: a negative posting on an account that permits it, `InsufficientFunds` on one that does not |
+| [Currency exchange](exchange.md) | Deposit, a two-leg cross-asset trade, withdrawal, and books scoping the two flows |
+| [Retail point of sale](retail.md) | Inventory as assets, a sale recording COGS, cash deposited to bank |
+| [Runnable programs](runnable.md) | The four programs in `crates/kuatia/examples/`, included from source |
+
+The exchange and retail chapters are walkthroughs: the code is real but the
+accounts are declared inline rather than built into a program you can run. The
+overdraft and runnable chapters include programs `cargo test` compiles.

+ 84 - 0
doc/examples/exchange.md

@@ -0,0 +1,84 @@
+# Currency exchange
+
+An exchange lets users deposit fiat, trade between currencies, and withdraw.
+
+**Setup:**
+
+```rust
+use kuatia::prelude::*;
+
+// Assets
+let usd = AssetId::new(1);
+let eur = AssetId::new(2);
+
+// Books: separate deposit/withdrawal flows from trading
+let deposits_book = BookBuilder::new("deposits")
+    .allow_asset(usd)
+    .allow_asset(eur)
+    .allow_flags(AccountFlags::USER_0 | AccountFlags::USER_1) // wallets + bank
+    .build();
+
+let trading_book = BookBuilder::new("trading")
+    .allow_asset(usd)
+    .allow_asset(eur)
+    .allow_flags(AccountFlags::USER_0) // only user wallets
+    .allow_account(exchange_pool)       // + the exchange pool
+    .build();
+
+ledger.create_book(deposits_book).await?;
+ledger.create_book(trading_book).await?;
+
+// Accounts — `Account::new` sets version 1, no flags, and the default book;
+// set the other fields explicitly where the common case is not enough.
+// Boundary account: overdraft allowed by default, so it can hold the offset.
+let mut bank = Account::new(AccountId::default());
+bank.flags = AccountFlags::USER_1; // bank flag
+bank.book = deposits_book.id;
+
+// Wallet: forbids overdraft, so its balance may not go negative.
+let mut alice = Account::debit_must_not_exceed_credit(AccountId::default());
+alice.flags |= AccountFlags::USER_0; // wallet flag
+alice.book = deposits_book.id;
+
+let mut exchange_pool = Account::new(AccountId::default());
+exchange_pool.book = trading_book.id;
+```
+
+**Deposit USD into Alice's wallet:**
+
+```rust
+let deposit = TransferBuilder::new()
+    .book(deposits_book.id)
+    .deposit(alice.id, usd, Cent::from(10_000), bank.id)?
+    .build();
+ledger.commit(deposit).await?;
+// Alice: +10,000 USD
+// Bank: -10,000 USD (offset: value entered the ledger boundary)
+```
+
+**Alice trades 5,000 USD for EUR at 1:0.92:**
+
+```rust
+let trade = TransferBuilder::new()
+    .book(trading_book.id)
+    .pay(alice.id, exchange_pool, usd, Cent::from(5_000))
+    .pay(exchange_pool, alice.id, eur, Cent::from(4_600))
+    .build();
+ledger.commit(trade).await?;
+// Alice: 5,000 USD + 4,600 EUR
+// Exchange pool: 5,000 USD - 4,600 EUR
+```
+
+**Withdraw EUR to Alice's bank:**
+
+```rust
+let withdrawal = TransferBuilder::new()
+    .book(deposits_book.id)
+    .withdraw(alice.id, eur, Cent::from(4_600), bank.id)
+    .build();
+ledger.commit(withdrawal).await?;
+// Alice: 5,000 USD, 0 EUR
+// Bank: -10,000 USD + 4,600 EUR
+```
+
+Conservation holds at every step. The exchange pool absorbs the spread.

+ 41 - 0
doc/examples/overdraft.md

@@ -0,0 +1,41 @@
+# Overdraft and the shortfall posting
+
+Two accounts hold the same 30.00 USD. Both try to pay 70.00 USD. One succeeds
+and ends up negative; the other is refused. The difference is a single flag.
+
+An account created with `Account::new` permits overdraft without bound. When its
+positive postings do not cover a debit, resolve consumes all of them and creates
+a negative posting for the remainder, and the transfer records because value
+still conserves per asset. An account created with
+`Account::debit_must_not_exceed_credit` carries
+`AccountFlags::DEBIT_MUST_NOT_EXCEED_CREDIT`, cannot hold a negative posting, and
+fails selection with `InsufficientFunds` instead. See
+[accounts](../accounts.md#balance-constraint) for the rule and
+[transfers](../transfers.md#resolve-algorithm) for where in resolve it applies.
+
+Running the program below prints both outcomes:
+
+```text
+Both accounts hold 30.00 USD. Both now try to pay 70.00 USD.
+
+treasury permits overdraft (Account::new):
+         30.00 USD  Active
+  commit succeeded, balance -40.00 USD
+  the 30.00 posting was consumed and a 40.00 shortfall posting created:
+         30.00 USD  Spent
+        -40.00 USD  Active
+
+wallet forbids it (Account::debit_must_not_exceed_credit):
+         30.00 USD  Active
+  commit refused: available 30.00 USD, requested 70.00 USD
+  balance unchanged at 30.00 USD
+```
+
+The shortfall posting is why the balance reads -40.00 without any field being
+mutated: the account's postings are now +30.00 (spent) and -40.00 (live), and
+the balance is the sum of the live ones. The merchant's +70.00 posting makes the
+transfer conserve: 30.00 consumed, 70.00 and -40.00 created.
+
+```rust
+{{#include ../../crates/kuatia/examples/overdraft.rs}}
+```

+ 118 - 0
doc/examples/retail.md

@@ -0,0 +1,118 @@
+# Retail point of sale
+
+A supermarket tracks inventory as product assets, records sales with COGS, and
+manages cash and bank accounts.
+
+**Setup:**
+
+```rust
+// Assets
+let gs = AssetId::new(1);            // Guaranies (currency)
+let product_a = AssetId::new(100);   // Product: rice 1kg
+let product_b = AssetId::new(101);   // Product: cooking oil 1L
+
+// Account flags
+const WAREHOUSE: AccountFlags = AccountFlags::USER_0;
+const CUSTOMER: AccountFlags = AccountFlags::USER_1;
+const REVENUE: AccountFlags = AccountFlags::USER_2;
+const BANK: AccountFlags = AccountFlags::USER_3;
+
+// Books
+let sales_book = BookBuilder::new("sales")
+    .allow_asset(gs)
+    .allow_asset(product_a)
+    .allow_asset(product_b)
+    .allow_flags(WAREHOUSE | CUSTOMER | REVENUE)
+    .build();
+
+let inventory_book = BookBuilder::new("inventory")
+    .allow_asset(product_a)
+    .allow_asset(product_b)
+    .allow_flags(WAREHOUSE)
+    .allow_account(world) // issuance source
+    .build();
+
+let banking_book = BookBuilder::new("banking")
+    .allow_asset(gs)
+    .allow_flags(WAREHOUSE | BANK)
+    .build();
+
+// Accounts — start from a constructor, then set flags where needed.
+// issuance source: mints product tokens on receipt (overdraft allowed)
+let world = Account::new(AccountId::default());
+
+let mut warehouse = Account::debit_must_not_exceed_credit(AccountId::default());
+warehouse.flags |= WAREHOUSE;
+
+let mut cash_register = Account::debit_must_not_exceed_credit(AccountId::default());
+cash_register.flags |= WAREHOUSE;
+
+let mut revenue = Account::new(AccountId::default());
+revenue.flags = REVENUE;
+
+let mut cogs = Account::new(AccountId::default()); // cost of goods sold
+cogs.flags = REVENUE;
+
+let mut bank = Account::debit_must_not_exceed_credit(AccountId::default());
+bank.flags |= BANK;
+```
+
+**Receive inventory from supplier (50 units of rice):**
+
+```rust
+let receipt = TransferBuilder::new()
+    .book(inventory_book.id)
+    .pay(world, warehouse.id, product_a, Cent::from(50_000)) // 50.000 units (precision 3)
+    .build();
+ledger.commit(receipt).await?;
+// Warehouse: +50.000 rice
+// World: -50.000 rice (offset: issued into the ledger)
+```
+
+**Cash sale, customer buys 2 rice at 15,000 Gs each:**
+
+```rust
+let sale = TransferBuilder::new()
+    .book(sales_book.id)
+    // Move product from warehouse to customer (consumed by sale)
+    .pay(warehouse.id, customer.id, product_a, Cent::from(2_000))
+    // Customer pays cash
+    .pay(customer.id, cash_register.id, gs, Cent::from(30_000))
+    // Record revenue
+    .pay(world, revenue.id, gs, Cent::from(30_000))
+    // Record COGS (cost was 10,000 Gs per unit)
+    .pay(world, cogs.id, gs, Cent::from(20_000))
+    .build();
+ledger.commit(sale).await?;
+```
+
+**Deposit cash to bank:**
+
+```rust
+let deposit = TransferBuilder::new()
+    .book(banking_book.id)
+    .pay(cash_register.id, bank.id, gs, Cent::from(30_000))
+    .build();
+ledger.commit(deposit).await?;
+```
+
+**Query balances:**
+
+```rust
+let warehouse_rice = ledger.balance(&warehouse.id, &product_a).await?;
+// 48.000 units remaining
+
+let bank_balance = ledger.balance(&bank.id, &gs).await?;
+// 30,000 Gs
+
+let total_revenue = ledger.balance(&revenue.id, &gs).await?;
+// 30,000 Gs
+
+let total_cogs = ledger.balance(&cogs.id, &gs).await?;
+// 20,000 Gs gross profit = revenue - cogs = 10,000 Gs
+```
+
+**Why books matter here:** The `sales` book prevents a bug where a bank
+transfer accidentally credits the revenue account. The `banking` book ensures
+only cash and bank accounts participate in deposits. Each flow is isolated by
+scope while sharing the same global balances.

+ 44 - 0
doc/examples/runnable.md

@@ -0,0 +1,44 @@
+# Runnable programs
+
+Four programs in `crates/kuatia/examples/` drive a real ledger over SQLite in
+memory, so each one runs with no setup:
+
+```sh
+cargo run -p kuatia --example create_accounts
+cargo run -p kuatia --example fund_and_trade
+cargo run -p kuatia --example withdraw
+cargo run -p kuatia --example inflight_hold
+```
+
+They are included below from source, so what the book shows is the code `cargo
+test` compiles.
+
+## Create accounts
+
+```rust
+{{#include ../../crates/kuatia/examples/create_accounts.rs}}
+```
+
+## Fund and trade
+
+A deposit into two accounts, then a cross-asset trade settled as one transfer:
+each asset conserves independently, so a swap needs no special verb.
+
+```rust
+{{#include ../../crates/kuatia/examples/fund_and_trade.rs}}
+```
+
+## Withdraw
+
+```rust
+{{#include ../../crates/kuatia/examples/withdraw.rs}}
+```
+
+## Inflight hold
+
+Authorize, confirm and void through a per-destination holding subaccount; see
+[inflight holds](../inflight.md).
+
+```rust
+{{#include ../../crates/kuatia/examples/inflight_hold.rs}}
+```

+ 5 - 206
doc/glossary.md

@@ -1,4 +1,4 @@
-# Glossary & Usage Guide
+# Glossary
 
 > Coming from classical accounting? See
 > [accounting-mapping.md](accounting-mapping.md) for how journals, entries, and
@@ -132,212 +132,11 @@ assigns IDs.
 
 ---
 
-## Usage Examples
+## Usage examples
 
-### Example 1: Currency Exchange
-
-An exchange lets users deposit fiat, trade between currencies, and withdraw.
-
-**Setup:**
-
-```rust
-use kuatia::prelude::*;
-
-// Assets
-let usd = AssetId::new(1);
-let eur = AssetId::new(2);
-
-// Books: separate deposit/withdrawal flows from trading
-let deposits_book = BookBuilder::new("deposits")
-    .allow_asset(usd)
-    .allow_asset(eur)
-    .allow_flags(AccountFlags::USER_0 | AccountFlags::USER_1) // wallets + bank
-    .build();
-
-let trading_book = BookBuilder::new("trading")
-    .allow_asset(usd)
-    .allow_asset(eur)
-    .allow_flags(AccountFlags::USER_0) // only user wallets
-    .allow_account(exchange_pool)       // + the exchange pool
-    .build();
-
-ledger.create_book(deposits_book).await?;
-ledger.create_book(trading_book).await?;
-
-// Accounts — `Account::new` sets version 1, no flags, and the default book;
-// set the other fields explicitly where the common case is not enough.
-// Boundary account: overdraft allowed by default, so it can hold the offset.
-let mut bank = Account::new(AccountId::default());
-bank.flags = AccountFlags::USER_1; // bank flag
-bank.book = deposits_book.id;
-
-// Wallet: forbids overdraft, so its balance may not go negative.
-let mut alice = Account::debit_must_not_exceed_credit(AccountId::default());
-alice.flags |= AccountFlags::USER_0; // wallet flag
-alice.book = deposits_book.id;
-
-let mut exchange_pool = Account::new(AccountId::default());
-exchange_pool.book = trading_book.id;
-```
-
-**Deposit USD into Alice's wallet:**
-
-```rust
-let deposit = TransferBuilder::new()
-    .book(deposits_book.id)
-    .deposit(alice.id, usd, Cent::from(10_000), bank.id)?
-    .build();
-ledger.commit(deposit).await?;
-// Alice: +10,000 USD
-// Bank: -10,000 USD (offset: value entered the ledger boundary)
-```
-
-**Alice trades 5,000 USD for EUR at 1:0.92:**
-
-```rust
-let trade = TransferBuilder::new()
-    .book(trading_book.id)
-    .pay(alice.id, exchange_pool, usd, Cent::from(5_000))
-    .pay(exchange_pool, alice.id, eur, Cent::from(4_600))
-    .build();
-ledger.commit(trade).await?;
-// Alice: 5,000 USD + 4,600 EUR
-// Exchange pool: 5,000 USD - 4,600 EUR
-```
-
-**Withdraw EUR to Alice's bank:**
-
-```rust
-let withdrawal = TransferBuilder::new()
-    .book(deposits_book.id)
-    .withdraw(alice.id, eur, Cent::from(4_600), bank.id)
-    .build();
-ledger.commit(withdrawal).await?;
-// Alice: 5,000 USD, 0 EUR
-// Bank: -10,000 USD + 4,600 EUR
-```
-
-Conservation holds at every step. The exchange pool absorbs the spread.
-
-
-### Example 2: Supermarket / Retail POS
-
-A supermarket tracks inventory as product assets, records sales with COGS, and
-manages cash and bank accounts.
-
-**Setup:**
-
-```rust
-// Assets
-let gs = AssetId::new(1);            // Guaranies (currency)
-let product_a = AssetId::new(100);   // Product: rice 1kg
-let product_b = AssetId::new(101);   // Product: cooking oil 1L
-
-// Account flags
-const WAREHOUSE: AccountFlags = AccountFlags::USER_0;
-const CUSTOMER: AccountFlags = AccountFlags::USER_1;
-const REVENUE: AccountFlags = AccountFlags::USER_2;
-const BANK: AccountFlags = AccountFlags::USER_3;
-
-// Books
-let sales_book = BookBuilder::new("sales")
-    .allow_asset(gs)
-    .allow_asset(product_a)
-    .allow_asset(product_b)
-    .allow_flags(WAREHOUSE | CUSTOMER | REVENUE)
-    .build();
-
-let inventory_book = BookBuilder::new("inventory")
-    .allow_asset(product_a)
-    .allow_asset(product_b)
-    .allow_flags(WAREHOUSE)
-    .allow_account(world) // issuance source
-    .build();
-
-let banking_book = BookBuilder::new("banking")
-    .allow_asset(gs)
-    .allow_flags(WAREHOUSE | BANK)
-    .build();
-
-// Accounts — start from a constructor, then set flags where needed.
-// issuance source: mints product tokens on receipt (overdraft allowed)
-let world = Account::new(AccountId::default());
-
-let mut warehouse = Account::debit_must_not_exceed_credit(AccountId::default());
-warehouse.flags |= WAREHOUSE;
-
-let mut cash_register = Account::debit_must_not_exceed_credit(AccountId::default());
-cash_register.flags |= WAREHOUSE;
-
-let mut revenue = Account::new(AccountId::default());
-revenue.flags = REVENUE;
-
-let mut cogs = Account::new(AccountId::default()); // cost of goods sold
-cogs.flags = REVENUE;
-
-let mut bank = Account::debit_must_not_exceed_credit(AccountId::default());
-bank.flags |= BANK;
-```
-
-**Receive inventory from supplier (50 units of rice):**
-
-```rust
-let receipt = TransferBuilder::new()
-    .book(inventory_book.id)
-    .pay(world, warehouse.id, product_a, Cent::from(50_000)) // 50.000 units (precision 3)
-    .build();
-ledger.commit(receipt).await?;
-// Warehouse: +50.000 rice
-// World: -50.000 rice (offset: issued into the ledger)
-```
-
-**Cash sale, customer buys 2 rice at 15,000 Gs each:**
-
-```rust
-let sale = TransferBuilder::new()
-    .book(sales_book.id)
-    // Move product from warehouse to customer (consumed by sale)
-    .pay(warehouse.id, customer.id, product_a, Cent::from(2_000))
-    // Customer pays cash
-    .pay(customer.id, cash_register.id, gs, Cent::from(30_000))
-    // Record revenue
-    .pay(world, revenue.id, gs, Cent::from(30_000))
-    // Record COGS (cost was 10,000 Gs per unit)
-    .pay(world, cogs.id, gs, Cent::from(20_000))
-    .build();
-ledger.commit(sale).await?;
-```
-
-**Deposit cash to bank:**
-
-```rust
-let deposit = TransferBuilder::new()
-    .book(banking_book.id)
-    .pay(cash_register.id, bank.id, gs, Cent::from(30_000))
-    .build();
-ledger.commit(deposit).await?;
-```
-
-**Query balances:**
-
-```rust
-let warehouse_rice = ledger.balance(&warehouse.id, &product_a).await?;
-// 48.000 units remaining
-
-let bank_balance = ledger.balance(&bank.id, &gs).await?;
-// 30,000 Gs
-
-let total_revenue = ledger.balance(&revenue.id, &gs).await?;
-// 30,000 Gs
-
-let total_cogs = ledger.balance(&cogs.id, &gs).await?;
-// 20,000 Gs gross profit = revenue - cogs = 10,000 Gs
-```
-
-**Why books matter here:** The `sales` book prevents a bug where a bank
-transfer accidentally credits the revenue account. The `banking` book ensures
-only cash and bank accounts participate in deposits. Each flow is isolated by
-scope while sharing the same global balances.
+The worked examples moved to their own section: [overdraft](examples/overdraft.md),
+[currency exchange](examples/exchange.md), [retail point of sale](examples/retail.md),
+and the [runnable programs](examples/runnable.md).
 
 ---