Cala Rust Library

website·Indexed 31 days ago

https://cala.sh

A Rust library for embedding a double-entry accounting ledger into services to build banking software at enterprise scale.

Tokens
1.1K
Snippets
5
Records
13
Agent score
63%

What's inside Cala

  1. Implement Double-Entry Accounting principles

    Double-entry accounting is a bookkeeping system where every financial transaction is recorded in at least two accounts: one debited and one credited. This ensures the fundamental accounting equation (Assets = Liabilities + Equity) remains balanced.

    Key operational rules:

    • Every transaction must have equal debits and credits.
    • Each transaction must affect at least two accounts to maintain the balance of the accounting equation.

    Benefits include increased accuracy (via balancing), comprehensive financial tracking, regulatory compliance, and a detailed view of a business's financial health.

    Example: Taking out a loan
    - Debit: Cash account (Asset increases)
    - Credit: Loans Payable account (Liability increases)
  2. Embed the Cala ledger in a Rust service

    Cala is an extensible, open-source core banking ledger designed for enterprise-scale banking applications. Unlike a standalone server, Cala is provided as a Rust library via the cala-ledger crate, allowing it to be embedded directly into a Rust application without the need for a separate runtime or server deployment. It supports double-entry accounting to ensure every transaction is recorded accurately on both sides of the ledger.
  3. Use the cala-ledger Rust crate

    To integrate Cala's ledger capabilities into a Rust service, use the cala-ledger crate. This allows the ledger to run wherever the Rust service is deployed (cloud, local, or private servers). Detailed API documentation, guides, and examples are available on docs.rs.
    [dependencies]
    cala-ledger = "#insert-version"
  4. Initialize the Cala Ledger with PostgreSQL

    To initialize the Cala ledger, create a PostgreSQL connection pool using sqlx and configure the CalaLedgerConfig. Setting exec_migrations(true) ensures the database schema is up to date. Finally, call CalaLedger::init(config) to instantiate the ledger.
    use cala_ledger::{CalaLedger, CalaLedgerConfig};
    
    let pool = sqlx::postgres::PgPoolOptions::new()
        .max_connections(20)
        .connect("postgres://user:password@localhost:5432/pg")
        .await?;
    
    let config = CalaLedgerConfig::builder()
        .pool(pool)
        .exec_migrations(true)
        .build()?;
    let cala = CalaLedger::init(config).await?;
  5. Add cala-ledger dependency to a Rust project

    Cala is a Rust library designed to be embedded within your own service. To use it, add the cala-ledger crate to your Cargo.toml file. A PostgreSQL database is required for the ledger to operate.
    cala-ledger = "0.20"
  6. Use Transaction Templates for recurring events

    Transaction templates are predefined structures used for specific transaction types (e.g., deposits or withdrawals). They ensure consistency and accuracy for recurring transactions by specifying required parameters and transaction details.
  7. Understand Journal entities in Cala

    A journal serves as a chronological record of all financial transactions. Each journal entry must include the date, the accounts affected, and the specific amounts debited or credited. In Cala, each journal is uniquely identified by a journalId.
  8. Manage Account Sets in Cala

    An Account Set is a grouping of accounts associated with a specific journal to facilitate management and reporting of related financial activities. Account Sets allow for the application of transaction templates and the tracking of consolidated balances. In Cala, each Account Set is uniquely identified by an accountSetId.
  9. Apply Debit and Credit logic in Cala

    Financial transactions in Cala use a double-entry system with two sides:

    • Debit: An entry on the left side of a ledger. It increases asset or expense accounts and decreases liability, equity, or revenue accounts.
    • Credit: An entry on the right side of a ledger. It increases liability, equity, or revenue accounts and decreases asset or expense accounts.
  10. Identify entities using UUIDs in Cala

    Cala uses 128-bit Universally Unique Identifiers (UUIDs) to uniquely identify core system entities, specifically accounts, journals, and transactions.
  11. Understand Transaction entities in Cala

    A transaction is a financial event that affects general ledger accounts. Transactions are recorded within journals and typically consist of debits and credits distributed across different accounts.
  12. Understand Account entities in Cala

    An account is a record in the general ledger used to track financial transactions. Accounts are categorized into five types: assets, liabilities, equity, revenues, or expenses. In Cala, every account is uniquely identified by an accountId.