GitHub
Architecture

Architecture

This page is for maintainers. It describes how the code is layered after plan 26 (platform readiness), and where a new user interface would plug in.

Most of the logic is in ledgeline-core. It reads journals, edits them safely, and computes every report and view. ledgeline-server wraps it in an HTTP API. Each host reaches that API in its own way: a desktop window, a headless server, or an iOS app calling the router in-process. The Svelte app in web/ only displays what the API returns.

hosts      desktop (wry window)   headless (--server)   iOS (ledgeline-ffi, in-process)
              │                       │                        │
server     ledgeline-server: axum router, snapshots, AppState
              │   features: gui · watcher · external-tools
shell      ledgeline-shell: token + Host guard · CSP · SPA embed · AppDirs · recents · GUI boot
              │   features: gui
core       ledgeline-core: vault · parse/edit · reports · view · display · ui_prefs

Core: crates/ledgeline-core

It is a plain library with no platform cfgs, no clock reads in report code, no HTTP, and no knowledge of where files live.

AreaModulesWhat it owns
Storagevault/, pinned.rsThe Vault trait (VaultPath, Entry, Availability, Revision, VaultError). LocalVault wraps the pinned, symlink-refusing, fsync’d writes; MemVault is for tests and can simulate files that are not downloaded yet and edits made behind the editor’s back. Writes are conditional on a Revision, so an external change produces a conflict instead of being overwritten.
Readingparse.rs, dirscan.rs, hledger_conf.rs, journals.rsparse_journal_in(vault, main, …) resolves includes inside the vault and returns each source’s revision.
Writingedit.rs, periodic.rs, accounts.rs, aliases.rs, rules/, projections/serialize.rsSpan-splice edits that change only the bytes they mean to, verified by a re-parse before anything is written.
Reportsreports/Balance sheet, income statement, cash flow, net worth, budget and the budget summary (span totals, pace, health, labels), insights, subscriptions, holdings. Exact decimals throughout (Dec, MixedAmount).
Journal viewview/The windowed journal: filter, sort, search text, summary, charts, local checks, cash balances.
Classification and displayreports/account_types.rs, reports/account_class.rs, display.rsOne resolver for account types and terms (declared, else inferred), the sign rule for entered amounts (signed_entry: revenue is entered positive and written negative), and the number formatter the UI uses.
Projectionsprojections.rsThe what-if engine, the scenario model, and the section a scenario line belongs in (line_section).
UI preferencesui_prefs.rs, ui_prefs/ledgeline.rsThe settings-files data model (plan 38/39): per-key merge of ledgeline.toml [ui] over ui-prefs.toml over the defaults, save routing, the theme pin, edit_ledger_text. Generic over a Schema each app registers; theme and uiScale are common to all of them.

Pure functions that used to be in TypeScript were ported here, with golden fixtures captured from the TypeScript first. See fixtures/journal-view/, fixtures/journal-meta/, fixtures/display-format/, fixtures/budget-summary/ and fixtures/projections-signs/, and the *_golden.rs tests that read them.

Server: crates/ledgeline-server

The server is an axum Router over an AppState. Every host links the library, and main.rs is the desktop and headless binary.

Shell: crates/ledgeline-shell

This crate has the code that turns a router and a built SPA into a hardened local server in a desktop window. Ledgeline and the invoicer both use it. An app describes itself once in an AppIdentity (name, bundle id, its token variable, the SPA’s two window globals and the path its SPA is served under; Ledgeline’s is ledgeline::APP, whose SPA is the whole origin, /, and the invoicer’s is under /app/).

Hosts

The web app

web/ is a SvelteKit SPA. Since plan 26 it requires the native API and holds no journal-sized data. The Journal tab reads windows of rows, the budget bars come with their pace and verdicts, and a projection line is sent signed as the file writes it, which the engine writes unchanged. The TypeScript that remains handles presentation: layout, formatting with the engine’s styles, chart and bar geometry, and form state. A component may still preview something while the user types (for example, whether a projection rule’s postings balance on their own), but once the engine’s answer arrives, it replaces the preview.

Native mode (the iOS app)

The iOS app shows the same SPA bundle with its own navigation bar in place of the HTML header. Its document-start script sets window.__LEDGELINE_NATIVE__ = {platform, idiom, version} and the ll-native class on <html>; isNative() in packages/ui/src/native/ (the UI package web/ shares with the invoicer) reads either. Every native-only path is gated on it, so the desktop app and a browser behave as before. The contract is in plans/42-mobile-app.md.

Two related changes depend on the device, not on native mode, so they apply in any browser too. Keyboard hints (<kbd> and “(v)” suffixes in tooltips, through hint() in packages/ui/src/keys/hint.svelte.ts) hide when there is no fine pointer (any-pointer: fine), and the journal’s calendar is not offered below the md breakpoint. There is no toggle and no v, and a cal=1 link shows its month as the list.

The invoicer: invoicer/

Ledgeline Invoicer is under invoicer/ in the same Cargo and bun workspaces, so it can move out later. Its design is in invoicer/ARCHITECTURE.md and its build order in invoicer/PLAN.md.

Invoicer code layout has the details.

Adding a native UI

A native desktop UI (egui, GPUI) or a SwiftUI app can connect in two ways:

  1. Link core directly. Parse through a vault, call the report and view functions, and draw the results. This is the fastest path (the native spikes put rows on screen in well under a second at 200k transactions) and needs nothing from the server. Writes go through the same core editors, so the conditional-write guarantee holds.
  2. Call the router in-process. Build an AppState and send requests to the router without a socket, as ledgeline-ffi does. This reuses every route’s validation, caching and JSON shape, which is quicker if a UI already uses the API.

Either way, nothing in core needs to change, and new domain logic belongs in core rather than in a UI.

Deferred until a UI is chosen (plan 26): a view-model crate that shapes report rows for display, server-side xlsx export, and protocols for the edit and import forms.