Skip to main content

Overview

pipeline status coverage report License: MIT

Double-Entry Ledger Abstraction for building financial systems

Book Keeper is a ledger storage service that provides a clean API for recording and querying financial transactions. It's the foundational primitive for building wallets, billing systems, payment platforms, and accounting applications.

What is Book Keeper?​

Think of it as a database specifically designed for money:

  • Records balanced transactions using double-entry bookkeeping (every debit has an equal credit)
  • Provides adapters for different storage backends (PostgreSQL, TigerBeetle, KurrentDB)
  • Generates financial reports (General Ledger, Trial Balance, Balance Sheet)
  • Handles multi-tenant isolation so multiple companies/products can share one deployment
  • Maintains immutable audit trail of every financial state change

Real-World Example​

Building a Digital Wallet? See Wallet Use Case for a complete walkthrough of how Book Keeper powers a multi-user wallet system with transfers, refills, and balance tracking.

Key Capabilities​

FeatureDescription
Double-Entry LedgerAll transactions are balanced (debits = credits). Built-in validation.
Swappable StorageStart with PostgreSQL, scale to TigerBeetle for high-throughput.
Event IntegrationListen to business events (e.g., InvoicePaid) and auto-record transactions.
Financial ReportsPre-built projectors for GL, Trial Balance, Balance Sheet.
Multi-TenancyStrict data isolation per company/tenant.
92% Test CoverageBattle-tested with comprehensive integration and unit tests.

Quick Start​

Prerequisites​

Development Setup​

# Clone the repository
git clone https://gitlab.com/castlecraft/citadel.git
cd citadel

# Copy dev container config
cp -r devcontainer-example .devcontainer

# Open in VS Code and "Reopen in Container"
# VS Code will build the container and start all services

# Setup book-keeper environment
cd citadel/apps/book-keeper
cp devcontainer.env .env

# Run tests
pytest

# Start the service
python -m uvicorn app.main:app --reload

For detailed setup instructions, see the Getting Started Guide.

Documentation​

DocumentDescription
Wallet Use CaseComplete example: building a digital wallet system
Configuration GuideAdapter setup, environment variables, deployment
Architecture OverviewDesign patterns, bounded contexts, infrastructure
Technology StackPython, FastAPI, PostgreSQL, adapters
Getting StartedDevelopment environment setup
ADRsArchitectural decisions and rationale

Architectural Notes​

Book Keeper uses Event Sourcing and CQRS patterns for auditability and performance:

  • Write-side: Commands record events to an immutable event store
  • Read-side: Projectors build optimized views for reports and queries
  • Event Bus: Integrates with other services via NATS/Kafka

While these patterns provide strong guarantees, they add complexity. For simple use cases, consider whether you need full event sourcing or just a transactional ledger.

Note: The plugin-based translator pattern exists for event integration but is not the preferred approach. Use direct event handlers instead.

Contributing​

See the Global Contributing Guidelines for development process, standards, and how to submit changes.

License​

MIT License. See LICENSE for details.