TARAflow
Developers / 03

Hazard Model

Data model, sync boundary with the DFD/Asset stores, and the review-workspace UI for the optional safety-analysis tab.

01

Data model

  • HazardItem (shared/models/hazard-types.ts) — lean; relations stored separately as ContributesToRelation / EndangersRelation (a HazardRelation union), joined by branded HazardItemId
  • HazardCombinationType — ANY (OR, default) | ALL (AND) — the Bowtie gate; only meaningful with ≥2 contributing causes
  • HazardImpact (shared/models/hazard-impact.ts) — discriminated union over human | environment | infrastructure, each with its own severity scale (SEVERITY_SCALE_BY_TARGET); HumanHarmSeverity = SafetyImpact — "none" (no injury, S0) is a rating, never counted as harm on the asset; environment and infrastructure use low | medium | high | critical
  • Asset references on relations are plain AssetReference.id strings, not the branded asset id type
  • Project.hazards: HazardData | null — HazardData = { hazards, relations, lastModified, configuration? }; null for pre-existing / non-safety projects, no migration required
  • Schema v2 inserted Hazard as its own PhaseId (id 1) — all later phase ids shifted; every call site references phases via PhaseId.X, never a bare literal
02

Gating & progress

  • Gate flag lives in ProjectInfoData.safetyRelevant (not a separate settings object), toggled via the Safety Analysis switch in the Overview tab; default false; requiresHazardAnalysis(tags) (EN 50742, IEC 81001, IEC TR 60601, IEC 63452, CLC/TS 50701) forces it on when the project is opened
  • Tab visibility: filtered out of phase-tab-bar's workflow sort when off, with a render-guard + redirect to Overview in workspace-layout as a second line of defense
  • PROGRESS_PHASE_IDS / getProgressPhaseIds(safetyRelevant) in phase-types.ts is the single source of truth for which phases count toward the progress bar — Hazard only counts when the toggle is on; Documentation/Audit/Integration are excluded from all workflows
03

Asset creation & the DFD sync boundary

  • No separate AssetStore — dfd.assets stays the canonical store; asset creation from the Hazard tab goes through a shared pure primitive, shared/services/asset-creation.ts
  • Bowtie onSave(draft, sessionAssets) buffers created assets on the tab (pendingCreatedAssets) until autosave folds them into dfd.assets via addCreatedAssets (features/dfd/services/dfd-asset-creation.ts); dialog-cancel discards the buffered assets, no leak
  • Known sharp edge: the Hazard write path bypasses the normal DFD→Assets sync (syncFromDFD) unless workspace-layout's handleHazardsUpdate explicitly re-invokes it after addCreatedAssets — two stores (project.dfd.assets / project.assets.assets) exist today, which is the interim state pending a tracked single-source-of-truth consolidation
  • environment is a 9th AssetGroup (prefix EN), added specifically to give hazard causes/targets outside the DFD (e.g. ambient conditions) somewhere to live
04

Review workspace

  • hazard-dialog.tsx is a master-detail review workspace, not a single edit form — a sidebar over every hazard, a detail pane with the scope decision, hazard fields, and a Bowtie editor
  • systemRelevance: "in_scope" | "out_of_scope" | "unknown" is the hazard-level rollup that gates whether a Bowtie needs modeling — it is the coarse, hazard-level counterpart to the still-parked edge-level Security-Safety Independence analysis (Phase 6), vocabulary-compatible with it
  • Progressive disclosure: hazard fields are always visible; the Bowtie collapses (not disabled) until scope is in_scope
  • No Save/Cancel — commit-on-close: OK, Escape, and backdrop click all call a single commitAndClose; a missing required label closes without persisting
05

Import bridge

  • Profile-based, format-agnostic: CSV (papaparse), XLSX/XLSM/XLS/ODS (SheetJS xlsx), and a native TARAflow-JSON adapter, all registered against one CanonicalField contract in safety-hazard-importer.ts
  • hazard-bridge.ts maps legacy SafetyHazard records into the native graph — affectedPersons becomes deduplicated human assets connected via structured, per-role endangers edges (SEVERITY_TO_HUMAN), deliberately not a single flattened severity value
  • Unrecognized source columns are retained as importMeta (provenance), not dropped