Crates.io | accounting-core |
lib.rs | accounting-core |
version | 0.1.1 |
created_at | 2025-08-21 05:49:04.700691+00 |
updated_at | 2025-08-27 09:29:42.754883+00 |
description | Core accounting functionality with double-entry bookkeeping, GST calculations, and financial reporting |
homepage | |
repository | https://github.com/harisr92/accounting-blue |
max_upload_size | |
id | 1804348 |
size | 228,463 |
A comprehensive Rust library for double-entry bookkeeping, GST calculations, and financial reporting. Designed as the open-source foundation for accounting applications.
Add this to your Cargo.toml
:
[dependencies]
accounting-core = "0.1.0"
use accounting_core::{Ledger, AccountType, TransactionBuilder};
use accounting_core::utils::MemoryStorage;
use bigdecimal::BigDecimal;
use chrono::NaiveDate;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a ledger with in-memory storage
let storage = MemoryStorage::new();
let mut ledger = Ledger::new(storage);
// Set up basic accounts
let cash = ledger.create_account(
"cash".to_string(),
"Cash".to_string(),
AccountType::Asset,
None,
).await?;
let revenue = ledger.create_account(
"revenue".to_string(),
"Revenue".to_string(),
AccountType::Income,
None,
).await?;
// Record a transaction
let transaction = TransactionBuilder::new(
"txn001".to_string(),
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
"Sale of goods".to_string(),
)
.debit(cash.id.clone(), BigDecimal::from(1000), None)
.credit(revenue.id.clone(), BigDecimal::from(1000), None)
.build()?;
ledger.record_transaction(transaction).await?;
// Generate reports
let balance_sheet = ledger.generate_balance_sheet(
NaiveDate::from_ymd_opt(2024, 1, 31).unwrap()
).await?;
println!("Total Assets: {}", balance_sheet.total_assets);
Ok(())
}
use accounting_core::{GstCalculator, GstCategory, GstLineItem, GstInvoice};
use bigdecimal::BigDecimal;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let calculator = GstCalculator::new(false); // intra-state
// Calculate GST for a service (18%)
let calculation = calculator.calculate_by_category(
BigDecimal::from(10000),
GstCategory::Higher,
None,
)?;
println!("Base Amount: โน{}", calculation.base_amount);
println!("CGST (9%): โน{}", calculation.cgst_amount);
println!("SGST (9%): โน{}", calculation.sgst_amount);
println!("Total: โน{}", calculation.total_amount);
Ok(())
}
types
: Core data structures (Account, Transaction, Entry, etc.)traits
: Storage and validation abstractionsledger
: Account management and transaction processingtax
: GST calculation engineutils
: Utilities including in-memory storage for testingThe library uses trait-based storage abstraction, allowing you to implement your own storage backend:
use accounting_core::{LedgerStorage, Account, Transaction};
use async_trait::async_trait;
#[derive(Debug)]
pub struct MyPostgresStorage {
pool: sqlx::PgPool,
}
#[async_trait]
impl LedgerStorage for MyPostgresStorage {
async fn save_account(&mut self, account: &Account) -> LedgerResult<()> {
// Your PostgreSQL implementation
todo!()
}
// Implement other required methods...
}
Run the examples to see the library in action:
# Basic ledger operations
cargo run --example basic_ledger
# GST calculation examples
cargo run --example gst_calculations
Run the test suite:
cargo test
This library follows standard accounting principles:
The library supports Indian GST with:
Generate standard financial reports:
Comprehensive validation ensures data integrity:
Licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.