Skip to content

ADR-2602: Multi-Repository Ownership and Kernel Package Boundaries ​

NOTE

ADR-2603 supersedes the source repository split, cross-repository publishing plan, and extraction sequence. The kernel SDK boundaries, module ownership decisions, and single-host transaction model carry forward. See the project plan for current work. The remaining text records the decision accepted on 2026-10-28.


1. Context & Problem Statement ​

The migration program splits the program across ten repositories. Repository ownership is not the same as runtime structure: a repository governs source, and a product is a purchasable application. Two accepted decisions constrain the runtime:

  • ADR-2610 makes every scaffold service a Cadence.Modules.* module hosted in one composition host.
  • ADR-2600 requires every clinical write, kernel or module, to commit through one PostgreSQL transaction. A module context enlists in the kernel's transaction on a shared database.

Splitting source across repositories raises questions neither ADR answers:

  1. Does a product repository become a runtime service, a separate database, or a package that the host composes?
  2. The public SDK, Cadence.Kernel.Modules, references EF Core, Npgsql and engine_core/Cadence.Core.Domain. A product that consumes it inherits all three. The registry says products must not depend on kernel persistence.
  3. MIGRATION_PLAN.md requires this ADR to reconcile ADR-2610 and ADR-2600 explicitly and forbids silently reclassifying them as superseded.

Current kernel project graph on main (e3955e1): Cadence.Kernel.Modules references Abstractions and engine_core/Cadence.Core.Domain. It also carries EF Core Relational, Npgsql, FluentValidation and Microsoft.AspNetCore.OpenApi. Module authors need EF Core because a module defines a ModuleDbContext. Npgsql appears in the SDK only where the module store and the migrations helper call UseNpgsql. The SDK also takes AggregateRootBase and IGxPAuditable from Cadence.Core.Domain. CommandResult<TResult> already lives in Abstractions/Commands.

