Multi-Tenancy Roadmap
The system has completed Phase 0: Platform Decoupling and Phases 1-4: Hospital-Agnostic Refactoring (configuration extraction, prompt parameterisation, generic naming, database-driven configuration cache). It runs in single-tenant pilot mode for ZOL. Full multi-tenant routing (subdomain resolution, per-tenant authentication) is planned. See also the Multi-Tenancy Architecture page for current implementation details.
1. Vision
The system was initially built as a single-hospital solution. To deploy it across several hospitals (a software-as-a-service model) the architecture must support tenant isolation: each hospital's data, configuration and user experience must be completely separate.
The decoupling follows a phased approach: first parameterise all hospital-specific references (Phase 0, completed), then make the codebase fully hospital-agnostic (Phases 1-4, completed 31 March 2026), then add tenant routing and management (planned), and finally implement full multi-tenant operations (future).
2. Phase 0: Platform decoupling (completed)
Phase 0 converted all hardcoded references to the pilot hospital into parameterised, configuration-driven code, so the codebase can serve any hospital by changing configuration rather than code.
2.1 What was done
| Component | Before | After |
|---|---|---|
| Taxonomy | 37 module-level constants loaded at import | A taxonomy object obtained from a per-hospital factory |
| Prompt templates | 70+ hardcoded references to the hospital name | A prompt-context object with hospital identity placeholders |
| Taxonomy tables | No tenant scoping | A tenant reference on all entities and relationships, with composite uniqueness rules |
| Redis keys | Flat key prefixes | A tenant prefix on all cache, rate-limit and session keys |
| Site configuration | A single global configuration object | Per-hospital configuration profiles |
| Hub page detection | Hardcoded page-type patterns | Automatic hub/detail classification by a language-model binary classifier |
| Document service | Hospital-specific title patterns | Patterns loaded from the hospital configuration |
| Query service | Hardcoded base URLs | URLs from the hospital configuration |
| RAG service | Pilot-hospital identity in responses | Identity taken from the prompt-context object |
| Taxonomy registry | Global singleton | Per-hospital registry cache |
| Frozen taxonomy | One global registry | One registry per hospital |
2.2 Configuration architecture
All hospital-specific data lives in one configuration file per hospital. A file contains these sections:
- Hospital identity: name, short name, website and public contact number.
- Campuses: for each campus an identifier, canonical name, aliases (the alternative names visitors use), address and contact number.
- Domain knowledge: mappings from hospital-specific centres to the conditions and treatments they handle. Standard departments are covered by a universal, hospital-independent knowledge base instead.
- Search aliases: a universal set plus hospital-specific aliases that map common lay terms to the right centre (for example a lay term for breast cancer mapping to the breast centre).
- Specialty-to-department map: which departments correspond to each medical specialty.
Departments and page-type patterns were removed from the file on 2026-03-09: departments are now discovered automatically by the extraction pipeline, and hub/detail classification replaced the earlier page-pattern lists.
Adding a new hospital requires only a new configuration file, with no code changes.
2.3 Backward compatibility
A compatibility shim re-exports the symbols of the old taxonomy module from the new one, so existing imports keep working during the migration period. It can be removed once all imports are updated.
3. Current state: single-tenant pilot
The pilot serves one hospital (ZOL) under a default tenant. Every component defaults to that tenant, so the system works fully without explicit tenant routing.
3.1 What works today
- The full RAG pipeline with hospital-parameterised prompts
- Taxonomy tables with tenant-scoped entities and relationships
- Tenant-isolated Redis caching and rate limiting
- Hospital-specific safety messages and disclaimers in several languages
- A configurable taxonomy with SNOMED-CT synonym enrichment
3.2 What remains single-tenant
- The front end has no tenant routing or hospital selection
- Authentication is not yet tenant-aware (separate Keycloak realms could provide per-tenant isolation in a later phase)
- There is no tenant-management interface
- There is no per-tenant billing or usage tracking
Conversations, users and analytics events all carry a tenant reference in the current data model. A later schema migration added referential constraints with cascading deletion to documents and conversations, closing the last gap from the Phase 0 rollout. The earlier statement that those tables lacked a tenant reference no longer applies.
The remaining single-tenant gaps are operational rather than schema-level: request routing (subdomain, path or header resolution), per-tenant authentication flows, a tenant-management interface and usage metering.
4. Hospital-agnostic refactoring (completed 31 March 2026)
Before multi-tenant routing, the codebase was made fully hospital-agnostic in a four-phase sprint:
| Phase | What | Status |
|---|---|---|
| Phase 1 | Configuration extraction: a crawl-configuration table and administrative interface | Done |
| Phase 2 | Prompt parameterisation: all language-model prompts use a prompt context built from the database | Done |
| Phase 3 | Generic naming: the hospital-specific crawler was renamed, hospital branding removed | Done |
| Phase 4 | Database-driven configuration cache replaces all in-code constants | Done |
Result: according to the project's own count, 259 hospital-specific references were removed, and a new hospital can be onboarded with database configuration only.
5. Tenant routing (planned)
The next phase adds the infrastructure to serve multiple hospitals from a single deployment.
5.1 Tenant resolution
Tenant resolution options, ordered by complexity:
- Subdomain-based: one sub-domain per hospital; cleanest for end users.
- Path-based: one path prefix per hospital; simpler infrastructure.
- Header-based: a tenant request header; for programmatic API consumers.
5.2 Database tenancy
| Approach | Isolation | Complexity | Recommended? |
|---|---|---|---|
| Shared schema with a tenant column | Row-level | Low | Yes, at pilot scale |
| Separate schema per tenant | Schema-level | Medium | Future option |
| Separate database per tenant | Full | High | Not needed |
The shared-schema approach adds a tenant column to all PostgreSQL tables and enforces row-level filtering in the application layer. It is sufficient for the expected scale of five to ten hospitals.
5.3 Estimated scope
| Task | Effort | Dependencies |
|---|---|---|
| Add a tenant column to the remaining PostgreSQL tables (migration) | Medium | None |
| Tenant resolver middleware | Small | None |
| Per-tenant authentication | Medium | Tenant resolver |
| Front-end tenant context | Small | Tenant resolver |
| Tenant-management interface | Medium | Database migration |
| Per-tenant configuration files | Small | Phase 0 (done) |
6. Full multi-tenant operations (future)
A later phase adds operational capabilities for managing multiple hospitals in production.
6.1 Features
- Tenant onboarding workflow: automated setup of a new hospital (configuration, database seeding, taxonomy initialisation, content crawl)
- Per-tenant analytics dashboard: hospital administrators see only their own data
- Content isolation verification: automated tests confirming there is no cross-tenant data leakage
- Per-tenant feature switches: enable or disable pipeline components per hospital
- Usage metering and billing: track language-model API costs, storage and query volumes per tenant
6.2 Content pipeline
Each hospital requires its own content pipeline:
7. Storage isolation summary
| Storage layer | Phase 0 (current) | Phase 1 (planned) | Phase 2 (future) |
|---|---|---|---|
| PostgreSQL | Single tenant | Row-level tenant filtering | Row-level (sufficient) |
| Taxonomy tables | Tenant reference on all rows | Same | Same |
| Redis | Tenant key prefix | Same | Same |
| MinIO | Tenant path prefix | Same | Same |
| pgvector | Single collection | Per-tenant collection or filter | Per-tenant collection |
8. Risk considerations
| Risk | Mitigation |
|---|---|
| Cross-tenant data leakage | Automated integration tests verifying isolation at every storage layer |
| Configuration drift | A validation schema for configuration files and continuous-integration checks for required fields |
| Performance at scale | Per-tenant caching, connection pooling, lazy taxonomy loading |
| Compliance variation | Per-tenant data-protection impact assessment and data-retention settings (stored in the tenant configuration) |
Document version 2.0 | 2026-03-31 | SOFT4U BV. A planning document; later sections describe planned work, not delivered features.