Accounting

This example is double-entry books for one person, kept in a workspace app. The owner posts journal entries, imports bank statements, attaches receipts, and issues invoices. Their accountant reads the reports through a read-only share link. No runtime code knows about accounts, entries, or invoices. The rules live in this folder.

The books

schema.sql defines one Collection with eleven tables: accounts, fiscal_periods, journal_entries, journal_lines, bank_imports, reconciliations, business, clients, invoices, invoice_lines, and invoice_payments. Amounts are integers in the currency's smallest unit: cents for USD, yen for JPY, fils for KWD. Each line has a currency, and every report runs per currency. operations.js holds every operation. dataset.json declares them and who may call them.

The books keep these rules, in SQL triggers and in the operations:

Bank statements

Import statement in Bank reads a CSV file in the browser. You choose the date, description, and amount columns, or separate money-in and money-out columns. The app sends rows to stageBankRows in calls under 60 KiB. With the owner-only bulk profile, one call takes up to 5,000 rows. Each row is stored with a SHA-256 hash of its bank account, date, amount, currency, and description, with case and spacing ignored. The hash also counts the identical rows before it in the same file, so two real charges for the same amount on the same day both stay. A row whose hash is already in the books lands in Duplicates, and so does a row from another file with the same bank account, date, and amount, because banks often change the description between exports. Each earlier row holds back one new row, and an exact repeat claims its own earlier row first, so a second real charge for the same amount that day lands in Review whatever order the file lists them in. Importing the same or an overlapping file again adds nothing twice. Rows dated in a closed month land in Skipped, and stay there, except a row that repeats one already imported, by hash or by date and amount, which lands in Duplicates already confirmed. A duplicate stays out of the books. Its inspector shows the row imported before and whether it is in the books. Enter or Confirm duplicate keeps it on record and takes it off the to-do list, and Undo or Unconfirm brings it back. If they are two separate purchases, choose Keep as new to give the second row a fresh identity. A month can't be locked while a duplicate dated in it is unconfirmed, and a duplicate in a closed month can only be confirmed.

The bank workbench has five queues: Review, Suggested, Duplicates, Posted, and Skipped. A new row is in Suggested when the app is confident what it is, and in Review otherwise, so the counts add up.

Reconcile compares a statement's ending balance for one bank account on one date with what has cleared the bank by then. An entry matched to a statement row clears on the row's date, so a check written on January 28 that the bank paid on February 10 counts in February. An entry with no statement row clears on its own date if it is older than the account's first imported row (skipped rows don't count), and otherwise waits as not cleared until a row matches it. The sheet shows what the statement should show, up to 200 of the entries that make the difference (an entry and its reversal that both wait on the same side cancel out and are left off), and the books' balance. It opens on the last month-end before the first row still waiting, when that date isn't reconciled yet. It refuses while rows dated on or before that date wait in Review, Suggested, or Duplicates, refuses a balance that differs from what has cleared, and refuses a date that is already reconciled or in a closed month. The dialog offers each currency the account holds. The bank top bar shows the latest reconciliation, or the earliest one that no longer holds. It warns when entries posted or matched later changed what had cleared by that date, or when a statement row dated on or before it arrived later and waits in Review, Suggested, or Duplicates. Choose the warning to open that date, where Remove deletes the reconciliation so you can reconcile again. Removing one that no longer holds has no Undo, because it could not be saved again as it was. Undo in the toast removes a new reconciliation. A month can't be locked while a reconciliation dated in it or earlier no longer holds, and a reconciliation in a closed month can't be removed or changed.

Receipts

An entry can carry one receipt: a PDF, or a PNG, JPEG, WebP, GIF, or HEIC image. Other file types are refused. Attaching, replacing, or removing a receipt works in any period, including locked ones, because a receipt is evidence and not part of the amounts. Each change has Undo in its toast. receiptAccess returns the file to the owner only. An entry counts as missing a receipt when it was posted by hand or from the bank, has an expense line, and is not a reversal or reversed.

Invoices

The first invoice asks for your business name, email, and address, which every invoice then shows under From. Edit them from any invoice editor. Saving a draft saves a new client and your business details in the same step, so a failed save changes nothing. Issuing an invoice copies your business and the client's details onto it, so renaming either later doesn't change an invoice already sent. Record payment takes the full balance or any part of it. A part-paid invoice shows Part paid and what is still due. A payment can't be dated where it would overpay the invoice on any later day, for example before an earlier payment's reversal. An invoice with payments can't be voided until they are reversed, and the void is dated no earlier than the last payment or reversal. The invoice inspector links to its sale, each payment, and its void entry by number. Overdue lists every issued invoice past its due date, across all pages. Invoice numbers continue from the highest number issued.

Keys

KeyAction
NNew journal entry
CNew invoice on Invoices, new account on Accounts
G then O, R, B, I, A, F, POverview, Register, Bank, Invoices, Accounts, Reports, Periods
J, K, Enter, EscMove, open, and close in the register, bank, and invoice lists
/Search
Enter on a bank rowPost it, match it to the chosen entry, record the chosen invoice payment, or confirm a duplicate
A, S, I, FChoose the account for, split, skip, or find an older entry for a bank row
=Fill the difference on an amount field in the composer
EnterMove from an amount to the next line in the composer, adding one after the last
Ctrl+Enter (⌘+Enter on macOS)Post the entry or save the invoice
?Show every shortcut

Publishing

Copy this folder into a workspace as accounting. Approve its descriptor, schema, and operations.

The portal's grant lists only booksInfo, trialBalance, incomeStatement, balanceSheet, and accountLedger. These are the only operations that allow link callers, and all five are read-only. A link caller who sends any other operation is refused. Revoking the link ends access.

Reports are read-only operations, not SQL views, because the runtime refuses CREATE VIEW. Every report and invoice has a Download printable HTML button that exports a standalone file with a print stylesheet (dohc's app iframe sandbox omits allow-modals, so window.print() inside the frame is blocked).

Limits

These limits come from dohc, not from this example. The example works inside them.

LimitValueEffect here
Operation input64 KiB of JSON, or 1 MiB for the owner-only bulk profilepostJournalEntries and stageBankRows use the bulk profile and take up to 5,000 items. The app's own calls stay under 60 KiB.
JSON structure16,384 nodes, or 131,072 with the bulk profileBulk batches stay under it.
One query result1,000 rows, 256 KiBBank review pages hold up to 100 rows and end early once the rows reach 240 KiB, so a page of long descriptions with five candidate entries each stays under the limit; the register pages at 100 entries and the accountant ledger at 100 lines (max 500).
SQL parameters128 per statement, 256 KiB of JSON per statement, or 4 MiB with the bulk profileBulk inserts send rows as one JSON parameter, in chunks.
json_eachAllowedOperations still read JSON arrays with a recursive query, written before dohc allowed json_each.
App backend calls30 at once, then 1 every 2 seconds, per app sessionBank posting batches rows into one call, and undo reverses up to 100 entries in one call.

Tests