Plan 001: Split expenses
- Spec:
specs/001-split-expenses/spec.md(withdesign.md) - Status: Approved
- Last updated: 2026-12-02
What you are approving
- The page is made of a few simple files, without framework or server. Amounts are computed in whole cents, and the number of payments is the minimum possible.
- Data stays in the browser; a page rule blocks every request outside and every external script.
- Test tools with exact versions (Node, Playwright 1.65.1, axe-core, ESLint 10.15.0): free, no account needed. One command,
npm run check, runs all the checks. They install in the project folder and the test browsers’ folder, and do not touch the rest of the computer. - Two checks stay with you, because the automatic ones cannot do them: trying the page on a real phone, and a pass with a screen reader (see Sections 8 and 11).
- Known risk: speed on the phone is only roughly measured on the computer. Where to publish is still to be decided (D2) and is not needed for this plan.
1. Summary
The page is plain HTML, CSS and ES modules, served as static files. A pure calculation module (money in integer cents, validation, equal split with remainder rule, balances, exact minimum payments) has no knowledge of the screen and is tested alone. A storage module saves one versioned record in the browser and validates it fully on load. The interface module writes names and descriptions only as text. A strict content policy in the page forbids external scripts and every network request. Quality is enforced by one local command that runs lint, unit tests, end-to-end tests in Chromium and WebKit, accessibility checks and the dependency audit.
2. Constitution check
| Rule | Compliance / note |
|---|---|
| C1 Spec is source of truth | Every mechanism cites R/AC; nothing beyond the spec is added. Proposed UI details are in the approved design. |
| C2 Human approval gates | Gate respected: no later step before human approval |
| C3 Do not invent requirements | Decisions below were confirmed by the human on 2026-12-02; interpretations are listed in the report. |
| C4 Traceability | Section 8 maps all 37 criteria to a test. |
| C5 Tests | see Section 8 |
| C6 Security & privacy | see Section 7 |
| C7 Accessibility | WCAG 2.2 AA through design, automated axe check and a keyboard-only end-to-end test (AC35). |
| C8 Simplicity / dependencies | see Section 10: no framework, no runtime dependency; four development tools. |
| C9 Small verifiable increments | Section 9 planned steps each leave npm run check green. |
| C10 Architectural decisions | see Section 4 |
| C11 Specs stay alive | Spec and design were updated together (R30); no other spec exists. |
| C12 Language | Identifiers and plan in English; Italian text only in the text catalogue. |
| C13 Brevity | Sections that do not apply say N/A. |
| C14 Independent verification | verify after the last task |
3. Technical context
- Touched areas: new project:
index.html,src/(modules),styles.css,tests/,scripts/,project/design-system.md. - Existing code/modules reused: none.
- Constraints: profile Sections 4-8 (no server, Chromium and WebKit in the gate, 360 px first, 3 s load target), web module W1-W11, no
latesttags. -
Tools and runtimes on the machine (verified 2026-12-02):
Tool Needed version Verification command Node.js 22.13 or newer (installed 22.23.5) node --versionnpm 10 or newer (installed 10.9.9) npm --versiongit any (installed 2.54.0) git --versionChromium and WebKit test browsers installed by Playwright 1.65.1 into the user’s cache (no account, no payment, no administrator rights) npx playwright --versionand the first end-to-end run
4. Decisions
Decision: Code structure
- Context: one screen, no server, quality gates must be checkable (D1), calculation must be testable without a screen.
- Options: A) plain HTML, CSS and ES modules, no build step. B) the same with a bundler. C) a framework.
- Decision: A. Files:
index.html,styles.css,src/money.js,src/rules.js(validation),src/split.js(shares, balances, payments),src/storage.js,src/messages.it.js(text catalogue),src/ui/*.js,src/main.js. (Verified: Node 22 and current browsers run ES modules natively.) - Consequences: no production build exists, so profile gate 5 has nothing to run (recorded in Section 12). Test code and page code share the same modules.
Decision: Money as integer cents
- Context: R9, R11, R15: exact totals.
- Options: A) integer cents. B) decimal numbers.
- Decision: A. The amount text is parsed with a strict pattern (digits, one optional comma or dot, one or two decimals; no thousands separators) straight to cents, without decimal arithmetic. Shown with the platform’s number formatting (verified on 2026-12-02:
Intl.NumberFormat('it-IT', EUR)gives “12,50 €” and “99.999,99 €”, with a non-breaking space before €). - Consequences: a sum never drifts; “1.000,50” is rejected (ambiguous), listed as an interpretation.
Decision: Exact minimum number of payments
- Context: R16, AC22, AC23. Fewest payments equals the number of people with a non-zero balance minus the largest number of groups that settle among themselves.
- Options: A) exact search over groups of people (at most 12 people, so at most 4,096 combinations). B) greedy pairing largest creditor with largest debtor: simpler, not always minimal (AC22 shows it can give 3 instead of 2). C) a library.
- Decision: A. Dynamic programming over the subsets of people with a non-zero balance finds the largest number of disjoint subsets whose balances sum to zero; inside each group, creditors and debtors are paired greedily, which uses at most (group size − 1) payments. Ties are broken by the order of people so the output is always the same.
- Consequences: about 50,000 operations at the maximum; no measurable cost. Tested with fixed examples and a seeded random property test (AC23).
Decision: Storage in the browser
- Context: R19-R21, profile Section 8.
- Options: A) one entry in the page’s local storage with a version number. B) IndexedDB. C) cookies.
- Decision: A. Record:
{version: 1, nextId, people: [{id, name}], expenses: [{id, description, amountCents, payerId, sharerIds}]}. Saved after every change. On load the whole record goes through the same rules as new input (R2-R4, R8-R12, R30 and links to existing people); any failure rejects the whole record (R20). A failed or refused write is caught and shows the notice (R21). - Consequences: about 5 MB limit per site is far above 500 expenses; clearing the browser’s site data erases it (accepted risk, profile Section 8). Not shared between browsers or phones.
Decision: Safe rendering and page policy
- Context: R25, R29, W9, C6.
- Options: A) names written with text-only methods (never as markup) plus a content policy in the page that allows only same-origin scripts and styles and no network connections. B) a sanitising library.
- Decision: A. No inline scripts or styles; no external fonts, images or analytics. The policy goes in a
<meta>tag now; the same policy plus the headers a tag cannot set (framing, referrer, content-type) are set at hosting time (D2). - Consequences: a test asserts no request leaves the page (AC36) and that markup in names shows literally (AC32). Until D2, the page cannot forbid being framed by other sites; recorded as open item in Section 13.
Decision: Test and check tools (D1)
- Context: profile gates 1-8, Chromium and WebKit, one local command, no CI. Release-age rule applied: Playwright 1.65.2 (2026-12-01) and ESLint 10.16.0 (2026-11-27) are under 7 days old, so the previous stable ones are used (verified in the npm registry on 2026-12-02).
- Options: A) Node’s built-in test runner for the calculation + Playwright for end-to-end and axe-core for accessibility + ESLint +
npm audit. B) Vitest for the calculation. C) Cypress. - Decision: A, exact versions:
@playwright/test1.65.1,@axe-core/playwright4.14.1,eslint10.15.0,@eslint/js10.0.1. Peer requirements checked:@eslint/jsneedseslint ^10,@axe-core/playwrightneedsplaywright-core >= 1.0.0, ESLint needs Node^22.13(installed 22.23.5). Release notes of Playwright 1.65 were read only through third-party summaries and the partly visible official page; no change affecting plain use was found. - Consequences: only four development packages; none reaches the page. A small own script
scripts/serve.js(about 20 lines, Node only) serves the files to the tests; it listens on the local address only.
Decision: Design system as a task
- Context: profile Section 7, no
project/design-system.mdyet. - Decision: a task creates it (tokens in CSS custom properties: colours, spacing, type sizes, radii, motion; light and dark values; the components of design Section 4). The page uses only those tokens (W3). Proposal, approved with this plan.
- Consequences: the
design-systemplaybook is not run (still unproven); the file is written inside a task, as in the BuddySplit trial recorded in the web module.
5. Data model
- Person:
id(positive integer, never reused within a record),name(trimmed, 1-30 visible characters, unique ignoring case and accents). Position in the list = order of people. - Expense:
id,description(trimmed, 1-60 visible characters),amountCents(integer, 1 to 9,999,999),payerId(an existing person),sharerIds(non-empty set of existing people). Position in the list = order of creation; the screen shows it newest first (design). - Record: at most 12 people and 500 expenses. Names are compared after removing accents (decomposition and removal of combining marks) and lower-casing with the Italian locale (verified in Node 22.23.5); length is counted in visible characters with the platform’s text segmentation (verified in Node 22.23.5; in WebKit by the end-to-end test of AC3).
- Ownership: the user’s browser owns the record. No migration yet:
versionis 1; an unknown version is treated as unreadable (R20).
6. Interfaces and contracts
No network interfaces. Internal modules (each is covered by unit tests):
| Interface | Purpose | Input → Output / errors | Auth | Covers | |———–|———|————————–|——|——–| | parseAmount(text) | text to cents | text → cents, or error code (empty, invalid, tooBig, zero) | N/A | R9 | | formatAmount(cents) | cents to “12,50 €” | cents → text | N/A | R26 | | validateName(text, people) | name rules | → trimmed name, or error code (empty, tooLong, duplicate, limit) | N/A | R2-R4 | | validateExpense(input, people, expenses) | expense rules | → expense, or errors by field (descEmpty, descTooLong, amountInvalid, amountTooBig, noPayer, noSharers, limit) | N/A | R7-R10, R12, R30 | | canRemovePerson(id, expenses) | removal rule | → yes / no (inUse) | N/A | R5, R6 | | splitExpense(expense, people) | shares in cents | → share per sharer; sum equals amount; leftover cents one each to the first sharers by order of people | N/A | R11 | | computeBalances(people, expenses) | balances | → balance per person; sum is 0 | N/A | R15 | | computePayments(balances) | minimal payments | → list of (from, to, cents), fewest possible, all cents > 0 | N/A | R16, R17 | | loadRecord() / saveRecord(record) | storage | load → valid record, empty, or unreadable; save → ok or refused | N/A | R19-R21 | | resetAll() | clear everything | → empty record saved | N/A | R22 | Error codes are English machine values; the interface maps them to the Italian catalogue keys of the design (Section 5 of design.md).
7. Security and privacy
Baseline: OWASP Top 10, applied to a page with no server, no accounts and no network use.
| Spec point | Mechanism | Test | |—|—|—| | R25 untrusted text | Text-only writing in every place a name or description is shown, in lists, panels and announcements; no markup assembly from user text anywhere; error messages are fixed catalogue strings that never contain input | AC32 (markup in name and description shown literally, no script runs, no error repeats it) | | R29 no data leaves | Content policy in the page: scripts, styles and images only from the same origin; no network connections; forms cannot submit anywhere; no analytics or third-party code (dependencies are development-only) | AC36 (no request after load); a test reads the policy and fails if it is loosened | | R20 untrusted stored data | Whole-record validation before any use; unknown version, extra or wrong-typed fields, broken links, duplicates and limit breaches all reject the record | AC27 with each kind of breakage | | Input limits | One set of rules used for new input and for stored data | AC2-AC5, AC9, AC10, AC16 | | Logging | Nothing is logged; no personal data in any message | review at verify; test asserts no console output during a full session | | Secrets | None exist | N/A | | Dependencies (W9) | Exact versions in the lock file; npm audit with no known high-severity issue in the quality command; development tools only | gate 6 | | Headers a tag cannot set (framing, referrer, content type) | Decided with D2; until then an open item | open item, Section 13 |
- Accepted risks: anyone with the phone sees the data (spec Section 7); data lost on clearing the browser.
8. Test strategy
Unit tests run with Node’s test runner on the pure modules (fast); end-to-end tests run in Chromium and WebKit through Playwright against scripts/serve.js. “Fails if” names an input that would break the test.
| AC | Level | Test description | |—-|——-|——————| | AC1 | e2e | Add “Anna” in an empty page; fails if the list stays empty. | | AC2 | unit + e2e | validateName(" Anna ") returns “Anna”; “” and “ “ give empty. | | AC3 | unit + e2e | 30 characters accepted, 31 tooLong; 30 accented letters and a letter plus separate combining accent count as visible characters (fails if bytes are counted); runs in WebKit too. | | AC4 | unit + e2e | With “Anna”: “anna”, “ANNA”, “Ánna” give duplicate; fails if the comparison ignores case or accents. | | AC5 | unit + e2e | 12 people; the 13th is rejected and the count stays 12. | | AC6 | unit + e2e | Remove an unused person; others’ balances unchanged. | | AC7 | unit + e2e | Person as payer, and as sharer only: both stay, message shown; fails if either case allows removal. | | AC8 | e2e | Three people, “Spesa” 30,00 paid by Anna shared by all: row appears with those values. | | AC9 | unit | “”, “ “ rejected; 60 characters accepted, 61 rejected. | | AC10 | unit | The listed inputs give: 12,50 / 12,50 / 12,00 accepted; “0”, “-5”, “abc”, “”, “12,505”, “100000” rejected; “99999,99” accepted. Fails on any mismatch. | | AC11 | unit + e2e | No sharer ticked: rejected, no expense added. | | AC12 | unit | 30,00 paid by Anna shared by Bruno and Carla: +3000, −1500, −1500. | | AC13 | unit | 1000 cents among Anna, Bruno, Carla in that order: 334, 333, 333; fails if the extra cent goes to the last. | | AC14 | unit | 1 cent among three: 1, 0, 0. | | AC15 | unit | 1000 between Bruno and Carla: 500, 500; 1001: 501, 500. | | AC16 | unit + e2e | 500 expenses (loaded from a prepared record), the 501st is rejected. | | AC17 | e2e | Edit all four fields; list and balances show only the new values. | | AC18 | e2e | Edit with amount “abc”: rejected; the expense keeps its old values. | | AC19 | e2e | Delete: with confirmation it goes and balances change; without, nothing changes. | | AC20 | unit | Seeded random sets (including awkward cents): sum of balances equals 0 every time. | | AC21 | unit | The listed case gives exactly Bruno→Anna 1000 and Carla→Anna 1000. | | AC22 | unit | Balances +3000, +2000, −3000, −2000 give exactly 2 payments; a greedy implementation would give 3. | | AC23 | unit | Seeded random sets with 12 people: applying all payments leaves every balance at 0; no payment of 0 or less; count never above the non-zero balances minus 1. | | AC24 | unit + e2e | No expenses, and expenses that cancel out: the “all even” message and no payment list. | | AC25 | e2e | After each add, edit, delete and removal the result area changes without reload; fails if a reload is needed. | | AC26 | e2e | Enter data, reload: same people, same order, same values. | | AC27 | unit + e2e | Unreadable text, unknown payer, 13 people, wrong version, wrong types: none is shown, message and offer shown; accepting leaves a working empty page. | | AC28 | e2e | Storage made to refuse writes: notice shown, adding and results still work. | | AC29 | e2e | Reset with confirmation: empty, also after reload; without confirmation nothing changes; the confirmation text says the data cannot be recovered. | | AC30 | e2e | Double tap on “Add” and on “Save”, and Enter twice: exactly one item; no “already exists” or “empty” message appears. | | AC31 | e2e | Invalid amount with other fields filled: message shown and all fields keep their values. | | AC32 | e2e | Name and description <b>x</b> and <img src=x onerror=...> appear literally; a flag set by the script would stay unset; no message repeats them. | | AC33 | unit + e2e | formatAmount gives “12,50 €” form; a scan of the rendered text in all states finds no text outside the catalogue and no English text. | | AC34 | e2e | No people: prompt to add the first person, no expense button; people but no expenses: prompt for the first expense. | | AC35 | e2e + automated accessibility | At 360 px: no horizontal scroll, controls at least 44×44 px, axe-core reports no violations on every state, full flow done with the keyboard only. Manual check by the human on a real phone (Section 11). | | AC36 | e2e | Record all requests during a full session; after load there is none; fails if any appears. | | AC37 | unit + e2e | No payer: rejected with the message, nothing added, values kept; editing cannot clear the payer. |
- Infrastructure: Node test runner for
tests/unit/; Playwright fortests/e2e/with Chromium and WebKit projects;scripts/serve.js; fixtures are prepared stored records. Everything comes from the packages in Section 4. - Performance (profile Section 4): an end-to-end test in Chromium, with CPU slowed fourfold and a slow-network profile, fails if the page is not usable within 3 seconds. This is an approximation of a mid-range phone, not proof (Section 11).
9. UI and UX
Follows design.md and, once created, project/design-system.md; not repeated here.
- Screens: main page, expense panel, confirmation dialogs, notices.
- States: empty, error and notices as in the design; loading is N/A and offline is N/A (spec Section 6).
- Text: every string comes from
src/messages.it.jswith the keys of design Section 5; a test finds no text outside it. - Accessibility: as in design Section 6; panel and dialogs trap and return focus; the result area is a polite live region.
- Double submit: after a successful submit the form ignores a repeated submit until the user types or moves focus again (AC30).
Planned steps (indicative; tasks may split them; each ends with npm run check green):
- Scaffolding:
package.jsonwith exact versions and lock file, lint config, test configs,scripts/serve.js,npm run check(lint, unit, e2e, audit), empty page that loads and a first passing test; Playwright browsers installed. - Text catalogue and money module (
parseAmount,formatAmount) with tests. - Rules and calculation modules with tests (AC2-AC5, AC9-AC15, AC20-AC24, AC37).
- Storage module with tests (AC26-AC28 at unit level).
- Design system file and base styles (one human review).
- People area and its end-to-end tests.
- Expense panel (add, edit, delete) and its tests.
- Result area, notices, reset and the remaining end-to-end tests (including no network and performance).
- Accessibility and policy pass; a short list of what only the human can check.
10. Dependencies
| Dependency | Why | Alternatives considered | |————|—–|————————-| | @playwright/test 1.65.1 | End-to-end tests in Chromium and WebKit (profile gate 2); actively maintained; development only; downloads browsers on install | Cypress (no WebKit), Vitest browser mode (younger) | | @axe-core/playwright 4.14.1 | Automated accessibility check (gate 3) inside the same tests | Manual checks only (weaker) | | eslint 10.15.0 and @eslint/js 10.0.1 | Lint (gate 4); nothing else in the project finds mistakes in code style and unused variables | None needed to run without; no linter would drop gate 4 | | Node built-in test runner | Unit tests without a package | Vitest 5.1.2 (extra dependency, not needed) | No runtime dependency reaches the page.
11. Risks and mitigations
| Risk | Likelihood / impact | Mitigation |
|---|---|---|
| Real iPhone and Android behaviour differs from the test browsers | Medium / medium | Human action at verify: open the page on a phone and run the main flow; recorded in the verification file |
| No keyboard-and-screen-reader pass by a person (web module: not yet proven) | Medium / medium | Automated axe plus keyboard test; the human does a short pass with the phone’s screen reader; gaps recorded in lessons.md |
| Firefox not tested | Low / low | Exception in profile Section 10 |
| Speed approximated on a computer | Medium / low | Small page, no dependencies; the human times it once on a phone |
| Playwright’s Firefox/WebKit start problems on this machine | Low / medium | WebKit is in the gate: if it fails to start, stop and report; never remove it silently |
| Browsers refuse local storage (private mode) | Medium / low | R21 notice, test with refused writes |
| Framing by other sites until hosting headers exist | Low / low | Decided with D2, open item |
12. Rollout and migration
- Rollout: publishing is a separate human-action task at release, after D2 is decided; no account is created before the human agrees.
- Migration: none; the record has
version: 1. - Profile gate 5 (production build): the project has no build step, so this gate has nothing to run; recorded here, not an exception.
- Rollback: previous files are in Git; a published page is replaced by publishing the previous commit.
13. Open questions
(none) Items that are not questions but remain: D2 (where to publish, with the headers a tag cannot set) is decided before the release task, not before the plan.
14. Approval
- Approved by: Luca Lanzano
- Date: 2026-12-02