# diamondlightsource/dedi-web architecture

> Architecture diagram of the GitHub repository diamondlightsource/dedi-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/diamondlightsource/dedi-web
- Repository: https://github.com/diamondlightsource/dedi-web

## Overview

1. **Overall shape**
   - `dedi-web` is a **single-page, client-only React application** for calculating detector distance / q-range values.
   - There is **no backend or API layer** in the repo; all state, calculations, and rendering happen in the browser.
   - The app is built with **TypeScript + Vite**, using **React**, **MUI**, **Zustand**, and some **SVG/plotting** utilities.

2. **Main runtime flow**
   - User input enters through the UI in `src/data-entry` and modal dialogs in `src/dialogs`.
   - That input is stored in small Zustand stores and/or persisted storage wrappers.
   - The core calculation modules in `src/calculations` derive ranges and scattering quantities.
   - Derived outputs are then rendered in `src/results` and `src/plot` as tables, diagrams, and visual overlays.

3. **State management boundary**
   - State is split by domain into independent stores such as:
     - `beamlineconfigStore`
     - `beamstopStore`
     - `cameraTubeStore`
     - `detectorStore`
     - `plotStore`
   - This keeps the app from having one monolithic state object; each subsystem reads/writes the piece it owns.
   - `src/utils/persistedStorage.ts` suggests browser persistence for user settings/configuration.

4. **Configuration and data-entry subsystem**
   - `src/data-entry` contains the main form-like controls for the beamline setup:
     - beamline selector
     - beamstop
     - camera tube
     - detector
   - These components are the primary user input surface for the calculation model.
   - They connect the user’s instrument configuration to the underlying stores and preset system.

5. **Dialog-driven configuration editing**
   - `src/dialogs` contains richer editing UIs, especially for beamline, detector, and calibrant configuration.
   - The beamline and detector dialogs are schema-driven: they include `schema.json` and `uischema.json`, plus table components and custom renderers.
   - This indicates a boundary between:
     - **structured configuration definition** via JSON schema
     - **presentation/rendering** via React/MUI custom components
   - The dialog layer is likely used to edit reusable config objects rather than ad hoc form fields.

6. **Preset and catalog subsystem**
   - `src/presets` holds built-in configuration data:
     - detector presets
     - calibrant presets
     - preset configuration mappings
   - `presetManager.ts` is the integration point that loads or selects those presets for the rest of the app.
   - This layer acts as the bridge between static reference data and editable user configuration.

7. **Calculation engine**
   - `src/calculations` is the mathematical core of the application.
   - It contains reusable geometric and numeric abstractions such as:
     - numeric ranges
     - unit ranges
     - q-space / q-range / q-value logic
     - rays and unit vectors
   - Tests alongside these modules show that the repo treats these calculations as a stable, independently verifiable domain layer.
   - This layer should be drawn as the pure computation boundary between UI/state and visual output.

8. **Visualization and plot subsystem**
   - `src/plot` turns the calculation results into interactive visual representations.
   - Components like `centrePlot`, `legendBar`, and the SVG helpers suggest a custom, SVG-based plotting/overlay layer rather than a generic charting package.
   - Utilities such as `segmentUtils` and `plotUtils` likely translate computed geometry into display primitives.
   - `plotStore` indicates plotting state is managed separately from domain configuration.

9. **Results presentation**
   - `src/results` contains the final user-facing outputs:
     - range diagrams
     - range tables
     - message/summary diagrams
     - a results bar
   - This layer sits downstream of the calculations and plot logic, formatting derived values into readable output.
   - It is the app’s “answer surface,” where computed q-range and related quantities are summarized for the user.

10. **Shared utilities and UI primitives**
    - `src/utils` holds cross-cutting helpers:
      - units and unit conversions
      - styles
      - reusable info/error components
      - color selection
      - shared types
    - These are not domain-specific; they support multiple layers, especially dialogs, forms, and results.
    - `src/basicAppBar.tsx` and `src/app.tsx` suggest a top-level shell that wires navigation/controls around the main calculator experience.

11. **Testing and reliability boundary**
    - Tests are concentrated around the numerical and plotting logic rather than the UI shell.
    - That indicates the repo values correctness in:
      - range math
      - q-space computations
      - unit conversions
      - preset handling
      - segment/plot utilities
    - For an architecture diagram, these test files show the most important “pure logic” boundaries.

12. **Deployment and packaging**
    - The project is designed for static deployment, with GitHub Actions for CI and GitHub Pages deployment.
    - `Dockerfile` and `.devcontainer` support reproducible local development, but they do not change the application architecture itself.
    - The deployment model reinforces the repo’s client-side, no-server design.

