Appearance
ADR-2212: DDF Compiler Pipeline Architecture
- Status: Accepted
- Date: 2026-08-23
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
The previous Digital Data Flow (DDF) compilation process in apps/execution/translator.py was an 830-line procedural monolithic script (process_translation). It coupled USDM schema validation, fallback metadata generation, CDISC ODM XML layout rendering, OpenRosa XForms XPath rule compilation, Playwright accessibility checking, and asynchronous database transaction/audit logging into a single tightly coupled function. This prevented isolated in-memory unit testing, duplicated rule parsing logic across apps/designer and apps/execution, and created high friction when adding new CDISC USDM specification versions.
2. Decision Drivers & Constraints
- GxP & CDISC Compliance (PRD-DDF-001, 21 CFR Part 11): CDISC USDM protocol specifications and rule conditions must compile deterministically into ODM and OpenRosa XForms with strict audit trail tracking.
- Deep Module Design: The compiler should present a minimal, pure in-memory interface (
DDFCompiler.compile(...)) hiding complex multi-stage pipeline machinery. - Zero Sibling Database Imports:
apps/designerandapps/executionmust not import each other's persistence models; shared transformation logic belongs in shared platform packages (e.g.packages.ddf). - Sub-Second Test Velocity: Unit testing compilation pipelines must run in-memory without database engines or browser automation overhead (
cadence test --fast).
3. Options Considered
Option 1: Option A (Selected): Create a shared, zero-database platform package (packages.ddf) with an explicit Intermediate Representation (IR), 5 isolated pipeline stages, and an injectable AccessibilityValidatorPort. Provide a thin DDFJobRunner adapter in apps/execution to manage database transactions and audit trails, while consolidating Designer rule ASTs.
- Overview: Option A (Selected): Create a shared, zero-database platform package (
packages.ddf) with an explicit Intermediate Representation (IR), 5 isolated pipeline stages, and an injectableAccessibilityValidatorPort. Provide a thinDDFJobRunneradapter inapps/executionto manage database transactions and audit trails, while consolidating Designer rule ASTs. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 2: Option B: Maintain the compiler within apps/execution as helper functions, exposing execution HTTP endpoints for Designer preview flows.
- Overview: Option B: Maintain the compiler within
apps/executionas helper functions, exposing execution HTTP endpoints for Designer preview flows. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 3: Option C: Dynamic DAG middleware engine streaming translation events.
- Overview: Option C: Dynamic DAG middleware engine streaming translation events.
- Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
4. Decision Outcome
- Chosen Option: Option A.
- Justification: Selected as primary architectural approach. We extract the DDF compiler into a dedicated package featuring:
- Pure In-Memory Interface:
DDFCompiler.compile(study_id, payload, options) -> DDFCompilationResult - 5 Pipeline Stages:
USDMNormalizerStage: Schema validation, metadata fallback synthesis, USDM version resolution.DDFSemanticIRBuilderStage: Builds strongly-typedDDFIntermediateRepresentationdecoupling ingestion from rendering.XPathRuleCompilerStage: Recursively compilesExpressionNoderule trees into OpenRosa XPath expressions.XmlLayoutRendererStage: Jinja2 template rendering for CDISC ODM v1.3.2 and OpenRosa XForms.LayoutAccessibilityValidatorStage: Validates form layouts viaAccessibilityValidatorPortprotocol.
- Unified Rule Engine: Consolidate
ExpressionNodeand rule evaluation in unified rule submodules for both Designer and Execution. - Execution Job Adapter:
DDFJobRunnerinapps/executionwrapsDDFCompilerwith database transactions and Part 11 audit logging. - Backward Compatibility:
apps/execution/translator.pyacts as a thin facade re-exporting legacy symbols.
5. Consequences & Trade-offs
- Positive:
- In-memory sub-millisecond compilation testing without spinning up PostgreSQL or Playwright.
- Complete elimination of AST/rule parsing duplication between
apps/designerandapps/execution. - Zero database transaction leakage into transformation logic.
- Negative:
- Requires maintaining an explicit Intermediate Representation (IR) layer between USDM and XML layouts.
6. Implementation & Verification
- Package architecture: shared compiler modules (
compiler.py,models.py,ports.py,stages/,rules/,templates/). - Adapters:
apps/execution/translator.pyfacade. - Unified Designer rules:
apps/designer/rules.pyandapps/designer/inverse_mapper.pyutilize canonical AST definitions. - Verification:
tests/test_translator.py,tests/test_translation_recovery.py.