The hard part of an internal tool isn't moving spreadsheets onto the web. It's folding business rules, edge cases and human forgetfulness into one verifiable order.
This is the build log of DormHub, a dormitory management system: brand redesign, financial-rule rewrite, two audit rounds, an embedded digital-twin wall, and finally an offline package that can be dropped onto a FnOS NAS. It isn't a launch announcement — it's a note on which traps were real and how we closed them.
1. It was never just a dormitory spreadsheet
The initial brief sounded simple: put housing data online and stop passing Excel files around. In reality it was four businesses at once — property assets, the full move-in lifecycle, maintenance work orders, and billing — plus two governance layers: security/compliance and integrations. There are four kinds of users (admin, dorm manager, finance, resident), each with different fields and permissions.
We chose a stack that could stay offline and stay maintainable: React 18, Vite 5, TypeScript and Tailwind on the front end; a plain Node ESM backend using node:http, node:crypto, node:fs and node:sqlite, with no heavyweight framework. Auth is JWT plus scrypt hashes, with role and operation-code checks. The whole thing needs only a Node runtime and a data file — ideal for a NAS.
Most of the UI work went into information density rather than decoration. On the resident table, filters, bulk actions, fee status and contract expiry share one field of view; the default is a compact 10-row page that stays readable.
2. The hardest part was money: splitting ¥80 without losing a cent
Pick one module that must never be wrong, and it's billing. The rules look simple; the edge cases aren't:
- Rent is ¥80 per room per month, split by actual occupants: one person pays ¥80, four pay ¥20 each.
- Three people cannot each be charged 26.67 — that sums to ¥80.01. We split integer cents exactly: 27 / 27 / 26, remainder to the last person, total conserved.
- Water, electricity and heating are billed separately. A legacy
utilityfield is kept for display compatibility but never added twice. - Mid-month arrivals and departures are prorated: rent, property, network and non-metered heating follow actual days; meter-based utilities and penalties do not; unused days are not redistributed to roommates.
- On a room transfer, the regional subsidy must follow the destination room, so
parkNameis refreshed in both transfer paths. - Subsidies first offset rent — but never more than rent. Any remainder is allocated proportionally across other categories; otherwise the rent line goes negative and the report looks broken.
| Rule | Treatment | Why |
|---|---|---|
| Rent split | Exact integer-cent split, remainder to last occupant | Total stays ¥80 for any headcount |
| Late fee | Capped at 30 chargeable days by default; true overdue days still recorded | Stops ¥10/day growing without limit |
| Subsidy | Proportional allocation with a cap; no negative category | Reports reconcile with net receivables |
| Fee status | Bills are the sole authority; resident feeStatus is a cache |
No "paid in the list, unpaid in the bill" |
| Meter readings | Store previous and current reading; reject reverse readings | Legacy usage-only entries remain valid |
None of this is hard-coded. The penalty cap (1–365 days), the proration switch and the vacancy-alert threshold live in system settings and take effect immediately. For an internal tool, welding business policy into source code means every finance tweak needs a release — and eventually nobody dares to change anything.
3. From "it runs" to "we dare deploy": two audit rounds
The first audit found six P1 issues plus a batch of P2s. A few worth remembering:
Old tokens survived a password change. Password changes now increment tokenEpoch; /api/me verifies the signature and the account's epoch, so old tokens die instantly. The change-password endpoint returns a fresh token and the client swaps its local session.
Client IP could be forged. X-Forwarded-For used to be trusted unconditionally. Now we trust the socket address by default, and only parse XFF right-to-left when a trusted-proxy flag is explicitly enabled.
Material deduction had a race. Work-order material use became two-phase: validate every item's inventory first, then deduct atomically and return per-materialId detail. Cancelled or closed orders can't be backfilled; a done order accepts one backfill only, and replays are rejected.
The deposit ledger was split. Paying a deposit creates and links a deposit record; checkout marks settledViaAdmission; refunds reject double payment and deduct unpaid bills.
The second round closed all seven deferred items and also fixed a prototype-key issue: export and report entities now use an own-key allowlist, so __proto__ returns 404 instead of a 500.
The verification chain was the most time-consuming part, and the most valuable:
| Stage | Result |
|---|---|
node --check + tsc --noEmit |
Pass |
| Vitest | 20 files / 159 tests |
| P1 e2e | 26/26 |
| Deferred-items e2e | 30/30 |
| Full e2e | 17 suites, zero failures |
| Real Chrome | Wall badge "live · HH:MM:SS", zero JS errors |
One run, Vitest skipped a file because of a temporary cache
EPERM; a rerun was fully green. Environment flakiness and a real regression are different things — conflating them is how you break working code.
4. The wall isn't "another page"
The digital-twin wall started as a separate /screen.html: 1920×1080, a factory floor plan redrawn as a futuristic campus aerial, with occupancy, room state, energy, access control, alerts and a live event feed around the edges. The integration request was explicit — don't open a separate page; put it inside the overview dashboard.
So it became an independent display region inside that page: a fixed 1920×1080 stage scaled with transform: scale() to fit its container, plus a fullscreen button, loading/failure states, iframe error fallback and retry. The dashboard's original KPIs and charts weren't simply deleted — they were merged into the wall's top strip for one unified view.
The data isn't a static screenshot. After login the wall polls /api/dashboard to refresh KPIs and the sync badge; without a token it falls back to a seed-data snapshot and says so explicitly in the corner rather than pretending to be live. That detail matters: a wall that lies is worse than no wall.
5. Onto the NAS: offline package and first login
The deliverable isn't source code but dormhub-fnnas.tar.gz: a portable Node runtime, the built frontend, screen.html, start scripts and documentation. Packaging excludes .db files, the initial-admin file, JWT secret and backups, so test state never reaches production.
On the FnOS NAS:
sha256sum -c dormhub-fnnas.tar.gz.sha256
tar -xzf dormhub-fnnas.tar.gz
cd dormhub-fnnas && bash fnnas.sh start
The first login uses the admin account with a random initial password printed by the startup script. A forced password change blocks all other actions until it's done; the old token is invalidated immediately and you must sign in again. It's mildly annoying, and it prevents the most common intranet accident: everyone sharing one initial password.
6. Rules I'd repeat
- Compute money in integer cents. Rounding in a split will lose a cent eventually, and always where you least want to explain it.
- One state, one authority. Fee status is derived from bills; payments write back to the cache; manual changes must also write a bill and an audit entry.
- Make policy configurable. Penalty caps, proration and alert thresholds are settings, so finance can change a rule without a release.
- Test the real path. Unit tests cover algorithms, e2e covers APIs and state machines, and finally a real Chrome session confirms the badge and numbers actually move.
- Audits aren't one-off. Every fix introduces new edges; roughly half the second round's deferred items were side effects of the first round's fixes.
The system now runs on a FnOS NAS at v1.37.0. It is far from perfect software, but every known issue has an owner, a test and a rollback path. For an internal tool, that matters more than having a long feature list.