This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
EMRALD (Event Modeling Risk Assessment using Linked Diagrams) is a dynamic Probabilistic Risk Assessment (PRA) tool developed at Idaho National Laboratory. Users design failure models as state diagrams in a React UI, then run Monte Carlo simulations via a separate .NET engine.
npm run dev # Dev server on :3000
npm run build # Production build
npm run lint # ESLint (max-warnings=0)
npm run format # Prettier
npm run test # Vitest (50s timeout)
npm run coverage # Vitest with v8 coverageRun a single test file:
npx vitest run src/tests/official/forms/TemplateForm/TemplateForm.test.tsxRun tests matching a name pattern:
npx vitest run -t "TemplateForm"npm run dev # Hot-reload desktop app (Tauri dev mode)
npm run build # Build Tauri desktop executableThe simulator (EMRALD_Sim) and engine (SimulationEngine) are .NET 10.0 projects. Build via VS or dotnet build EMRALD.sln.
The project has three independently runnable layers:
Emrald-UI (React 19) ← model designer, runs in browser or Tauri
↓ JSON files
SimulationEngine (.NET) ← loads JSON model, runs Monte Carlo simulation
↕ WebSocket
External simulators ← physics codes coupled via CouplingWebSocket/XMPP
- State management: Preact Signals (
@preact/signals-react) hold the global model inappData. Domain-specific operations (CRUD for states, events, actions, etc.) live in 12 React contexts undercontexts/. - UI layout: Three-pane —
Header, collapsibleSidebar(palette of model elements),MainCanvas(ReactFlow diagram editor). - Forms: Editing a model element opens a form component under
components/forms/. Each feature type (State, Event, Action, Diagram, Variable…) has its own form directory. - Model types: Defined in
src/types/EMRALD_Model.ts, which re-exports fromsrc/utils/Upgrades/v3_2/AllModelInterfacesV3_2.ts. Current schema version is 3.2. - Model mutations: Go through
src/utils/UpdateModel.ts. Cross-element references are tracked insrc/utils/ModelReferences.ts.
Old models are auto-upgraded on load. The upgrade chain runs: v1.x → v2.4 → v3.0 → v3.1 → v3.2. Each version subdirectory contains interfaces and an Upgrade*.ts class. UUIDs are assigned the first time an old model is loaded.
SimulationEngine/— core logic;StateTracker.csdrives state transitions,ProcessSimBatch.cshandles batch Monte Carlo runs.SimulationDAL/— JSON deserialization (Newtonsoft.Json), AJV-style schema validation, and ClearScript V8 for evaluating user-defined code snippets at runtime.MessageDefLib/— shared protocol types for WebSocket coupling.
Tests live in src/tests/official/. Each test directory mirrors the component under test and typically includes:
- A
.test.tsxfile expectedOutputs/JSON fixtures for snapshot-style assertionssrc/tests/test-utils.tsxprovides custom render helpers that wrap providers
Vitest uses jsdom and global test APIs (describe, it, expect without imports). The @/ alias maps to src/.
@/path alias is configured in bothvite.config.tsandvitest.config.js. Use it for all internal imports.- Prettier config (
.prettierrc): single quotes, trailing commas, avoid arrow parens. - ESLint enforces zero warnings — lint failures will block CI.
- Tauri IPC is used when the app runs as a desktop app; the UI degrades gracefully in plain browser mode.