How diamondlightsource/dedi-web works
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: app.tsx App layout · qrange.ts Math core · plotter.ts Plotting · beamlineconfigStore.ts Beamline store
Components 25
Shell
Top-level app bootstrap and layout
- App shell · Top-level React entry and app wiring
src/main.tsx - App layout · Main application composition and calculator surface
src/app.tsx - Top bar · Primary application bar and global controls
src/basicAppBar.tsx
Input & config
User-facing configuration entry and preset selection
- Beamline form · Beamline selector and configuration entry
src/data-entry/beamlineSelector.tsx - Beamstop form · Beamstop configuration input
src/data-entry/beamstop.tsx - Camera tube form · Camera tube configuration input
src/data-entry/cameraTube.tsx - Detector form · Detector configuration input
src/data-entry/detector.tsx - Beamline dialog · Schema-driven beamline configuration editor
src/dialogs/beamline/appConfigDialog.tsx - Detector dialog · Schema-driven detector editor and module selection
src/dialogs/detector/detectorDialog.tsx - Calibrant dialog · Calibrant selection and editing UI
src/dialogs/calibrant/calibrantDialog.tsx - Preset manager · Loads and selects built-in presets and config mappings
src/presets/presetManager.ts
State
Domain stores and browser persistence
- Beamline store · Beamline configuration state
src/data-entry/beamlineconfigStore.ts - Beamstop store · Beamstop state slice
src/data-entry/beamstopStore.ts - Camera store · Camera tube state slice
src/data-entry/cameraTubeStore.ts - Detector store · Detector state slice
src/data-entry/detectorStore.ts - Plot store · Interactive plot state slice
src/plot/plotStore.ts - Persistence · Persisted browser settings and configuration wrapper
src/utils/persistedStorage.ts
Computation
Pure calculation and domain math
- Math core · Range, q-space, q-value, ray, and vector calculations
src/calculations/qrange.ts
Output
Rendered plots and result summaries
- Plotting · SVG plot construction, overlays, and segment utilities
src/plot/plotter.ts - Centre plot · Main detector-distance plot view
src/plot/centrePlot.tsx - Legend bar · Auxiliary legend and scale display
src/plot/legendBar.tsx - Results view · Range diagrams, tables, and summary output
src/results/rangeDiagram.tsx - Scattering quantities · Derived output quantities presented to the user
src/results/scatteringQuantities.ts
Shared
Cross-cutting utilities and UI primitives
- Shared utils · Units, styles, colours, info and error components
src/utils/units.ts
Other components
- User · Person configuring the detector calculation
Connections 34
- 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