13. **How to draw the architecture**
    - A good diagram would show:
      - **User**
      - **React UI shell**
      - **Input/config layer** (`data-entry`, `dialogs`, `presets`)
      - **State layer** (`zustand` stores, persisted storage)
      - **Calculation engine** (`calculations`)
      - **Rendering layer** (`plot`, `results`)
      - **Browser storage** as the persistence boundary
    - The key dependency direction is: **inputs and presets → stores → calculations → results/plot**, with persistence feeding back into the stores on load.

Main entry points: [`src/app.tsx`](https://github.com/diamondlightsource/dedi-web/blob/main/src/app.tsx) (App layout), [`src/calculations/qrange.ts`](https://github.com/diamondlightsource/dedi-web/blob/main/src/calculations/qrange.ts) (Math core), [`src/plot/plotter.ts`](https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/plotter.ts) (Plotting), [`src/data-entry/beamlineconfigStore.ts`](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamlineconfigStore.ts) (Beamline store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Shell"]
  node_n2["App shell<br/>react root<br/>[main.tsx]"]
  node_n3["App layout<br/>react app<br/>[app.tsx]"]
  node_n4["Top bar<br/>ui shell<br/>[basicAppBar.tsx]"]
end

subgraph group_g2["Input & config"]
  node_n5["Beamline form<br/>input panel"]
  node_n6["Beamstop form<br/>input panel<br/>[beamstop.tsx]"]
  node_n7["Camera tube form<br/>input panel<br/>[cameraTube.tsx]"]
  node_n8["Detector form<br/>input panel<br/>[detector.tsx]"]
  node_n9["Beamline dialog<br/>schema dialog"]
  node_n10["Detector dialog<br/>schema dialog<br/>[detectorDialog.tsx]"]
  node_n11["Calibrant dialog<br/>config dialog"]
  node_n12["Preset manager<br/>preset registry<br/>[presetManager.ts]"]
end

subgraph group_g3["State"]
  node_n13["Beamline store<br/>zustand store"]
  node_n14["Beamstop store<br/>zustand store<br/>[beamstopStore.ts]"]
  node_n15["Camera store<br/>zustand store<br/>[cameraTubeStore.ts]"]
  node_n16["Detector store<br/>zustand store<br/>[detectorStore.ts]"]
  node_n17["Plot store<br/>zustand store<br/>[plotStore.ts]"]
  node_n18[("Persistence<br/>browser storage")]
end

subgraph group_g4["Computation"]
  node_n19["Math core<br/>calculation engine<br/>[qrange.ts]"]
end

subgraph group_g5["Output"]
  node_n20["Plotting<br/>svg plot layer<br/>[plotter.ts]"]
  node_n21["Centre plot<br/>visualization<br/>[centrePlot.tsx]"]
  node_n22["Legend bar<br/>visualization<br/>[legendBar.tsx]"]
  node_n23["Results view<br/>results ui<br/>[rangeDiagram.tsx]"]
  node_n24["Scattering quantities<br/>results model"]
end

subgraph group_g6["Shared"]
  node_n25["Shared utils<br/>utility layer<br/>[units.ts]"]
end

node_n1(("User<br/>actor"))

node_n1 -->|"uses"| node_n2
node_n2 -->|"renders"| node_n3
node_n3 -->|"contains"| node_n4
node_n3 -->|"shows"| node_n5
node_n3 -->|"shows"| node_n6
node_n3 -->|"shows"| node_n7
node_n3 -->|"shows"| node_n8
node_n5 -->|"writes"| node_n13
node_n6 -->|"writes"| node_n14
node_n7 -->|"writes"| node_n15
node_n8 -->|"writes"| node_n16
node_n9 -->|"edits"| node_n13
node_n10 -->|"edits"| node_n16
node_n11 -->|"selects"| node_n12
node_n12 -->|"seeds"| node_n13
node_n12 -->|"seeds"| node_n16
node_n18 -->|"hydrates"| node_n13
node_n18 -->|"hydrates"| node_n14
node_n18 -->|"hydrates"| node_n15
node_n18 -->|"hydrates"| node_n16
node_n13 -->|"feeds"| node_n19
node_n14 -->|"feeds"| node_n19
node_n15 -->|"feeds"| node_n19
node_n16 -->|"feeds"| node_n19
node_n19 -->|"drives"| node_n20
node_n19 -->|"derives"| node_n24
node_n20 -->|"renders"| node_n21
node_n20 -->|"renders"| node_n22
node_n24 -->|"formats"| node_n23
node_n17 -->|"coordinates"| node_n20
node_n25 -->|"supports"| node_n9
node_n25 -->|"supports"| node_n10
node_n25 -->|"supports"| node_n23
node_n25 -->|"supports"| node_n20

click node_n2 "https://github.com/diamondlightsource/dedi-web/blob/main/src/main.tsx"
click node_n3 "https://github.com/diamondlightsource/dedi-web/blob/main/src/app.tsx"
click node_n4 "https://github.com/diamondlightsource/dedi-web/blob/main/src/basicAppBar.tsx"
click node_n5 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamlineSelector.tsx"
click node_n6 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamstop.tsx"
click node_n7 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/cameraTube.tsx"
click node_n8 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/detector.tsx"
click node_n9 "https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/beamline/appConfigDialog.tsx"
click node_n10 "https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/detector/detectorDialog.tsx"
click node_n11 "https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/calibrant/calibrantDialog.tsx"
click node_n12 "https://github.com/diamondlightsource/dedi-web/blob/main/src/presets/presetManager.ts"
click node_n13 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamlineconfigStore.ts"
click node_n14 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamstopStore.ts"
click node_n15 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/cameraTubeStore.ts"
click node_n16 "https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/detectorStore.ts"
click node_n17 "https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/plotStore.ts"
click node_n18 "https://github.com/diamondlightsource/dedi-web/blob/main/src/utils/persistedStorage.ts"
click node_n19 "https://github.com/diamondlightsource/dedi-web/blob/main/src/calculations/qrange.ts"
click node_n20 "https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/plotter.ts"
click node_n21 "https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/centrePlot.tsx"
click node_n22 "https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/legendBar.tsx"
click node_n23 "https://github.com/diamondlightsource/dedi-web/blob/main/src/results/rangeDiagram.tsx"
click node_n24 "https://github.com/diamondlightsource/dedi-web/blob/main/src/results/scatteringQuantities.ts"
click node_n25 "https://github.com/diamondlightsource/dedi-web/blob/main/src/utils/units.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n2,node_n3,node_n4 toneBlue
class node_n5,node_n6,node_n7,node_n8,node_n9,node_n10,node_n11,node_n12 toneAmber
class node_n13,node_n14,node_n15,node_n16,node_n17,node_n18 toneMint
class node_n19 toneRose
class node_n20,node_n21,node_n22,node_n23,node_n24 toneIndigo
class node_n25 toneTeal
class node_n1 toneNeutral
```

## Components

### Shell

Top-level app bootstrap and layout

- [App shell](https://github.com/diamondlightsource/dedi-web/blob/main/src/main.tsx): react root · Top-level React entry and app wiring · `src/main.tsx`
- [App layout](https://github.com/diamondlightsource/dedi-web/blob/main/src/app.tsx): react app · Main application composition and calculator surface · `src/app.tsx`
- [Top bar](https://github.com/diamondlightsource/dedi-web/blob/main/src/basicAppBar.tsx): ui shell · Primary application bar and global controls · `src/basicAppBar.tsx`

### Input & config

User-facing configuration entry and preset selection

- [Beamline form](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamlineSelector.tsx): input panel · Beamline selector and configuration entry · `src/data-entry/beamlineSelector.tsx`
- [Beamstop form](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamstop.tsx): input panel · Beamstop configuration input · `src/data-entry/beamstop.tsx`
- [Camera tube form](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/cameraTube.tsx): input panel · Camera tube configuration input · `src/data-entry/cameraTube.tsx`
- [Detector form](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/detector.tsx): input panel · Detector configuration input · `src/data-entry/detector.tsx`
- [Beamline dialog](https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/beamline/appConfigDialog.tsx): schema dialog · Schema-driven beamline configuration editor · `src/dialogs/beamline/appConfigDialog.tsx`
- [Detector dialog](https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/detector/detectorDialog.tsx): schema dialog · Schema-driven detector editor and module selection · `src/dialogs/detector/detectorDialog.tsx`
- [Calibrant dialog](https://github.com/diamondlightsource/dedi-web/blob/main/src/dialogs/calibrant/calibrantDialog.tsx): config dialog · Calibrant selection and editing UI · `src/dialogs/calibrant/calibrantDialog.tsx`
- [Preset manager](https://github.com/diamondlightsource/dedi-web/blob/main/src/presets/presetManager.ts): preset registry · Loads and selects built-in presets and config mappings · `src/presets/presetManager.ts`

### State

Domain stores and browser persistence

- [Beamline store](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamlineconfigStore.ts): zustand store · Beamline configuration state · `src/data-entry/beamlineconfigStore.ts`
- [Beamstop store](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/beamstopStore.ts): zustand store · Beamstop state slice · `src/data-entry/beamstopStore.ts`
- [Camera store](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/cameraTubeStore.ts): zustand store · Camera tube state slice · `src/data-entry/cameraTubeStore.ts`
- [Detector store](https://github.com/diamondlightsource/dedi-web/blob/main/src/data-entry/detectorStore.ts): zustand store · Detector state slice · `src/data-entry/detectorStore.ts`
- [Plot store](https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/plotStore.ts): zustand store · Interactive plot state slice · `src/plot/plotStore.ts`
- [Persistence](https://github.com/diamondlightsource/dedi-web/blob/main/src/utils/persistedStorage.ts): browser storage · Persisted browser settings and configuration wrapper · `src/utils/persistedStorage.ts`

### Computation

Pure calculation and domain math

- [Math core](https://github.com/diamondlightsource/dedi-web/blob/main/src/calculations/qrange.ts): calculation engine · Range, q-space, q-value, ray, and vector calculations · `src/calculations/qrange.ts`

### Output

Rendered plots and result summaries

- [Plotting](https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/plotter.ts): svg plot layer · SVG plot construction, overlays, and segment utilities · `src/plot/plotter.ts`
- [Centre plot](https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/centrePlot.tsx): visualization · Main detector-distance plot view · `src/plot/centrePlot.tsx`
- [Legend bar](https://github.com/diamondlightsource/dedi-web/blob/main/src/plot/legendBar.tsx): visualization · Auxiliary legend and scale display · `src/plot/legendBar.tsx`
- [Results view](https://github.com/diamondlightsource/dedi-web/blob/main/src/results/rangeDiagram.tsx): results ui · Range diagrams, tables, and summary output · `src/results/rangeDiagram.tsx`
- [Scattering quantities](https://github.com/diamondlightsource/dedi-web/blob/main/src/results/scatteringQuantities.ts): results model · Derived output quantities presented to the user · `src/results/scatteringQuantities.ts`

### Shared

Cross-cutting utilities and UI primitives

- [Shared utils](https://github.com/diamondlightsource/dedi-web/blob/main/src/utils/units.ts): utility layer · Units, styles, colours, info and error components · `src/utils/units.ts`

### Other components

- **User**: actor · Person configuring the detector calculation

## Connections

- User → App shell: uses · User interacts with the React application
- App shell → App layout: renders · App shell composes the main experience
- App layout → Top bar: contains · Global app bar and navigation controls
- App layout → Beamline form: shows · Main beamline selection surface
- App layout → Beamstop form: shows · Beamstop controls in the main form
- App layout → Camera tube form: shows · Camera tube controls in the main form
- App layout → Detector form: shows · Detector controls in the main form
- Beamline form → Beamline store: writes · Beamline entry updates its store slice
- Beamstop form → Beamstop store: writes · Beamstop entry updates its store slice
- Camera tube form → Camera store: writes · Camera tube entry updates its store slice
- Detector form → Detector store: writes · Detector entry updates its store slice
- Beamline dialog → Beamline store: edits · Schema dialog edits beamline configuration
- Detector dialog → Detector store: edits · Schema dialog edits detector configuration
- Calibrant dialog → Preset manager: selects · Calibrant dialog uses preset data
- Preset manager → Beamline store: seeds · Preset selection initializes configuration
- Preset manager → Detector store: seeds · Preset selection initializes detector config
- Persistence → Beamline store: hydrates · Persisted settings restore beamline state
- Persistence → Beamstop store: hydrates · Persisted settings restore beamstop state
- Persistence → Camera store: hydrates · Persisted settings restore camera tube state
- Persistence → Detector store: hydrates · Persisted settings restore detector state
- Beamline store → Math core: feeds · Beamline geometry contributes to calculations
- Beamstop store → Math core: feeds · Beamstop geometry contributes to calculations
- Camera store → Math core: feeds · Camera tube geometry contributes to calculations
- Detector store → Math core: feeds · Detector parameters contribute to calculations
- Math core → Plotting: drives · Computed geometry is turned into plot primitives
- Math core → Scattering quantities: derives · Core math produces final scattering quantities
- Plotting → Centre plot: renders · Plotting layer powers the main plot view
- Plotting → Legend bar: renders · Plotting layer powers legends and annotations
- Scattering quantities → Results view: formats · Derived quantities are presented in results views
- Plot store → Plotting: coordinates · Plot state controls interactive rendering
- Shared utils → Beamline dialog: supports · Shared UI helpers support schema dialogs
- Shared utils → Detector dialog: supports · Shared UI helpers support detector dialogs
- Shared utils → Results view: supports · Units and display helpers support results rendering
- Shared utils → Plotting: supports · Shared geometry and styling helpers support plot rendering
