Нема описа

C 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
.github ca752e859f Render the doc tree as a book so its diagrams and nav are usable пре 2 недеља
crates 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
doc 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
theme ca752e859f Render the doc tree as a book so its diagrams and nav are usable пре 2 недеља
.gitignore 7e7cfde94d Introduce Kuatia, an append-only, auditable multi-asset ledger пре 4 месеци
CHANGELOG.md 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
CLAUDE.md b401e9833d Cut 0.4.0, with a deadline on held funds and no cross-account read пре 4 дана
Cargo.lock 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
Cargo.toml 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
LICENSE 7e7cfde94d Introduce Kuatia, an append-only, auditable multi-asset ledger пре 4 месеци
README.md 70b9992a2d Make kuatia the only crate an application depends on пре 3 дана
book.toml 3066a87107 Give the book an examples section, its only ones being buried away пре 2 недеља
rust-toolchain.toml 7e7cfde94d Introduce Kuatia, an append-only, auditable multi-asset ledger пре 4 месеци

README.md

kuatia

kuatia (kuatiʼa) — Guaraní for paper, document, writing. A fitting name for a small, append-only ledger library.

Auditable, multi-asset UTXO-style ledger in Rust.

Overview

kuatia models value as postings — signed amounts owned by exactly one account. Transfers atomically consume existing postings and create new ones, enforcing per-asset conservation. This gives the same safety guarantee as double-entry bookkeeping (Σ debits = Σ credits), expressed as sum(consumed) == sum(created) per asset over signed postings. There are no mutable balance fields; an account's balance is always the sum of its active postings.

It supports journaling: a committed transfer is a journal entry, a transfer with multiple movements is a compound journal entry (one balanced event touching many accounts, and, since each asset balances independently, many assets), and the append-only transfer log is the accounting journal. Replaying that log reconstructs every balance, so the ledger is auditable by construction. See doc/journaling.md.

┌─────────────────────────────────────────────────────┐
│                   kuatia (async)                    │
│                                                     │
│  Intent layer:  TransferBuilder + commit · balance  │
│  Commit path:   resolve → validate → atomic commit  │
│  Composition:   workflow::run_transfers (LIFO)      │
├─────────────────────────────────────────────────────┤
│               kuatia-core (pure)                    │
│                                                     │
│  Types:        Account · Transfer · Posting · Amount│
│  Validation:    validate_and_plan()                 │
│  Hashing:       double-SHA256, content-addressed    │
│  Selection:     greedy posting selection            │
└─────────────────────────────────────────────────────┘

Crates

An application depends on kuatia alone. It re-exports the whole chain, the SQL backend as kuatia::sql behind the sqlite or postgres feature, so the crates below it are reachable without being named in a manifest. They are published for custom development: a hand-written Store, or an embedding of the pure core with no async layer at all.

Crate Purpose
kuatia What you depend on. Async resource layer: Ledger, the atomic commit engine, intent-layer API.
kuatia-core Pure, sans-IO decision logic: validation, hashing, posting selection.
kuatia-types Domain types: AccountId, Posting, Transfer, Asset, Amount.
kuatia-money The Cent monetary type behind Amount. Its integer width is swappable and never appears in a public signature.
kuatia-storage Store trait (8 sub-traits), InMemoryStore, store_tests! conformance macro.
kuatia-storage-sql SQL-backed Store: SQLite and PostgreSQL via sqlx.

Quick Example

kuatia is the only crate to name in Cargo.toml:

[dependencies]
kuatia = "0.4"
tokio = { version = "1", features = ["full"] }

An asset is registered by code on first sight, and the handle it returns is what every amount is denominated in. "100.00" parses at that asset's own scale. Alice and Bob forbid overdraft, so neither can go negative; external is the boundary account where value enters and leaves, and it permits overdraft, so it goes negative by exactly what the ledger holds.

use kuatia::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ledger = Ledger::new(InMemoryStore::new());

    let usd = ledger.asset("USD", "$", 2).await?;

    let alice = AccountId::new(1);
    let bob = AccountId::new(2);
    let external = AccountId::new(99);

    ledger
        .create_account(Account::debit_must_not_exceed_credit(alice))
        .await?;
    ledger
        .create_account(Account::debit_must_not_exceed_credit(bob))
        .await?;
    ledger.create_account(Account::new(external)).await?;

    ledger
        .commit(
            TransferBuilder::new()
                .deposit(alice, ("100.00", &usd), external)
                .build()?,
        )
        .await?;

    ledger
        .commit(
            TransferBuilder::new()
                .pay(alice, bob, ("25.00", &usd))
                .build()?,
        )
        .await?;

    println!("alice: {}", ledger.balance(&alice, &usd).await?);
    println!("bob:   {}", ledger.balance(&bob, &usd).await?);

    Ok(())
}

That is crates/kuatia/examples/quickstart.rs verbatim. Run it with cargo run -p kuatia --example quickstart; a test fails if the two drift.

Persistence

The SQLite and PostgreSQL backend is a feature of the same crate:

kuatia = { version = "0.4", features = ["sqlite"] }
let ledger = Ledger::connect("sqlite://ledger.db?mode=rwc").await?;

Only that line changes. The URL scheme picks the backend, and connect installs the driver, sizes the pool and applies the schema.

Documentation

doc/ 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.

cargo install mdbook mdbook-mermaid
mdbook serve                       # localhost:3000
mdbook build                       # into target/book

License

See LICENSE for details.