npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@classytic/ledger

v0.12.3

Published

Production-grade double-entry accounting engine for MongoDB — schemas, reports, tax, multi-tenant

Readme

@classytic/ledger

Double-entry accounting engine for MongoDB. Integer-cents arithmetic, plugin-based, country-agnostic, multi-tenant. Framework-agnostic — works with Fastify, Express, Nest, or plain Mongoose.

Install

npm install @classytic/ledger @classytic/mongokit mongoose
npm install @classytic/ledger-bd   # Bangladesh (BFRS chart of accounts)

Quick Start

import mongoose from 'mongoose';
import { createAccountingEngine } from '@classytic/ledger';
import { bangladeshPack } from '@classytic/ledger-bd';

const engine = createAccountingEngine({
  mongoose: mongoose.connection,
  country: bangladeshPack,
  currency: 'BDT',
  multiTenant: { orgField: 'organizationId', orgRef: 'organization' },
});

// Seed chart of accounts for a branch
await engine.repositories.accounts.seedAccounts(orgId);

// Post a journal entry
const entry = await engine.repositories.journalEntries.create({
  journalType: 'GENERAL',
  date: new Date(),
  label: 'Office supplies',
  journalItems: [
    { account: expenseAccountId, debit: 500_00, credit: 0 },
    { account: cashAccountId, debit: 0, credit: 500_00 },
  ],
});
await engine.repositories.journalEntries.post(entry._id, orgId);

Multi-Currency (0.9.0+)

GL stays in base currency (BDT). Foreign currency is audit metadata.

const engine = createAccountingEngine({
  country: bangladeshPack,
  currency: 'BDT',
  multiCurrency: { enabled: true, currencies: ['USD', 'EUR', 'GBP'] },
  bridges: {
    exchangeRate: myRateBridge, // host-injected rate source
  },
});

// Post with foreign currency metadata
await engine.repositories.journalEntries.create({
  journalType: 'PURCHASES',
  date: new Date(),
  label: 'Import from China',
  journalItems: [
    {
      account: inventoryId,
      debit: 120_500_00,    // BDT (base currency, always)
      credit: 0,
      currency: 'USD',
      originalDebit: 1_000_00, // USD 1,000.00
      exchangeRate: 120.50,
    },
    { account: apId, debit: 0, credit: 120_500_00 },
  ],
});

Features

| Feature | What it does | |---------|-------------| | Double-entry | doubleEntryPlugin validates debit = credit on every post | | Integer cents | All amounts in minor units (paisa/cents). No float errors. | | Multi-tenant | organizationId scoping via mongokit plugin | | Multi-currency | Optional foreign currency fields + FX realization + revaluation | | Idempotency | idempotencyPlugin prevents duplicate postings | | Period locking | createLockPlugin blocks edits to closed periods | | Credit limits | creditLimitPlugin enforces per-partner credit caps | | Immutable guard | immutableGuardPlugin prevents posted entry edits | | Country packs | Pluggable chart of accounts (BD, CA, custom) |

Reports

import {
  generateTrialBalance,
  generateBalanceSheet,
  generateIncomeStatement,
  generateCashFlow,
  generateGeneralLedger,
  generateAgedBalance,
  generateBudgetVsActual,
  generatePartnerLedger,
  generateRevaluation,
} from '@classytic/ledger';

All reports accept { startDate, endDate, organizationId } and return typed result objects.

Bridges

All optional. All methods optional. Features degrade gracefully.

import type { ExchangeRateBridge, SourceBridge, NotificationBridge } from '@classytic/ledger';

const engine = createAccountingEngine({
  // ...
  bridges: {
    exchangeRate: myRateBridge,    // FX rate lookup
    source: mySourceBridge,        // resolve external doc refs
    notification: myNotifBridge,   // alert on reversals, period locks
  },
});

Source provenance — JournalEntry.sourceRef (0.13.0+)

Every JE carries a typed sourceRef: { sourceModel, sourceId, label?, kind? } slot for "what produced this whole JE". Per-line back-references live on journalItems[].sourceRef (settles which document) and journalItems[].linkedRefs[] (additional docs touched).

Add the index for fast source → JEs drill-down:

import { createAccountingEngine, ENTRY_SOURCE_INDEX } from '@classytic/ledger';

createAccountingEngine({
  schemaOptions: {
    journalEntry: { extraIndexes: [ENTRY_SOURCE_INDEX] },
  },
});

// After import — stamp the back-reference, then query by it.
await JE.updateMany({ _importRunId: docId }, { $set: { sourceRef: {
  sourceModel: 'SourceDocument', sourceId: docId,
  label: 'INV-2026-001 — Acme Corp', kind: 'xero-invoice',
}}});

// Drill-down. Include `sourceModel` in the predicate so the query
// planner reliably picks `sourceRef_idx` (the partial index only
// contains stamped docs; the planner prefers it when both fields are
// constrained). The sourceId-only form returns identical results but
// may COLLSCAN on small collections.
await JE.find({ 'sourceRef.sourceModel': 'SourceDocument', 'sourceRef.sourceId': docId });

Plugins

import {
  doubleEntryPlugin,
  idempotencyPlugin,
  creditLimitPlugin,
  fxRealizationPlugin,
  immutableGuardPlugin,
  createLockPlugin,
} from '@classytic/ledger';

Plugins attach to mongokit repository hooks. They run at POLICY priority before any query.

Subpath Exports

import { Money } from '@classytic/ledger/money';
import { CATEGORIES, CURRENCIES } from '@classytic/ledger/constants';
import { defineCountryPack } from '@classytic/ledger/country';
import { exportToCsv, quickbooksFieldMap } from '@classytic/ledger/exports';

Architecture

  • Repositories extend @classytic/mongokit Repository directly
  • No service layer — domain verbs live on the repository
  • No barrel re-exports — import from source paths
  • Events: arc-compatible DomainEvent / EventTransport shapes
  • Country packs: pluggable chart of accounts + journal type seeds
  • Tax: NOT in ledger. Use @classytic/bd-tax for Bangladesh tax calculations.

License

MIT