Architecture, stack, key decisions and the quality gates DEV3 Ambulora passed before release.
A calm hospital management system for long stays: an icon rail with a section panel, ward census cards, care plans and a family portal, in a compact layout built for 1920 px screens.
The problem it solves
Give rehabilitation and long-stay hospitals a self-hosted system built around weeks-long admissions (census, care plans, interim bills, family contact) while keeping every module a multi-branch hospital group runs.
Architecture and approach
Ambulora is one Next.js 16 application (the DEV3 hospital operations engine with its own design) with MongoDB, written in TypeScript. There is no separate API server and no native app. The design choices below are the ones that matter when you read or extend the code.
One group, many branches
Every record that belongs to a branch carries a branch id, and every read goes through a scope filter built from the signed-in user's role. Patients and employees are group-wide, so one MRN works across branches. Branch settings (currency, tax, timezone, numbering) override the group value and can be reset.
Roles and permissions
There are 21 built-in roles and custom roles. Each permission is a module and action with a scope: own, department, branch or all. Menus, buttons and server actions use the same check, and a role-menu snapshot is checked in the browser flows.
Money
Amounts are whole cents. Rounding is half-up in one place. Each invoice stores the currency rate it was created with, so later rate changes do not alter old bills. All charges go through one posting service, which prevents double posting with request keys.
Bed charges and bills
Bed-days follow a midnight census with a 12:00 discharge cut-off and half-day rule, all configurable by branch. A live bill is opened with the admission and receives charges from the bed, nursing, pharmacy, lab, OT and blood bank. The payer split (insurer and patient) is recomputed whenever a pre-authorisation is decided.
Safe under concurrency
The app does not need MongoDB transactions, so it runs on a single node. Writes that must not race use conditional single-document updates, unique and partial indexes and short named locks. Race tests run parallel requests against a real MongoDB, covering double-clicked payments, parallel refunds, parallel finalise clicks and parallel dispense.
Stock
Stock moves only through one kernel, by batch and expiry, first-expiry-first-out. Pharmacy, store, OT and ward indents all use it, which keeps the ledgers and the controlled-drug register consistent.
Audit and locks
Every write records who, when and a before and after diff. Clinical records are signed and then locked, with addenda. Payroll and other periods lock, and writes into a locked period are refused with a message.
Documents
PDFs (prescriptions, reports, bills, payslips, discharge summaries, tables) are rendered on demand with React PDF; nothing sensitive is stored as a file except uploads.
Quality gates
The package ships with more than 3,500 Vitest tests, integration tests on real MongoDB, static checks for server-action guards and client/server import boundaries, and headless browser flows with a responsive sweep at 375 and 768 pixels.
Quality gates and results
Every screen is checked at 1920, 1440 and 390 px in light and dark, with right-to-left layouts, an axe accessibility pass with no violations and more than 3,500 automated tests on real MongoDB.
Tech stack
| Area |
Technologies |
| Application |
Next.js, React, TypeScript |
| Data |
MongoDB |
| Styling |
Tailwind |
Inside the build
Hospital website — Departments, doctors and branches with a book-an-appointment call to action.
Role sign-in — One-click demo sign-in for every hospital role, from doctor to auditor.