Appearance
ADR-2247: Clinical Kernel Single Database Schema and Architecture Sentinel Hardening
- Status: Accepted
- Date: 2026-09-29
- Authors: @fderuiter, Antigravity AI
- Deciders: @fderuiter
- Supercedes: ADR-2244 (Extended & Hardened)
1. Context & Problem Statement
Following the clean-break migration to .NET 10 (ADR-2243) and the establishment of the Clinical Kernel Modular Monolith specification (docs/kernel/CLINICAL_KERNEL_SPECIFICATION.md), three critical architectural and operational discrepancies emerged:
- Database Topology Discrepancy:
.NET Aspire AppHost(apps/apphost/src/Program.cs) provisioned 5 separate physical databases (cadence-kernel,cadence-edc,cadence-etmf,cadence-ctms,cadence-quality). This contradicted the Clinical Kernel specification §9, which requires a single relational database with PostgreSQL schema-level isolation (kernel.*,edc.*,ctms.*,etmf.*,quality.*). Multi-database boundaries prevent atomic cross-domain 21 CFR Part 11 transactions, composite foreign keys(tenant_id, id), and unified bitemporal point-in-time state reconstruction. - Architecture Sentinel Blindspots (Issue #4723): ArchUnitNET rules
K-XS-1andK-XS-2intests/Cadence.ArchitectureTests/ArchitectureSentinelTests.csonly registered 6 assemblies, omitting 12 microservices. Furthermore, the check only filtered classes inheriting fromAggregateRootBase, allowing plain POCO classes (Site,Organizationinapps/org) and prefixed types (CtmsStudy,CtmsDelegationinapps/ctms) to define duplicate clinical aggregates withstringIDs, violating domain unification. - 21 CFR Part 11 GxP Traceability Gap (Issue #4717):
Cadence.Compliance.RtmGeneratorServicetracks 226 canonical requirements (192 PRD, 34 SRS). Only 8 were mapped in test attributes, leaving 218 unmapped. Additionally, 34 requirements were legacy PythonTrace-1..34aliases fromdocs/SRS.mdTable 7.2 referencing deleted Python test files, and a parser bug inScanTestsmisattributed docstrings placed inside method bodies.
2. Decision Drivers & Constraints
- Driver 1 (21 CFR Part 11 & GxP Invariants): Cross-domain mutations (e.g. subject enrollment triggering initial eCRF schedule generation and audit ledger persistence) must be committed atomically within a single PostgreSQL ACID transaction without distributed dual-write failure windows.
- Driver 2 (Domain Purity & Modular Monolith): A single canonical clinical truth (
Cadence.Kernel.Domain) must govern core entities (Tenant,Organization,Person,Study,Site,Participant,Observation,Attestation). Product modules must never define shadow tables or duplicate types. - Driver 3 (Deterministic Traceability): The Requirements Traceability Matrix (RTM) must reflect real verification status without false qualification or blocking CI on planned future sprint deliverables.
3. Options Considered
Option 1: Single Relational Database with Schema Partitioning & Universal ArchUnit Sentinels (Selected)
- Overview:
- Standardize Aspire AppHost and microservice EF Core
DbContextconfigurations on a single PostgreSQL database (cadence) with schema isolation:kernel,edc,ctms,etmf,quality. - Expand ArchUnitNET rules
K-XS-1andK-XS-2across all 18 microservice assemblies with zero tolerance for local entity duplication. - Refactor
apps/organdapps/ctmsto project directly fromCadence.Kernel.DomainUUIDv7 entities. - Introduce a Two-Tier RTM verification lifecycle:
Qualified(xUnit tested) vsPlanned(milestone scheduled).
- Standardize Aspire AppHost and microservice EF Core
- Pros:
- ✅ Preserves transactional ACID atomicity and outbox guarantees under 21 CFR Part 11.
- ✅ Enables PostgreSQL Row-Level Security (RLS) across composite keys
(tenant_id, id). - ✅ Mathematically guarantees Clean Architecture boundaries via ArchUnitNET across all 18 assemblies.
- ✅ Unblocks
dotnet cadence gxp syncin strict mode.
- Cons:
- ❌ Requires updating
apps/apphost, EF Core migrations, and DbContext schema bindings.
- ❌ Requires updating
Option 2: Retain Multi-Database Isolation & Phased Sentinel Exclusions
- Overview: Maintain separate databases per microservice in Aspire, coordinate cross-domain state via MassTransit distributed sagas, and grant temporary exemptions to
apps/organdapps/ctms. - Pros:
- ✅ Requires minimal initial migration refactoring.
- Cons:
- ❌ Re-introduces distributed eventual consistency windows and two-phase commit overhead prohibited by GxP invariants.
- ❌ Violates Clinical Kernel Specification §9 and allows architecture erosion to persist.
4. Decision Outcome
- Chosen Option: Option 1.
- Justification: Conforming Aspire AppHost and microservices to a single relational database with schema isolation directly delivers on the Clinical Kernel mission. Universal ArchUnit sentinels protect the codebase from structural backsliding, while the Two-Tier RTM provides rigorous, honest regulatory accounting.
5. Consequences & Trade-offs
- Positive Impact:
- Single database connection string across Aspire and staging environments.
- 100% architectural sentinel coverage across all 18 services.
- Eliminates duplicate domain aggregates and redundant migrations in
apps/organdapps/ctms. - Strict GxP synchronization passes deterministically.
- Negative Impact / Operational Changes:
apps/organdapps/ctmslocal duplicate entities (Organization,Site,Personnel,CtmsStudy) must be removed and replaced with references toCadence.Kernel.Domain.- Aspire AppHost database registrations consolidate from 5 instances to 1 with schema assignments.
6. Implementation & Verification Plan
- DX & Build Blocker Remediation:
- Patch
MarkdownValidatorService.csdirectory exclusions (.venv,bin,obj,dist,.antigravity) and fenced code block tracking. - Decouple
scripts/setup_wizard.sh(replace Stage 3 with native git pre-commit hook binding) andscripts/build-docs.js(remove Python preflight check). - Resolve
vitestdependency inapps/web.
- Patch
- Regulatory & Parser Fix:
- Fix
ScanTestsinside-method docstring regex inRtmGeneratorService.cs. - Update
docs/SRS.mdTable 7.2 to deprecate legacyTrace-1..34aliases in favor of canonicalPRD-*requirements.
- Fix
- Architecture Sentinel Expansion:
- Expand
ArchitectureSentinelTests.csto test all 18 microservice assemblies. - Refactor
apps/organdapps/ctmsto project fromCadence.Kernel.Domain.
- Expand
- AppHost Consolidation:
- Update
apps/apphost/src/Program.csto provision single database"cadence".
- Update
- Sprint 2 Core Kernel:
- Implement PostgreSQL Native Bitemporality (Issue #4725).
- Implement ProtocolVersion Snapshots & DDF Compiler (Issue #4724).