TARAflow
Developers / 02

DFD Engine

The DFD engine bridges draw.io XML to the typed graph model used by the threat generator.

01

DFDGraphReference

  • elementsById: Map<string, DFDElementReference> — all elements by ID
  • connectionsById: Map<string, DFDConnectionReference> — all DataFlows by ID
  • effectiveElementTrustBoundary: Map<string, string> — innermost TB per element (prevents duplicates in nested TBs)
  • assetsById, outgoingConnections, incomingConnections — assets and topology
  • elementTrustBoundaries / trustBoundaryElements and trustBoundaryHierarchy — TB membership (overlap-based) and nesting
  • elementPhysicalBoundaries, elementChipBoundaries — PB/CB membership maps (no nesting)
  • chipBoundaryElements, physicalBoundaryElements — reverse maps
  • dataFlowAnalysis — per flow, the boundaries it crosses
02

From draw.io XML to the graph

  • dfd-parser.ts parses the draw.io XML (in the CLI with @xmldom/xmldom); build-dfd-graph.ts is the one entry point for the analysis graph — a single page goes straight to the builder, several pages through the effective model
  • dfd-graph-builder.ts: lookup and topology maps, TB membership (overlap-based) and hierarchy, the effective (deepest) TB per element, data-flow analysis, derived exposure levels, and the location of sensors and actuators from their physical boundary
  • app/utils/to-reference-graph.ts widens the concrete DFDGraph to the analysis view DFDGraphReference — the single sanctioned cast; workspace-layout.tsx memoizes it and hands it to the features as dfdGraph
  • The graph is derived, never persisted — the save path strips it from the project file
03

Asset Graph (features/dfd/asset-graph)

  • buildAssetGraph: pure preparation of nodes, edges, stubs and counts for the layer and focus view
  • layoutAssetGraph: d3-force with one lane per layer and a fixed-seed random source — deterministic; known positions are fixed, only new nodes move
  • Positions are view state: kept per session and in browser storage per project id, never in the project file
  • Edit mode writes nothing itself: asset links go through A2AOpsContext → commitA2AOps → relations service; assets, asset properties and element relations through the DFD tab's existing callbacks
  • Undo / redo names links by (source, target, type), not by id — a restored link gets a new id and is still found
04

Leveled DFDs (features/dfd/services/leveled)

  • Each draw.io page is parsed separately; the page tree and the identity links (definition ↔ context copy) live in dfd.pages of the project, not as XML attributes
  • Effective model (effective-model.ts): the leaves of the decomposition and, per logical flow, one resolved pair of endpoints stitched from all its occurrences — the deepest endpoint on one containment chain wins; otherwise the flow falls back to the parent level, never "pick one". Derived on every load, never persisted
  • Flow state: resolved | fallback (with reasons) | excluded; refines balances a parent flow, abstract excludes it only once a valid refinement exists
  • Interfaces inherit physical and chip boundaries along the flow's interface chain
  • leveled-analysis.ts: one parse and one effective model per DFD state, cached; every consumer — save path, validator, table groups, asset roll-up, reporter — asks there
  • Findings (leveled-findings.ts) never block editing, saving or generation: "error" only marks the DFD phase incomplete
  • Table groups (table-groups.ts): an element belongs to the top-level decomposed multiprocess it lies in, a flow to that group only if both resolved ends lie inside it
  • Asset roll-up (asset-rollup.ts): a decomposed multiprocess holds no relations of its own; its view is the distinct (asset, relation type) pairs of its parts, read-only
  • Schema 9 is the version fence: older releases refuse a file whose pages they would silently merge