Appearance
ADR-2179: Comprehensive Hexagonal Architecture Standardization and Frontend Modularization
- Status: Accepted
- Date: 2026-08-14
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
As the Cadence Clinical platform scales across 14 microservices, multiple shared packages, and two web applications (apps/web and apps/subject-portal), architectural drift has emerged in several areas:
- Microservices have accumulated loose root-level service and helper files, mixed directory layouts (
infrastructure/vsadapters/vsservices/), and inconsistent exception handling. - API errors returned varying formats across services rather than a unified RFC 7807 problem details specification.
- The patient/subject portal frontend (
apps/subject-portal) accumulated logic in monolithic single files (App.vue,index.js,style.css,sync-queue.js) rather than modular components, views, and stores.
To satisfy system requirement PRD-SYS-001, we establish a comprehensive platform-wide architectural standardization covering the 4-layer Hexagonal layout, plural adapters/ consolidation, RFC 7807 error formatting, and frontend modularization.
2. Decision Drivers & Constraints
- GxP Immutability & Auditability (PRD-SYS-001): Enforce strict decoupling between pure clinical domain logic, persistence layers, and HTTP delivery mechanics.
- Structural Convergence: Standardize directory layouts across all 14 microservices so developer tooling, linters, and architectural sentinels operate uniformly.
- Standardized API Error Contracts: Align all HTTP 4xx and 5xx error responses with RFC 7807 problem details (
type,title,status,detail,instance,invalid_params). - Frontend Modularity & Design Token Parity: Refactor monolithic frontend structures into modular Vue components and Pinia stores, sharing semantic CSS design tokens from
packages/ui/tokens.css. - Zero Dead Code: Directly refactor in-place and remove obsolete directories, loose files, and legacy shims.
3. Options Considered
Option 1: Comprehensive Full-Stack Standardization (Selected)
- Backend Hexagonal Layering: Every service under
apps/*strictly conforms todomain/(pure entities & exceptions),application/(ports & use cases),adapters/(persistence ORM, repositories, external HTTP clients, background workers), andpresentation/(FastAPI routers & DTOs). - Consolidation on Plural
adapters/: Retire allinfrastructure/andservices/folders in favor of canonicaladapters/andapplication/. - Centralized RFC 7807 Problem Details: Register standard
DomainErrorexception handlers viapackages.hexagonal.register_rfc7807_handlers(app)across all microservices. - Frontend Modularization: Modularize
apps/subject-portalintosrc/views/,src/components/,src/stores/, andsrc/services/sharing tokens withapps/web. - Package Cleanup: Purge empty and unused packages such as
packages/deid. - Pros:
- ✅ Addresses requirements
- Cons:
- ❌ Trade-offs accepted
Option 2: Partial / Backend-Only Migration
- Refactor only primary backend services (
designer,execution,etmf,ctms,quality) while keeping satellite services and frontend structures unchanged. - Trade-off: Leaves architectural fragmentation in place and increases maintenance burden over time.
- Pros:
- ✅ Addresses requirements
- Cons:
- ❌ Trade-offs accepted
4. Decision Outcome
- Chosen Option: Option 1 (Comprehensive Full-Stack Standardization).
- Justification: Selected as primary architectural approach.
Architectural Rules:
apps/<service>/domain/: Pure Python entities, value objects, domain invariants, and domain exceptions subclassingpackages.hexagonal.DomainError. No framework dependencies (no SQLAlchemy, no FastAPI).apps/<service>/application/: Interface ports (subclassingRepositoryPort[T],ExternalServiceClientPort,UseCasePort) and application use case orchestrators.apps/<service>/adapters/: Persistence models (SQLAlchemy / SQLModel), database repositories, external HTTP clients, and background workers.apps/<service>/presentation/: FastAPI routers, Pydantic DTO schemas, and response serializers.apps/<service>/main.py: Thin FastAPI bootstrap with lifespan lifecycle,GatewayAuthMiddleware, andregister_rfc7807_handlers(app).- Frontend Modularization: Shared design tokens in
packages/ui/tokens.cssconsumed by bothapps/webandapps/subject-portal.
5. Consequences & Trade-offs
- Positive:
- Standardized, predictable directory hierarchies across all 14 microservices.
- Uniform RFC 7807 error responses improving API contract reliability.
- Modularized frontend code with clean component boundaries and reusability.
- Seamless automated validation across all 10 quality gates.
- Negative:
- One-time refactoring overhead across multiple services and test import paths.
6. Implementation & Verification
- Shared Kernel:
packages/hexagonalupdated withProblemDetailsandregister_rfc7807_handlers. - Service Refactoring: Consolidated
infrastructure/andservices/intoadapters/andapplication/acrossapps/*. - Frontend Refactoring: Modularized
apps/subject-portaland aligned token usage. - Verification: All 10 architecture sentinels and quality gates validated via
uv run cadence check --parallel, with full test suite passing viauv run pytest -n auto.