Backend Engineering

HMS — Multi-Tenant Hospital Management System — A Developer's Deep Dive

Modular, multi-tenant hospital platform: 53 backend modules across clinical, finance, HR, and supply chain.

2026-09-122 min read

A modular, multi-tenant hospital management system built as a Go + Rust + Next.js monorepo. The Go backend ships 53 business modules — patient registration, OPD/IPD, pharmacy, laboratory, EMR, e-prescription, nursing, operation theatre, radiology, blood bank, ambulance, billing, general ledger, AR/insurance, accounts payable, procurement, payroll, recruitment, telemedicine, patient/doctor portals, CSSD, dietary, housekeeping, biomedical equipment maintenance, and a cross-module BI dashboard, among others — each implementing a shared module contract with its own routes, migrations, permissions, tests, and generated docs, so modules can be excluded per customer to build smaller, licensed offline installers. The Next.js + TypeScript frontend is offline-first (IndexedDB via Dexie, sync outbox), backed by a Rust sync-engine for push/pull replication, PostgreSQL for data, Redis for caching, and Meilisearch for search.

The problem

Hospitals running dozens of departments — clinical, pharmacy, lab, billing, HR, procurement — typically stitch together separate systems per department with no shared patient record, no offline resilience during network drops, and no way to license or deploy a smaller build per customer without shipping the entire system.

The approach

Designed a modular Go backend where all 53 business modules implement a common module contract (routes, migrations, permissions, tests, generated docs) registered through a per-tenant module toggle system, so unused modules can be excluded to produce smaller offline installers. Backed it with PostgreSQL, Redis, and Meilisearch, added a Rust sync-engine (Axum push/pull) feeding the offline-first Next.js/TypeScript frontend (Dexie-backed IndexedDB cache + outbox), RBAC with branch-scoped overrides, a tamper-evident audit hash-chain, and Ed25519-based offline license verification.

The outcome

53/53 backend modules complete and tested, a Next.js dashboard with a generic CRUD UI across every module plus dedicated pages (results portal, subscription, clinic settings), Playwright end-to-end coverage across 19 specs, and a generated documentation site (BRD/FRD/SRS/API/permissions per module) — roughly 97% weighted complete, with external pentest sign-off and installer packaging as the remaining steps.

Stack

Go, Rust, Next.js, TypeScript, PostgreSQL, Redis, Meilisearch, Docker Compose

Live architecture demo

See it move, not just read about it.

Re-using the original animation from the linked project — same diagrams and trace you see on the case-study page.

HMS 53-Module Monorepo

STATE: OFFLINE CLINIC WRITES
Next.js 15 + TS Offline PWA53 Domain Contracts
Clinical Context:EMR Chart & OPD Triage
Security & License:Ed25519 Offline Validated
Rust Sync & Go Backend CoreAxum Replication + Chi Router
Integrity:Hash-Chained Audit Ledger
Engine State:Rust Sync: Queueing Outbox
IndexedDBDEXIE STORE
Outbox:14 Queued Delta Writes
Latency:< 2 ms local
Postgres RLSTHE TRUTH
Search:Meilisearch <100ms
Master:Disconnected
LAN severed. Hospital staff chart visits in IndexedDB (Dexie). Operations continue uninterrupted via local Ed25519 signature validation.

Ed25519-signed offline writes, drained into PostgreSQL with RLS once reconnected.

The Sub-2s Offline Reconcile

STEP 1/6
Next.js PWA • OPD / EMR
LAN drops during shift; physician charts MRN:9402, writes to IndexedDB (Dexie) • ~1 ms
Dexie Outbox
write queues locally; Ed25519 signed license validates offline capability • no block
Rust Sync Engine
link re-establishes; Axum push worker batches 42 pending mutations in sub-2s budget
Go Core • PostgreSQL 16
branch-scoped RLS checks tenant context; atomically commits clinical delta • ~32 ms
Tamper-Proof Audit
SHA-256 hash-chain signs previous block; write sealed into immutable compliance log
Redis • Meilisearch
hot OPD cache invalidates; patient index searchable across 53 modules • <80 ms

System architecture

Open in new tab ↗

← All posts