Appearance
ADR-2239: Universal Decimal Financial Precision Dynamic OpenAPI Gateway Discovery and Tier 2 Quality Realignment
- Status: Accepted
- Date: 2026-09-03
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
During the Phase 0 forensic gap analysis (AUD-NET10-001) of the Cadence Clinical repository, three critical architectural hazards were uncovered that jeopardized migration to .NET 10:
- Floating-Point Financial Non-Compliance: The legacy Python implementation in
apps/paymentsmodeled monetary currency amounts, fee schedules, split payee shares, withholding deductions, and invoice totals using binary floating-point (float). Under 21 CFR Part 11 and IRS 1099 compliance regulations, binary floating-point arithmetic introduces IEEE-754 precision drift, risking audit disqualification and ledger reconciliation errors. - In-Process Gateway Coupling:
apps/gateway/main.pyaggregated downstream OpenAPI schemas by dynamically importingapps.{name}.mainin-process. Transcribing Python services to .NET 10 breaks this reflection mechanism, causing gateway startup crashes or missing route documentation. - False Leaf Node Sequencing:
apps/qualitywas designated as a Tier 1 leaf node, yet its surveillance runner (QualityExecutionClient) relies on HTTP calls toapps/execution(port 8002).
2. Decision Drivers & Constraints
- 21 CFR Part 11 & IRS 1099 Integrity: Absolute financial ledger precision is non-negotiable; rounding errors on participant stipends and investigator payouts violate GxP traceability (
PRD-SYS-053,PRD-PAY-002). - Strangler Fig Proxy Independence: The gateway must route traffic and publish API documentation transparently whether a downstream service is running on Python FastAPI or .NET 10 Minimal APIs.
- Hermetic Integration Testing: Services in higher migration tiers must be testable without circular dependencies or unmocked upstream network failures.
3. Options Considered
Option 1: (Selected) Universal C# 14 Decimal Standard: Enforce strict C# 14 decimal (System.Decimal) mapped to PostgreSQL numeric(18, 4) with MidpointRounding.ToEven (banker's rounding) across all financial DTOs, domain models, and calculation engines.
- Overview: (Selected) Universal C# 14 Decimal Standard: Enforce strict C# 14
decimal(System.Decimal) mapped to PostgreSQLnumeric(18, 4)withMidpointRounding.ToEven(banker's rounding) across all financial DTOs, domain models, and calculation engines. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 2: Floating-Point with API Boundary Coercion: Retain double internally and coerce to decimal at the HTTP serialization boundary. Rejected: Internal domain calculation accumulation errors would remain.
- Overview: ### B. OpenAPI Gateway Discovery
- Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 3: (Selected) Dynamic HTTP Discovery & Precompiled Schema Fallback: Gateway polls downstream /openapi.json endpoints asynchronously and merges them into the public schema, falling back to build-time generated OpenAPI artifacts in docs/openapi/.
- Overview: (Selected) Dynamic HTTP Discovery & Precompiled Schema Fallback: Gateway polls downstream
/openapi.jsonendpoints asynchronously and merges them into the public schema, falling back to build-time generated OpenAPI artifacts indocs/openapi/. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 4: Retain In-Process Module Reflection: Keep importlib and stub out .NET services with Python placeholder files. Rejected: Violates clean-break migration and introduces synthetic technical debt.
- Overview: ### C. Quality Service Sequencing
- Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 5: (Selected) Tier 2 Realignment with Typed Contracts: Demote Cadence.Quality to Tier 2 (migrating after Cadence.Execution), standardizing cross-service interactions on IExecutionApiClient in Cadence.Contracts.
- Overview: (Selected) Tier 2 Realignment with Typed Contracts: Demote
Cadence.Qualityto Tier 2 (migrating afterCadence.Execution), standardizing cross-service interactions onIExecutionApiClientinCadence.Contracts. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 6: Retain Tier 1 with Ad-hoc Mocks: Keep Cadence.Quality in Tier 1 using loose HTTP string mocks. Rejected: Fragile contracts fail to detect schema drift.
- Overview: ---
- Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
4. Decision Outcome
- Chosen Option: Option 1
- Justification: 1. Adopt Universal Decimal Precision Standard: All currency, fees, withholding rates, overheads, and stipend records in
Cadence.Paymentsmust usedecimalwith explicit banker's rounding.
- Decouple Gateway Schema Discovery: API Gateway discovers OpenAPI endpoints over standard HTTP (
GET /openapi.json) or from static schema files, eliminating runtime Python module imports. - Reclassify Cadence.Quality as Tier 2:
Cadence.Qualityis scheduled in Tier 2 followingCadence.Execution. Cross-service calls use typedIExecutionApiClientcontracts.
5. Consequences & Trade-offs
- Positive: Eliminates floating-point calculation drift under financial audit; enables clean Strangler Fig proxying without Python in-process dependencies; establishes robust contract-based integration testing.
- Negative: Requires updating
BOUNDED_CONTEXT_MIGRATION_MATRIX.mddependency graphs; requires implementing typed contracts inCadence.Contractsprior to Tier 2 service migration.
6. Implementation & Verification
- Glossary Updated: Added
Universal Decimal Precision StandardandCanonical Timestamp Normalization InvarianttoCONTEXT.md. - Migration Hub Documented: Updated
docs/migration/Migration_Phase0_Readiness_Audit.mdand indexed indocs/migration/index.md. - Validation: Verified using
python scripts/validate_adrs.pyandpython scripts/validate_markdown.py.