Load the browser workspace
app.js reads the V5 localStorage key, normalizes the saved state, attempts the V3 legacy migration when needed, then renders the landing screen or active workspace.
This page describes the code that exists today. It explains the application layers, browser data lifecycle, finance calculation, export behavior, quality checks and the limits of the current release.
Architecture boundary: Bachelor Finance Manager is a static, browser-only application. GitHub Pages serves the files; workspace data and financial calculations run in the user's browser. There is no backend, account system, server database or cloud synchronization.
The browser is the runtime boundary. The development-time test pipeline is separate and does not run when a visitor uses the app.
| Layer | Files / APIs | Responsibilities | Must not own |
|---|---|---|---|
| Presentation | index.html, styles.css | Landing screen, dashboard controls, forms, tables, reports, responsive and print styles | Financial calculations or data persistence rules |
| Application | app.js | App state, event delegation, validation, workspaces, migration, localStorage, filtering, rendering, import/export and print | Duplicating the settlement algorithm |
| Domain | src/domain/settlement.js | Paise arithmetic, allocation, paid/owed/net balances, transfer generation and result validation | DOM, browser storage, files or network access |
| Export serialization | src/infrastructure/csv.js | CSV quoting and spreadsheet-formula prefix neutralization | Downloading files or managing UI events |
| Browser platform | localStorage, FileReader, Blob, URL, print, confirm | Persistence, file reading/download, print dialog and confirmations | Server-side durability or identity |
Important implementation detail: storage is not yet extracted into its own adapter. The application layer calls localStorage directly. Likewise, app.js creates the CSV download; the CSV module only serializes rows.
app.js reads the V5 localStorage key, normalizes the saved state, attempts the V3 legacy migration when needed, then renders the landing screen or active workspace.
The form is normalized. Rupees are converted to integer paise, the date and payer are checked, and at least one workspace participant is required before saving.
Search, month and category filters produce the current expense set. That set feeds the settlement domain and the dashboard summaries.
The UI renders the ledger, category totals, payer contributions, balances and transfers. CSV exports filtered rows; JSON backs up the complete active workspace.
Money is stored as integer paise. For each expense, the payer is credited with the full amount, while the obligation is divided among the selected participants. The base share is the floor of amount divided by participant count; remaining paise are assigned one each to the first participants in the saved participant order.
Net = amount paid − share obligation. A positive result means the member should receive money; a negative result means the member should pay.
Debtors and creditors are sorted by balance, with member name as a deterministic tie-breaker. The engine repeatedly transfers the smaller outstanding balance.
Filter-aware totals: total spend, paid/owed balances, charts and suggested transfers all use the current filtered expense set. The “Average spend / member” KPI divides filtered spend by all members in the workspace; it is a reference figure only and does not influence settlement.
Money invariant: participant shares must sum to each expense amount, and all member net balances must sum to zero. The app does not execute payments; it only calculates suggested transfers.
One localStorage item holds schema version 5, activeWorkspaceId and a map of all saved workspaces for the current browser profile.
A workspace stores its ID, name, owner label, timestamps, ordered member-name list and expense list. Member names act as identifiers; there are no separate member IDs.
An expense stores its ID, date, payer name, category, description, integer amountMinor and participant-name array.
Paid, owed, net balances, category totals and transfer suggestions are derived in memory. Suggested payments are not stored as ledger entries.
The current schema and migration behavior are documented in the data model document.
| Operation | Scope | Behavior |
|---|---|---|
| localStorage | All browser workspaces | One versioned JSON state object under BFM_DATA_SESSION_V5 |
| CSV download | Active workspace, filtered expenses | Rows include date, payer, category, description, amount in INR and participants |
| JSON backup | Complete active workspace only | Includes workspace details, members and all its expenses plus backup metadata; not every workspace |
| JSON import | One imported workspace | Parsed and normalized in the browser, assigned a new ID and added without overwriting the existing workspace |
| Current visible report | Opens the browser print dialog and uses print-specific CSS |
CSV cells beginning with spreadsheet formula characters are prefixed before quoting. JSON backups may contain names and household spending details, so exported files should be kept private.
Import limitation: JSON import normalizes a workspace-shaped file rather than enforcing a signed or strict versioned schema. Newly submitted expense dates are calendar-validated; a non-empty date in a hand-edited import is currently passed through. Do not rely on the importer as a validator for untrusted financial records.
Workspace records remain in browser localStorage. It is not encrypted secure storage, and anyone using the same unlocked browser profile may be able to access the records.
The owner name is a label, not a login. The current version has no access roles, remote database, live multi-user editing or cloud backup.
Browser cleanup, profile loss or storage failure can remove data. JSON export is the user's recovery path; there is no server-side restore service.
Transfers are recommendations calculated from expense records. No bank connection, payment execution, receipt verification or settlement confirmation exists.
The project uses native browser JavaScript modules and has no runtime npm dependencies. Node.js 20+ runs the syntax checks and Node built-in tests. The GitHub Actions workflow runs these checks on pushes to main/refactor branches and pull requests targeting main.
Current automated tests focus on settlement invariants, participant splits, paise remainders, transfer validation, CSV quoting and spreadsheet-formula neutralization. They are not browser end-to-end tests. Responsive behavior, actual localStorage lifecycle, file picker/download and print output still require browser verification.
GitHub Pages serves static files; there is no compile/bundle stage, web server process or database deployment. The site.webmanifest is metadata only: the current repository does not include a service worker or offline cache implementation.
| Visible area | Implementation path |
|---|---|
| Landing, workspace form and saved workspace list | index.html + app.js workspace functions |
| Roommate list and add/remove | index.html forms + app.js member lifecycle |
| Expense form and ledger | index.html + app.js addExpense, filteredExpenses and renderExpenses |
| Search, period and category filters | app.js filteredExpenses and renderFilters |
| KPIs, charts and balances | app.js renderDashboard, renderCharts and renderBalances |
| Suggested transfers | src/domain/settlement.js computeSettlement + app.js renderTransfers |
| CSV download | src/infrastructure/csv.js + app.js exportCsv |
| JSON backup and restore | app.js exportJson and importJson |
| Print report | app.js window.print + styles.css print rules |