Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Business Logic Decisions
The living log of where rules go and why — the companion to business-logic-patterns.md (the placement guide) the same way ui-decisions.md companions the generative renderers. Because the primitives are shared, a placement decision here is not a per-module choice — it applies to every module at once, and an inconsistent placement is a bug, not a style preference.
Format per decision: Decision · Rationale · Applies to · Status.
Decided
1. Stamp point-in-time facts; derive live facts.
- Decision: A value that is a fact about a moment (the tax rate an
invoice was issued under, the price a line was sold at, the owner who created a record) is stamped into the record at write time — by the server or a pre-write hook — and never recomputed from today's reference data. A value that should always reflect current stored state (an invoice total, a payment balance, a full name) is derived by a formula/rollup and recomputes when inputs change.
- Rationale: Reference data changes; history must not. Deriving
yesterday's invoice tax from today's rate table silently rewrites the past — the classic sales-tax bug. Conversely, stamping a total that should track its lines guarantees drift. The question "moment-fact or live-fact?" decides stamp vs derive every time.
- Applies to: tax rates, sold-at prices, FX rates on transaction dates,
ownership; vs. totals, balances, counts, display names.
- Status: doctrine. First stamping precedent: server-side
owner_id;
first derivation adopters: fin_journals totals, contacts.full_name.
2. Time-driven state belongs to the daemon; never to read-time checks.
- Decision: When the passage of time changes a record's meaning (an
invoice becomes overdue, a task becomes stale, an approval expires), a daemon scheduled pass makes the transition through the ordinary write/transition machinery — the state is stored. No surface ever computes "is it overdue?" at read time.
- Rationale: Nothing writes when time passes, so materialize-on-write
can't see it — and read-time checks multiply into disagreeing copies (list says overdue, report says current). A stored transition is permission- checked, transition-guarded, realtime-pushed, notify-able, and audited — one truth for every surface. The daemon's after_hours auto-transitions already established the pattern.
- Applies to: aging/overdue states, expiries, escalation steps, SLA
timers.
- Status: doctrine; aging/dunning are the next adopters (need the
payments collection first). Not an expiry: a lapsed hold. An unpaid checkout's claim on a pickup place (object_pickup) and on stock (object_reservations, 2026-11-30) lapses by time and is DERIVED, not swept: nothing about the order changes meaning when its hold lapses (it is still a draft with a live pay link), so there is no state to store, only a count (#1); and a release that depended on the scheduler would never happen on a stock install. Both ask one function, object_pickup.hold_lapsed, so a window and a shelf cannot disagree.
3. Money never mutates; it moves.
- Decision: Corrections to money (and inventory) are **new, append-only
compensating records — a refund pointing at its payment, a reversing journal, a stock move — never edits to the original. Invariants on the movement ("refund ≤ payment − prior refunds", "journal balances") are pre-write hooks; displayed positions ("refunded_cents", "on-hand") are rollups**.
- Rationale: Auditability is structural, not procedural: if the original
can't change, the history is the ledger. Every mature money system converges here (double-entry is 700 years of this doctrine); systems that edit payment rows in place cannot answer "was this refund correctly credited?" because the question has no record to point at.
- Applies to: payments/refunds, journals (posted = immutable + reversals),
stock_moves; storage: append is the substrate.
- Status: doctrine, and since the 2026-11-28 gate review enforced rather
than described. Until then every ledger here said "never edited" in its description while its permission rule granted the owner update and delete and its hook gated create only: a payment was raised past its invoice by a PUT, a refund deleted and issued again, a stock move edited negative, a posted journal re-dated. Now: a posted journal is frozen for everyone by schema locked_when; payments, refunds and stock_moves are frozen by their hooks for anybody who is not an admin (a payment keeps status and notes, a refund keeps reason, a stock move keeps nothing), deletes included, and an admin's repair passes the same invariants as a create. The ceilings hold for every writer, whoever it is and whatever moves underneath: they are schema locked_checks that object_records runs inside the write lock, holding the ledger lock every write to payments, refunds, invoices, invoice lines and settings takes (validation-and-logic.md, "Locked checks"). (v3's per-parent sequence numbers covered hooked writers only and are retired.) That admin exception is a decision awaiting its owner, taken conservatively: whether recorded money may ever be edited or deleted at all, and by whom, is not settled. The permission rules still grant update and delete: the owner needs update for what stays editable, and a gate in the hook holds on every box whatever its policy says. Withdrawing the grants as well is left for when that decision is made.
4. Extract the primitive after the pattern repeats — never before.
- Decision: New business logic is first written concretely in the
cheapest correct primitive for that one module — usually a hook (three lines of real code) or a plain object. Only after substantially the same shape appears in two or three real modules is it promoted to a declarative schema key, and the concrete versions are then deleted onto it.
- Rationale: This is how every good layer here was actually built: four
hand-rolled comment tables → capabilities.comments; eight bespoke view pages → one detail renderer; one balance rule → the hook primitive; the hook's repeated shapes → formulas and rollups. The graveyard of "business operating systems" is full of the opposite order: a workflow/rules engine designed first, with reality forced through it — and the first rule that doesn't fit becomes the wall. An abstraction extracted from three working instances fits by construction. (UI precedent: ui-decisions #10.)
- Applies to: every "should this be declarative?" debate. The hook is the
staging area; schema keys are the graduation.
- Status: doctrine — the house method, now named.
5. State freezes fields — in hooks now, a schema key when it repeats.
- Decision: "A posted invoice's amounts are immutable" (and every
rule of the shape fields X are locked when status = Y) is expressed in each module's pre-write hook for now: reject when existing.status is in the frozen set and changes touches a locked field. When the third module writes that same hook, promote it to a declarative field/schema key (working name locked_when) and delete the hooks onto it, per #4.
- Rationale: It's clearly a repeating shape, but guessing the declarative
form before seeing real instances is how bad keys get designed — does it lock per-field or per-schema? Does admin bypass? Does it compose with transitions? The hooks will tell us.
- Applies to: posted journals/invoices, completed orders, archived
records.
- Status: the key exists: schema
locked_when
(validation-and-logic.md). The third hook arrived (time logs, expenses, scans each carry an allow-list), and a review found what all three share: none ran on delete, and each reads the record before the write lock, so an edit overlapping an approval lands on the approved row. What the hooks told us: it locks per record with an allow-list of fields that may still change (so a field added later is frozen by default); nobody bypasses it; it leaves the state field to transitions. Two schemas declare it: fin_journals (posted: nothing editable, terminal — no hook ever froze a posted journal, so this is new enforcement, not a move) and time_logs (approved/billed, with the hook's own allow-list; the hook keeps its copy for the message a person reads, and a test holds the two together). expenses and scans still carry the rule in their hooks only, with the same delete and overlap gaps.
6. Gates before the write; reactions after — never crossed.
- Decision: A pre-write hook may reject or stamp but never notify, email,
or call external systems. Notifications and side effects run after the write via notify_rules / trigger objects / connectors, and never block or undo it.
- Rationale: A gate with side effects leaks that a denied write was
attempted, couples save latency to SMTP, and can half-happen. A reaction that gates would mean the write's fate depends on a mail server. The two postures also fail differently by design: gates fail closed (a broken gate rejects), reactions and derived values fail soft (a broken formula stores empty; a failed notify retries).
- Applies to: every hook, every notify rule, every connector.
- Status: doctrine (established in
event-hooks-decisions.md; restated here as the load-bearing boundary of the whole map).
7. Generated documents carry provenance and face the same gates.
- Decision: Every machine-composed record (a journal from a payment, a
reversal, a recurring adjusting entry) stamps generated_from with its source ("payments/{id}", "reversal:{id}", "fin_recurring/{id}:{period}"), composers check that stamp before composing (replays are no-ops), and a generated entry passes the same balance verification a human entry would — composers re-verify because storage-layer writes bypass the HTTP-only hook.
- Rationale: Idempotency by provenance makes event redelivery, daemon
restarts, and manual re-runs safe by construction — no dedup tables, no distributed locks; the ledger itself remembers what was generated. And a machine allowed to skip the gates would make generated books less trustworthy than hand-kept ones — the opposite of the point.
- Applies to: system_books composers, action_reverse_journal,
fin_recurring_runner; every future composer.
- Status: doctrine, shipped with the books spine.
8. Independent evidence is never edited to agree with our records
- Decision: Records authored by an outside party — imported bank
statement lines today, provider payout feeds and scanned documents next — are stored append-only with the original text preserved verbatim, and their factual fields are immutable after the write. What an operator may add is their own work about that evidence: what it matched, how it was resolved, a correction recorded as a new record. Corrections to the evidence itself come from re-importing a corrected file.
- Rationale: The reason comparing our books to a bank statement is the
strongest practical control is that the bank's copy was written by someone with no stake in our numbers. The moment a line can be edited, that independence evaporates and the check becomes self-certification — reconciliation degenerates into making the two sides match rather than explaining why they differ. This is also why the act of reconciling is an ordinary attributed update rather than a silent background match: reconciliation performed invisibly by the same hands that move the money is the classic embezzlement pattern, and an attributed change log makes who-decided-what structural instead of procedural.
- Applies to:
bank_lines(hook-enforced immutability of
posted_on/amount/description/raw/identity fields), imported statement provenance (bank_statement_imports); the same posture is required of scanned-document intake and provider payout imports when they land.
- Corollary — a check that cannot run must say so: an import records
which self-checks ran, not only which passed, so a statement that carried no balances never reads as trustworthy as one whose arithmetic was verified. Silent skipping is how controls rot.
- Status: doctrine, shipped with bank import.
9. Reactions belong to the write path; storage-level writers must say so
- Decision: Event handlers dispatch on the HTTP write path only. An
object that writes through object_records directly (a runner, an action) does not trigger HANDLES reactions, so if such a write needs its reaction it must perform it explicitly — using the shared primitive with the same provenance marker the handler would have used, never a private copy of the logic.
- Rationale: Sharing the marker makes the two paths idempotent against
each other: whichever runs first wins, the other is a no-op. Copying the logic instead would fork the rule and guarantee eventual divergence.
- Instances so far (counting toward #4): (1)
action_apply_count
composes its own inventory-variance journal; (2) action_resolve_bank_line composes the NSF bounce reversal under payments/{id}:bounced, the marker system_books also uses.
- At the third instance, extract instead of working around: the real fix
is a daemon pass that dispatches handlers from the record-change log — the same shape process_notifications already uses to avoid depending on synchronous dispatch. Do not write a third workaround.
- Status: observed twice; extraction pending the third.
10. An amount is an integer in its denomination's smallest unit
- Decision: Money is stored as a whole number of the smallest unit of
its own denomination, and a denominations record declares what that unit is (USD scale 2, JPY scale 0, BTC scale 8, ETH scale 18, XAU scale 4). Floats never appear; Decimal is used only at the edges to convert human text to and from integers. Amounts in different denominations are never added — combining them requires converting through a rate stamped at the transaction moment (#1), which is a deliberate act.
- Rationale: This is the generalization of the founding "money is
integer cents" rule rather than a replacement for it — cents were always USD minor units. A business holds value in several denominations at once (a bank balance, bitcoin, a stablecoin, a box of cash, gift cards, maybe a weight of metal), and they divide differently. The alternative — a per-denomination decimal_places field beside one fixed-scale decimal column — is what the predecessor system did, and it lets a schema declare more precision than it can hold: the first 18-decimal asset truncates silently, while every ordinary dollar carries six meaningless digits where rounding dust collects. Integer minor units are exact by construction, have no ceiling (Python ints are unbounded), and are what payment processors and chains already use.
- Corollary — rounding is a decision, not a parse. Converting text that
does not fit the scale (0.005 USD) raises; a caller that genuinely wants rounding calls quantize_minor and says so. Half a cent silently becoming a cent is how a per-row error turns into a real number at scale.
- Applies to:
object_money.py, thedenominationscollection; new
value-bearing collections use *_minor + a denomination. Existing USD-only collections keep *_cents, which is honest for them — a big-bang rename buys nothing.
- Status: doctrine, shipped with denominations; the value-account layer
it founds is specified in plan/value-accounts-and-denominations-spec.md.
The owner's money decisions (2026-11-30)
Accepted from research article a614eae0. Each is built where it lands; the code names the decision.
11. An issued invoice's total never changes; status follows the money
- Decision: A debt is cancelled only by a credit note. "Refund this
sale" is a credit note plus a refund, and the invoice reads refunded with nothing due. A refund alone, a bounce or a deleted payment reopens the invoice and dunning resumes. The status is read off received, refunded and credited (object_corrections.money_status): paid, partial, sent/overdue, credit_owed (the shop owes the customer), refunded, credited.
- Applies to: system_invoice_status, the aging pass, the overpayment
ceiling (credits count), app-counter's void (an issued line is credited, not restated) and correction (a refund is a credit note plus the money).
12. Tax is stamped per line at issue, once per rate group
- Decision: The rate is stamped on each line when the document is
issued; tax is computed once per rate group, half-up, the odd cent to the line with the largest remainder (object_lines.allocate_tax); never recalculated after issue (credit notes use the original rate). Orders store shipping and discount. Tax posts to Sales Tax Payable.
- Applies to: object_lines, checkout, invoice_totals (drafts only),
order_totals, the counter's void and credit notes, system_books.
13. Formulas count in exact integers
- Decision: Whole numbers are integers of any size; Decimal only for
division; a division into an integer formula rounds half-up; round() and floor() are available. Rollups sum exactly.
- Applies to: object_computed.
14. Subscriptions bill the base fee in advance, usage in arrears
- Decision: A period's base fee is billed when the period begins (the
invoice closing one period carries the next period's fee); its usage is billed when it closes. Cash basis recognises revenue on receipt; accrual posts what is billed in advance to Deferred Revenue and releases it monthly. Cancellation runs to the period's end; staff may instead end a subscription now with a pro-rata credit note. Usage is bucketed by when it occurred.
- Applies to: system_billing_runner, system_usage_rollup, system_books
(deferral), invoice_lines.service_start/service_end, action_subscription_credit_unused.
15. Roles: registered is a customer, manager is staff, the books are finance's
- Decision:
registered(signed in, no role) is a customer;
role:manager is staff. role:cashier and role:finance (the bookkeeper) are optional narrower presets; role:owner sits above all. The chart of accounts and the journals move off registered to role:finance and role:owner.
- Applies to:
object_permission_store.ROLE_PRESETS(labels only; a
preset grants nothing by being listed), app-finance's rules (the books' registered grants retracted, owner fallback off), the trial balance, statements and journal reversal (the whole books for a keeper).
16. Scrap and rebates are contra-COGS; a barter is a sale and a purchase
- Decision: Scrap proceeds and vendor rebates reduce cost of goods sold
(expense-type accounts with a credit balance), never income. A barter is a sale and a purchase, each at fair value, taxable, booked through a clearing account; what is left in clearing is what the two sides still owe each other.
- Applies to: action_record_contra_cogs, action_record_barter (keepers
only), the double-entry chart (Barter Clearing 1290, Scrap Sales 5010, Vendor Rebates 5020).
17. Interest Income 4910 and Bank Fees 5840; setup maps what it can
- Decision: The double-entry chart has Interest Income (4910) and Bank
Fees (5840), and account setup writes reconcile.journal.interest_account -- a fresh box reported "Books NOT READY" for banking with nothing to point it at. Setup maps every key an account in the chart answers (also fees, Sales Tax Payable, Deferred Revenue, Barter Clearing and the contra-COGS pair), only where the key is unset.
- Applies to: app-finance's site_setup_accounts.
Open: not settled by these decisions
Written down rather than invented; each refuses (fails closed) today.
- A basket discount on a void or a line correction. A promotion is
applied to the basket and rounded once. When one item comes off, does the discount shrink (pro rata by net? by the promotion's own rule, e.g. a minimum spend no longer met?) or stay whole? The void refuses where the sale carries a basket discount. A correction after payment still credits the line at its own price and stamped tax, which can give back more than the customer paid for that item; the invoice then reads credit_owed.
- Part of a line credited. A whole line is credited at exactly what it
was stamped with; part of a line at the original rate, rounded half-up on its own. Several part-credits of one line can differ by a cent from its stamped share. Whether the last part-credit should take the remainder is not decided.
- An order with document-level tax and no issued invoice. The share of
tax a line carried is recorded on the invoice line; an order whose tax was typed on the document and never invoiced has nowhere to read it, and its void still refuses.
- Late usage for a period already invoiced. Usage belongs to the period
it occurred in; an event folded after that period's bill went out would change a bill already sent. Whether it is billed on the next invoice, and against which period's allowance, is not decided: such events stay unrated and the rollup reports them (late_for_invoiced_period).
- A pro-rata credit on accrual books. The credit note for unused days
reverses revenue; the part of it that was still in Deferred Revenue (not yet released) is not separated, so until the period's release runs the books carry the credit against revenue while the deferral is released in full. Whether the credit should reverse Deferred Revenue first is not decided.
- Input tax on what a barter brings in. The sale side charges tax at
fair value; the purchase side is booked at fair value with no input tax, because whether the shop may reclaim tax on what it received depends on its jurisdiction and registration.
How to use this
- Placing a new rule? Walk
business-logic-patterns.md's flowchart; if the placement needed a judgment call, record it here.
- If two modules place the same kind of rule differently, that's a bug: pick
one, log it, and fix the outlier.
- Counting instances for #4: when you write the second concrete copy of a
shape, note it here so the third triggers extraction.