Architecture
The DTIFx monorepo is organised around a layered runtime model. Shared utilities live in @dtifx/core, domain-specific runtimes build on top, and thin hosts expose commands or services. Nx powers the workspace so builds, tests, and documentation run reproducibly.
Repository topology
packages/coreprovides core facilities: telemetry runtimes, structured logging, configuration discovery, token source planning, token resolution, concurrency utilities, and the policy engine.packages/buildorchestrates end-to-end build pipelines. It exportscreateDefaultBuildEnvironmentto prepare caches and registries,createBuildRuntimeto wire services, andexecuteBuildto run planners, resolvers, transforms, and formatters.packages/diffimplements the diff session pipeline. It exposes token source adapters,runDiffSession, filtering utilities, failure policies, and report renderers.packages/auditloads policy manifests, resolves tokens through either the native or build-backed environments, and runs evaluations throughcreateAuditRuntimewith CLI reporters.packages/clistitches the runtimes together behind thedtifxbinary. Command modules register with the shared kernel so each workflow receives a consistent IO contract.
Shared TypeScript configuration, ESLint rules, and Markdown linting live at the repo root. Nx project files (project.json) define build, test, lint, and docs:build targets with caching enabled.
Runtime layering
Foundation –
@dtifx/core- Token sources use pointer templates, placeholders, and layered context to create deterministic plans. The same abstractions feed both build and audit pipelines.
- Telemetry is provided by
createTelemetryRuntime, which returns a tracer and anexportSpanshook. Exporters include the OpenTelemetry console span exporter (stdout). - Policy configuration loads default governance factories (owner metadata, deprecation replacements, tag requirements, override approvals, WCAG contrast) and plugin modules.
Domain runtimes – build, diff, audit
- Build runtime services (
SourcePlanner,TokenResolutionService,TransformationService,FormattingService,DependencyTrackingService) coordinate planning, parsing, transformation, formatting, and dependency snapshots. - Diff sessions combine token loading, rename detection, impact classification, summarisation, and failure policy evaluation before rendering reports.
- Audit runtimes reuse the same resolution services and policy engine, optionally delegating to the build runtime when audits need build-aware context such as cached transforms.
- Build runtime services (
Hosts – CLI and integrations
- The CLI registers command modules that translate Commander arguments into runtime calls. Each command resolves configuration paths through
@dtifx/core/config, prepares environments, and forwards IO and telemetry handles to the runtimes. - Custom hosts can import the same functions to embed DTIF workflows in pipelines, bots, or other automation without reimplementing orchestration logic.
- The CLI registers command modules that translate Commander arguments into runtime calls. Each command resolves configuration paths through
Telemetry and logging integration
Domain services publish lifecycle events to an in-memory event bus. CLI entry points subscribe with logging and telemetry adapters:
- Build commands attach
createBuildStageLoggingSubscriberto emit human-readable events or NDJSON structured logs when--json-logsis set. - Telemetry spans are created per command (for example
dtifx.cli.generate,dtifx.cli.inspect,dtifx.cli.audit). Each pipeline stage becomes a child span, and exporters flush viaexportSpans()before the process exits. - Audit commands reuse the same pattern, forwarding stage timings and policy summaries to the configured reporter.
Design principles
- Single source of truth – Token planning, parsing, diffing, and policy evaluation share the same adapters to keep behaviour identical across hosts.
- Predictable automation – Configuration loading, telemetry wiring, and logging use shared utilities so CI and local runs surface the same diagnostics.
- Extensibility without forks – Plugins register transforms, dependency strategies, and policies by exporting factories. Custom report renderers hook into the diff runtime via the public
renderReportAPI. - Incremental adoption – Teams can start with the diff engine, add the build runtime for artefact generation, and adopt the audit runtime once governance requirements mature, all through the same CLI.
Read the telemetry guide for exporter details and instrumentation patterns.