#ledger #transaction #accounting #control #cala #account #journal

bin+lib cala-ledger

An embeddable double sided accounting ledger built on PG/SQLx

60 releases

new 0.3.2 Dec 6, 2024
0.2.46 Nov 15, 2024
0.2.30 Jul 23, 2024

#6 in #cala

Download history 1004/week @ 2024-08-15 294/week @ 2024-08-22 77/week @ 2024-08-29 132/week @ 2024-09-05 10/week @ 2024-09-12 163/week @ 2024-09-19 81/week @ 2024-09-26 14/week @ 2024-10-03 15/week @ 2024-10-10 7/week @ 2024-10-17 30/week @ 2024-10-31 20/week @ 2024-11-07 236/week @ 2024-11-14 22/week @ 2024-11-21 234/week @ 2024-11-28

513 downloads per month
Used in cala-server

Apache-2.0

410KB
11K SLoC

Cala

Cala is a robust ledger system developed by Galoy, designed to handle complex financial transactions and accounting operations. It provides a flexible and scalable solution for managing financial records with strong consistency guarantees.

Features

Core Capabilities

  • Double-Entry Accounting: Built-in support for double-entry bookkeeping principles ensuring accurate financial records
  • SQL-Compatible: Engineered to work with SQL databases (PostgreSQL) for robust data persistence and querying
  • Strong Consistency: Ensures accuracy and reliability of financial records
  • Real-time Processing: Efficient transaction processing suitable for production financial systems

API & Integration

  • GraphQL API: Modern API interface with built-in playground for easy integration and testing
  • Extensible Architecture: Modular design with support for custom extensions via the Node.js bindings
  • Transaction Templates: Customizable transaction templates for common financial operations
  • Multi-Currency Support: Handle transactions across different currencies

Core Entities

Accounts

  • Unique identification via UUID and optional external IDs
  • Configurable normal balance type (debit/credit)
  • Version-controlled with status tracking (active/locked)
  • Rich metadata support with JSON fields
  • Balance queries with currency and time-range filtering

Account Sets

  • Hierarchical account grouping with nested set support
  • Journal-scoped for organizational separation
  • Consolidated balance reporting across member accounts
  • Flexible member management (add/remove operations)

Journals

  • Independent ledger contexts for transaction isolation
  • Support for multiple concurrent journals
  • Transaction correlation and external ID tracking

Transactions

  • Template-based transaction creation
  • Effective dating support
  • Correlation ID for transaction linking
  • Multi-layer support (settled/pending/encumbrance)
  • Rich metadata and external ID tracking

Velocity Controls

  • Configurable transaction limits
  • Balance-based and time-based controls
  • Multiple limit aggregation support
  • Flexible control attachment to accounts/sets

Technical Specifications

Query Interface

  • Point lookups by UUID, external ID, and code
  • Cursor-based pagination with configurable page sizes
  • Balance queries with time range support
  • Comprehensive transaction search

Type System

  • Strong typing with custom scalars (UUID, Timestamp, Date)
  • JSON support for flexible metadata
  • Decimal type for precise financial calculations
  • Expression-based template parameters

Implementation Details

  • Consistent versioning across all entities
  • Optimistic concurrency control
  • Immutable audit fields (createdAt, modifiedAt)
  • Rich error handling and validation

Developer Experience

  • Interactive GraphQL playground at http://localhost:2252/graphql
  • Built-in schema documentation
  • Query validation and type checking

Components

  • cala-ledger: Core ledger implementation
  • cala-server: Server implementation handling API requests
  • cala-nodejs: Node.js bindings for integration with JavaScript/TypeScript applications
  • cala-cel-interpreter & cala-cel-parser: Common Expression Language (CEL) support
  • cala-tracing: Tracing and monitoring functionality

Developing

Dependencies

Nix package manager

direnv >= 2.30.0

Docker

Testing

Run unit tests with:

make reset-deps next-watch

Run end-to-end tests with:

make e2e

Running the Server

To run the server:

make run-server

Dependencies

~52–73MB
~1.5M SLoC