GitHub
Invoicer code layout

Invoicer code layout

Ledgeline Invoicer is under invoicer/ in the same Cargo and bun workspaces as Ledgeline, so it can move to its own repository later. It shares Ledgeline’s version and release. The user manual for it is the Invoicer section.

The design documents are in the repository:

invoicer/
  crates/
    invoicer-core/        lib: documents, the bill table, booking, reconciliation, views
    ledgeline-invoicer/   bin: the CLI, the HTTP API, the desktop window, PDF export
  web/                    the SvelteKit SPA, served under /app
  fixtures/               accrual, cash and empty books folders for tests
packages/
  ui/                     themes, scale, components, keymap and API client shared with web/
crates/
  ledgeline-core/         the journal engine both apps book through
  ledgeline-shell/        the desktop and server shell both apps boot through

invoicer/crates/invoicer-core

This crate holds everything except UI and platform code. It follows the same rules as ledgeline-core: no globals, today passed in rather than read from the clock, all file access through a Ledgeline Vault, no platform cfg. All journal writes go through ledgeline-core (plan 45’s accrual::ops and its ExternalChange guard). The invoicer writes no journal text of its own.

ModuleHolds
tableThe bill-table engine: parse with spans, recognize columns and rows, compute, check, write back aligned. table::words is [invoicer.words].
bookingThe pure split of a computed table into one booking line per account and deferral.
frontmatterLossless frontmatter reading and the by-key editor behind set.
notesDiscovery of notes by type and tag, behind an API shaped like mbr’s Site.
doc, customers, catalog, snippets, templatesThe document types and their validation.
tera_scanA light scan of Tera tags: blocks, extends, the name line.
customer_edit, catalog_edit, snippet_edit, template_editThe library editors’ writes, shared by the API and the CLI.
numberingThe next number over the files and the books.
indexThe in-memory document index, refreshed incrementally.
draft, edit, editorCreating drafts, the CLI’s writes (new, set, recalc), and the app editor’s form and save.
sessionAn open books folder: vault, settings, journal styles, index.
settingsledgeline.toml [invoicer].
booksThe books bridge: send, re-book, void, deposits, cash-books Apply payment and its undo, recognition.
reconcileThe books’ payment state, the paid: mirror and the books-versus-files checks.
receivablesOpen items, aging, DSO and days to pay.
viewsThe serializable shapes the read commands and the API return, the dashboard among them.
problemWhat check reports.

Tests are in tests/ (accrual and cash books flows, goldens, proptests, the dashboard). The benches in benches/ run on a generated 5,000-invoice corpus, and just invoicer-bench-gate fails when one is slower than benches/baseline.json allows.

invoicer/crates/ledgeline-invoicer

This is the binary. main.rs parses the command line with clap, opens the books and prints the result. Each command is one invoicer-core call. human.rs formats the text output. The CLI reference documents every command.

Cargo features decide what is built:

BuildHas
default (gui)the CLI, the server, and the desktop window around it
--features serverthe CLI and the headless server (--server), no window
--no-default-featuresthe CLI alone: every command but pdf

The app, src/app/, is one axum server, headless or in-process behind the window, booted through ledgeline-shell as Ledgeline is:

PathServed by
/api/*the invoicer API (app::api and its route modules), bearer token required
/app/*the embedded SPA
/.ledgeline-invoicer/*export links and the preview page
everything elsembr’s router, unmodified, behind a session cookie

mbr is at the root so it needs no base path, and the SPA is under /app. app::watch follows file changes and runs the reconciler on every journal or markdown change. app::pdf and pdf.rs drive mbr’s PDF export through the shell’s event loop.

starters.rs embeds the starter templates and the invoice base from templates/ (classic.html, modern.html, classic-logo.html, modern-logo.html, _invoice_base.v1.html). The base’s comment header is its own documentation, mirrored for users on Templates. The fixtures carry a byte-identical copy of the base, which a test checks. app/preview.rs renders every preview with invoicer_preview: true in the note’s frontmatter (never saved), so a template can show something only in the app’s preview, such as the “Your logo” box in the “with logo” starters.

tests/cli.rs runs the CLI on copies of the fixtures under target/ and compares its JSON with tests/snapshots/. Those snapshots are worked examples of every --json shape.

invoicer/web

A SvelteKit SPA with paths.base = "/app", built to static files and embedded in the binary. just build-invoicer builds it, and build.rs mirrors the build into the crate, or writes a placeholder page when there is none.

packages/ui

The parts both SPAs import as #ui/…: themes, UI scale and container-query breakpoints, shared components such as DateInput, the API client and token, the native bridge, and the keymap engine in keys/ (chords, layers, the typing guard, the ? sheet). Each app keeps its own bindings and passes its section order to the keymap.

Fixtures

invoicer/fixtures/ holds three synthetic books folders, described in its README:

FolderBooks
accrual/Invoices 101–108 covering paid, partly paid, void, deposit, final, overdue and draft, on plan 45’s accrual books.
cash/Invoices 201–207 on cash books, with payments applied and a deposit income on receipt.
empty/A first day: [invoicer] set up, nothing billed yet.

Tests copy them before writing. Never point a write at the committed folders.

Recipes

RecipeDoes
just build-invoicerBuild the SPA into invoicer/web/build.
just invoicer-server JOURNALRun the headless server on port 5199, for vite dev on 4273. Use a copy of a fixture.
just invoicer-e2eBuild the SPA and the binary, then run the Playwright suite.
just invoicer-bench-gateRun the benches and compare them with the baseline.
just testThe vitest suites of web/, packages/ui and invoicer/web.

cargo test -p invoicer-core -p ledgeline-invoicer runs the Rust tests. CI lints invoicer/web with prettier and eslint like the other web folders.