Repository navigation
Open
Labels
area:backendBackend (Express/SQLite)enhancementNew feature or requestpriority:normalNormal priority against the backlogstate:needs-designNeeds a design/scope decision before work startstype:designArchitecture/design decision needed before implementation
Milestone
Description
Problem
Legacy catalog and transactional columns (products.price, orders.total, bills.subtotal/tax_amount/total) are stored as SQLite REAL floats and manipulated with JS floating-point numbers in several older routes, creating drift risk across 0-decimal (JPY/KRW), 2-decimal (USD/INR), and 3-decimal (KWD/BHD/OMR) currencies. Per maintainer guidance, FloCafe does not need a disruptive big-bang rewrite of every table, but it does need a single canonical minor-unit Money helper and clear persistence/calculation boundary rules for all new and refactored financial services (#369, #364, #363, #1342).
Codebase Anchor
- Existing minor-unit & exact-decimal foundations:
main/countries.ts(getCurrencyFractionDigits,getCurrencyMinorUnitFactor- supports 0, 2, and 3 decimal currencies).shared/charges.ts:8-11,276-306(integer minor-unit calculation using tenant fraction digits).main/services/tax-engine.ts:10-144(Decimal.jswithROUND_HALF_UP/ROUND_HALF_EVEN/FLOOR/CEILING).main/services/refund.ts(refunds.amount_centsminor-unit storage perdocs/reference/product-invariants.md:278-283) andmain/routes/cash-sessions.ts/main/routes/cash-closures.ts(*_centsinteger columns).main/routes/bills.ts:96-99,175,548-556(inline minor-unit rounding and split remainder distribution).
Core Invariants & Constraints
- Currency precision agnosticism (
docs/reference/product-invariants.md:278-283): Never hardcode* 100; always derive factor (1,100,1000) fromgetCurrencyMinorUnitFactor(currency). - Data safety (Core Invariant fix(windows): add Express path-rewriting middleware for Next.js static exports #2): Legacy
REALcolumns on existing installs must stay backward-compatible across migrations without rounding distortion on historical bills.
Scope / Acceptance Criteria
- Extract a single shared minor-unit helper (
shared/money.ts) consolidatingtoMinorUnits,fromMinorUnits,roundMinor,percentageMinorUnits, and penny-safeallocateMinor(largest-remainder / proportional split) soshared/charges.ts,main/services/payment-tender.ts(#369), and frontend previews never duplicate rounding math. - Document the persistence boundary contract in
docs/architecture/: all new financial columns storeINTEGERminor units (named*_minoror*_centsper convention), while legacyREALcolumns convert at the service boundary viatoMinorUnits(..., factor)and round deterministically on write. - Add exhaustive rounding and penny-safe split tests across 0-, 2-, and 3-decimal currencies wired into
package.json.
Concrete Design Decisions to Lock Before Coding
- Rounding default: Confirm
ROUND_HALF_UPvsROUND_HALF_EVENoutside tax packs (tax packs already carry per-packRoundingMethod). - Legacy column migration: Confirm legacy
orders/billsREALcolumns stay as-is (boundary-converted) rather than adding dual shadow columns.
Out of Scope
- Migrating existing
products.price,orders.total, orbills.totalSQLite column types in place.
Metadata
Metadata
Assignees
Labels
area:backendBackend (Express/SQLite)enhancementNew feature or requestpriority:normalNormal priority against the backlogstate:needs-designNeeds a design/scope decision before work startstype:designArchitecture/design decision needed before implementation
Activity
khaira777 commentedon Aug 16, 2026
Verdict: VALID BUT NEEDS RESCOPING (architecture review warranted)
Findings:
main/db.ts:4015price REAL; order/bill totals:4166-4205REAL) and manipulated with JS numbers in places — the float-drift concern is real.half_even(main/services/tax-engine.ts:10,:117-118;main/tax-packs/types.ts:3RoundingMethod), and penny-safe split math with minor-unit rounding + remainder distribution already exists (main/routes/bills.ts:96-99,:175,:548-556).Suggested scope: don't replace every money path with a library in one change. Start with (a) minor-unit conversion at persistence/calculation boundaries (store cents as INTEGER or round at write via Decimal), (b) centralize rounding/split helpers by reusing the existing bills.ts math, (c) a reconciliation test. Maintainer decision needed on how far to take it (full library vs boundary-only). Related: #282 (tender service), #280 (REAL stock_quantity), #278.
itsbkm commentedon Sep 21, 2026
Checked current state: no main/core/money.ts exists yet, so this issue's scope is unchanged from when it was filed - still relevant as-is. Per the stabilization plan, narrowing to specifically the persistence/calculation boundary question (not a full monetary-type migration) is the recommended framing. Labeling type:design / state:needs-design.