TARAflow
Developers / 09

CLI Report Generator

taraflow-report — a headless entry point that generates the exact same documentation as the Documentation tab, from a saved .tara.json file, with no UI and no Electron. Built for CI/CD pipelines and containers where launching the desktop app isn't practical.

01

Entry-point separation, not a runtime switch

  • Two independent entry points share only the pure generation core: main.tsx (Electron/browser renderer) and taraflow-reporter/taraflow-report.ts (plain Node) — there is no branch in main.tsx/app.tsx that decides "am I headless?"
  • The purity boundary (invariant): no module in the generation path (features/documentation/{models,utils}/**) may import a feature barrel (features/*/index.ts), react, react-dom, @mui/*, draw.io, or any module with a top-level window/document reference. import type edges are exempt — they're erased at build time and carry no runtime weight
  • The boundary is enforced with a dependency-cruiser rule (utils/depcruise-doc.cjs), run as a CI-failing step
  • The renderer's own PDF path (pdf-generator-renderer.ts, window/IPC-based) and the UI's doc-generator.ts factory are never touched — the CLI gets its own factory (cli-generators.ts) that imports the four pure generators directly, never through the barrel that would drag in the renderer's PDF module
02

What changes vs. what's additive

  • Exactly one category of change touches existing files: swapping barrel imports for deep-path imports in the generation path (e.g. DFD formatters, risk mitigation helpers, threat catalog resolvers, shared tag utilities) — runtime-identical, the renderer resolves the same functions as before
  • Everything else is additive: new files under taraflow-reporter/: the entry with argument parsing (--format, --lang de|en, --out, --chapters) and cli/ (Node DOM parser, Node-side i18n init, project loader, chapter resolution, Project → DocProjectData mapper)
  • The i18n singleton is reused as-is in Node once initialized with a filesystem resource backend instead of the browser's — namespaces actually used by templates/mappers must all be registered, or raw i18n keys leak into the report instead of labels
03

Loading a project outside the app

  • No storage-service dependency (that's Electron/browser-coupled) — a plain fs.readFile + JSON.parse, followed by the same schema migrations the app runs on load (risk data, asset configuration, factor ratings)
  • The project's computed maps (e.g. impactLabels) must be present as empty Maps, never undefined — the base generator accesses them with a nullish-coalescing fallback on the value, not on the map itself
  • attackTree (singular, in DocProjectData) maps from project.attackTrees (plural) — a naming mismatch worth knowing about before it causes a silent empty section
  • The on-disk DFD thumbnail is already a base64 SVG — reports embed it directly, no headless draw.io instance needed; leveled DFDs store one thumbnail per page
  • The DFD XML is parsed with @xmldom/xmldom in Node, so the CLI runs the same leveled analysis (effective model, table groups, parent-level flows) as the app
04

Build & packaging

  • Its own tsconfig.cli.json (extends the base config) keeps the renderer's build untouched; path aliases (features/*, shared, i18n) are resolved via tsx + tsconfig-paths, or bundled with esbuild --platform=node --format=esm and --alias flags mirroring the same tsconfig paths; pdfmake and @resvg/resvg-js stay external and are installed into dist-cli/node_modules
  • Distributed as a standalone .deb package (depends only on nodejs; the two runtime modules ship inside), decoupled from the Electron desktop installer — installs taraflow-report straight to /usr/bin
  • PDF without a headless browser: pdf-generator-node.ts builds the document with pdfmake 0.3 and rasterizes the DFD SVG with @resvg/resvg-js — no Puppeteer, no Electron
05

CI guardrail

  • The dependency-cruiser rule runs as a hard CI failure: any reintroduced barrel/react/draw.io import in the generation path breaks the build immediately, not just a lint warning
  • A smoke test generates a report from a fixture project and asserts the output is non-empty and contains the expected chapter titles
  • The CLI binary itself runs against that fixture as a CI job, not just its library code in isolation
06

Sibling: taraflow-verify

  • A second headless binary in taraflow-verifier/ runs the Audit Verification Engine against a git repository: taraflow-verify <repo> (--anchor <hash> | --policy <file.json>) [--ref --strict --four-eyes --protected b1,b2 --json]
  • Exit codes for CI: 0 pass · 1 findings · 2 usage · 3 engine error (git missing, not a repository, unresolvable ref)
  • Same engine core as the app (features/audit/services/verify), git through one exec adapter; packaged as its own .deb depending on nodejs and git