The reference chain is transitive. Cadence.Core.Domain references Cadence.Security, which references Cadence.Kernel.Abstractions. A product that takes the SDK therefore also receives Core.Domain and Security. The inventory (SOURCE_INVENTORY.md, merged in #5681) records the project graph. A consumer of the SDK today also inherits these NuGet packages: FluentValidation, Microsoft.AspNetCore.OpenApi, EF Core, Npgsql, System.IdentityModel.Tokens.Jwt and Microsoft.IdentityModel.Tokens. Abstractions has no package references. Core.Domain is itself in the K-XS-1 baseline (16 entries). They sit in the Randomization, Supply and Rules namespaces, and no SDK, Abstractions, Application or Domain file references them. Excluding those namespaces from the SDK path would clear the entries, without moving Core.Domain. That is an SDK-surface decision and must be made before the SDK is published.

2. Decision Drivers & Constraints ​

  • K-XS-2: applications reference Cadence.Kernel.Abstractions and Cadence.Kernel.Modules only.
  • K-TX-1..5 and ADR-2600 §4.2: one transaction per command across kernel and module rows, with no two-phase commit.
  • ADR-2601 and ADR-2610: one host and one runtime for the modules. The existing runtime is preserved.
  • Registry principles: no cross-repo private DbContext, no floating dependency on another repository's main, and a composition manifest that pins verified versions.
  • Five-gates roadmap (#5310): earlier gate evidence must keep passing after any boundary change.
  • Pre-deployment: no dual writer and no compatibility layer for the module write path.

3. Options Considered ​

3.1 Runtime shape of a product repository ​

OptionSummaryVerdict
A. Product repository is its own runtime service with its own databaseEach repository deploys its own hostRejected. Contradicts ADR-2610 and ADR-2601. Splits the transaction that ADR-2600 requires.
B. Product repository produces module packages; the composition host composes them over one shared databaseEach module keeps its own schema and DbContext, and writes through the kernel command pathProposed. Keeps ADR-2600 Option A and ADR-2601 unchanged.
C. Per-product databasesEach product gets its own databaseDeferred. ADR-2600 consequence: a later boundary decision, and it needs a separate ADR.

3.2 Dependency shape of the public SDK (answers kernel plan §2.1 and §2.2) ​

OptionSummaryVerdict
1. Keep EF Core, Npgsql and Cadence.Core.Domain in Cadence.Kernel.ModulesSimplest. Every product inherits every dependency.Rejected. Makes the public SDK carry persistence and a non-kernel dependency. This is the most likely source of a later breaking change.
2. Split the SDKAbstractions holds contracts with no EF, Npgsql or engine_core. Modules keeps the EF Core base types module authors must use. Npgsql moves to a host-side adapter. AggregateRootBase and IGxPAuditable move or are redefined in kernel-owned code. The K-XS-1 members in Core.Domain move first.Proposed, pending inventory.
3. Publish engine_core as a shared kernel dependencyKeeps the reference and publishes it.Not preferred. engine_core is not kernel-owned (matrix: "shared domain utilities").

Recommended shape under option 2, to be confirmed by K1:

  • Cadence.Kernel.Abstractions: typed IDs, command and event contracts, IClock, and CommandResult<TResult>, which already lives here. No EF Core, Npgsql or engine_core reference. Needs inventory: the dependency closure of that result type.
  • Cadence.Kernel.Modules: ICommandHandler, ICommandContext, IKernelUnitOfWork, AddCommandHandler, ModuleDbContext and the migrations helper. It references EF Core Relational as a pinned, explicit SDK dependency, because module authors define EF contexts (ADR-2600 §4.2). It does not reference Npgsql.
  • A host-side adapter (name to be chosen in K1, for example Cadence.Kernel.Modules.Npgsql) supplies the Npgsql options and the connection provider. Only the composition host references it.
  • Kernel-internal Domain, Application, Persistence and Api stay internal. Products never reference them.

3.3 Standards and rules assemblies (Cadence.Rules, Cadence.Standards) ​

  • Proposed: keep them as separately versioned packages in the kernel repository, with one canonical registry and one evaluator. Authoring UI stays in Blueprint.
  • Needs decision (matrix item 4): whether the standards registry belongs to the kernel repository or to a standards repository. This waits for the file-level inventory of packages/kernel and apps/knowledge.

4. Decision Outcome ​

  1. Repositories are source ownership, not runtime. The composition host in cadence-clinical remains the only runtime composition authority (ADR-2601). Product repositories publish packages the host composes. Repository boundaries never create a runtime service.
  2. One database per tenant deployment for the composed host (ADR-2600 Option A). Each module owns its schema and DbContext, and writes only through the kernel command path. A product repository never opens another module's DbContext.
  3. Public SDK packages follow §3.2 option 2. Abstractions and Modules are the only public packages. Modules pins EF Core and does not reference Npgsql or engine_core.
  4. Ownership follows the capability ownership matrix. Each change has exactly one source owner and one destination context. Ambiguous classes (execution, interop, knowledge, fileshare, org, packages/kernel standards and rules) are assigned per file or per class, never per folder.
  5. Versioning: packages are semver-versioned and pinned in the composition manifest. No floating reference to another repository's main. Public API snapshot tests gate each Abstractions and Modules release.
  6. Gating: extraction starts only when the four conditions in the migration plan and the agent execution guide hold.

4.1 Ownership Matrix Amendments ​

The matrix is not edited in this change. The amendments below are approved and go into the matrix in a follow-up docs PR:

  • Add a row for Cadence.Kernel.Modules SDK contract (kernel) and host-side Npgsql adapter (clinical).
  • Record AggregateRootBase and IGxPAuditable as kernel-owned contracts, once the move or redefinition is decided.
  • Note that Cadence.Security is a transitive dependency of the SDK today.
  • Keep the seven "Required resolution before extraction" items in the matrix open until the inventory closes them.

5. Consequences & Trade-offs ​

  • ✅ Products depend on a small, versioned public SDK. Persistence stays internal to the kernel and the host.
  • ✅ The single transaction and the single audit chain per tenant (ADR-2600) are preserved.
  • ❌ EF Core remains a shared SDK dependency. Upgrading it becomes a coordinated, pinned change.
  • ❌ One shared database means a cross-module schema change needs coordination. The ADR-2600 consequence on tenant-chain throughput still applies.
  • ❌ Splitting the SDK adds one package to publish and test.

6. Implementation & Verification ​

  • Abstractions and Modules public API snapshots pass.
  • A consumer project that references only the packages compiles a minimal module (kernel plan K2).
  • An architecture test fails if any product assembly references Domain, Application, Persistence, Api, Npgsql or engine_core.
  • The boundary baseline (kernel-boundaries.baseline.txt, 496 lines) may only shrink.
  • PostgreSQL-backed kernel tests run with zero skips before K1 closes (kernel plan §1, condition 3).

No check in this list has been run for this ADR. A green build is not validation.

6.1 Open Items (after acceptance) ​

These are implementation details inside the accepted direction. None of them reopens §4.

#ItemOwner of the answer
1Move or redefine AggregateRootBase and IGxPAuditable out of Core.Domain before the SDK is published (K1)Kernel prep thread (task 3)
2Exclude the 16 Core.Domain baseline namespaces from the SDK path, so the baseline entries clear without moving Core.Domain (K1)Kernel prep thread, with the inventory's symbol review
3Name and location of the host-side Npgsql adapter (K1)Kernel prep thread, under §4
4Home of Cadence.Rules and Cadence.Standards. Still needs inventory review; not covered by this acceptanceInventory thread, then decision
5Six owner choices decided in §8.1. The other 101 suggestions stand as given. Per-class dispositions for the 107 needs decision inventory rows, from the symbol-level review merged in #5683. The review is read-only and not line-by-line verified, and its owners are suggestions. Each slice must confirm its file list before moving codeInventory thread, then the slice owner (K3 and later)
6Whether a later per-product database (option C) needs its own ADRDeciders, after K3

6.1.1 Owner decisions (accepted 2026-10-28) ​

@fderuiter approved the recommendations for the six owner choices in the inventory's symbol-level review (#5683). The other suggestions in that review stand as given. Each decision takes effect in the matrix at the slice that moves the code, not now.

#AreaDecisionOwner
1Execution DbContextSplit by owner schema, one context per module, under ADR-2600. The migration plan follows the split.platform-shell (composition)
2Subject and consentParticipants own the workflow. Kernel keeps participant identity and ConsentStatus. Retire the duplicate /consents route and the second SubjectConsent in econsent.participants
3CGT custodyInterventions own the workflow. Custody events become kernel provenance.interventions
4CEC and signaturesSafety owns the CEC. Signatures bind to kernel Attestation. Confirm the consumer of Grade3ToxicityDetected before extraction.safety
5Lab reference ranges and bulk importEvidence owns the ranges. Capture only reads them.evidence
6Identity and crypto helpersPlatform-shell for now. Move to kernel IdentityVault later under K006. Retire the dormant DemographicsNormalizationService.platform-shell now, kernel IdentityVault later

These decisions do not start extraction. The synchronization conditions in the migration plan still apply.

6.2 Rollback ​

This ADR changes documentation only. Reverting its pull request restores the previous state. No runtime, database or package is affected.