# visuphy/gaussianbeam architecture

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

- Interactive diagram: https://gitdiagram.com/visuphy/gaussianbeam
- Repository: https://github.com/visuphy/gaussianbeam

## Overview

This is a browser-based Gaussian beam optics simulator. Users configure initial beam parameters and optical elements, run ABCD-matrix propagation, inspect the beam envelope and system parameters in a canvas, plots, and table, then export w(z) and R(z) data as CSV. The main computation and interface logic share script.js, while interactiveCanvas.js handles drawing and drag interaction. README-described plotting and configuration capabilities are included; unsampled implementation details are represented at the enclosing source-file level.

Main entry points: [`script.js`](https://github.com/visuphy/gaussianbeam/blob/main/script.js) (Beam Propagation), [`interactiveCanvas.js`](https://github.com/visuphy/gaussianbeam/blob/main/interactiveCanvas.js) (Canvas Controller), [`index.html`](https://github.com/visuphy/gaussianbeam/blob/main/index.html) (Beam Plots)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["System Configuration"]
  node_webpage["Simulator Page<br/>[index.html]"]
  node_beam_setup["Beam Parameters<br/>[script.js]"]
  node_element_setup["Element Editor<br/>[script.js]"]
  node_system_state["Optical System State<br/>[script.js]"]
end

subgraph group_simulation["Beam Simulation"]
  node_matrix_models["ABCD Element Models<br/>[script.js]"]
  node_propagation["Beam Propagation<br/>[script.js]"]
  node_beam_metrics["Beam Metrics<br/>[script.js]"]
end

subgraph group_visualization["Visualization"]
  node_canvas_controller["Canvas Controller"]
  node_canvas_view["Interactive Canvas<br/>[index.html]"]
  node_plot_views["Beam Plots<br/>[index.html]"]
end

subgraph group_output["Results and Export"]
  node_parameter_table["System Table<br/>[index.html]"]
  node_csv_export["CSV Export<br/>[script.js]"]
end

node_user(("Optics User"))
node_plotly["Plotly.js"]
node_browser_download["Browser Download"]

node_user -->|"opens"| node_webpage
node_user -->|"configures"| node_beam_setup
node_user -->|"edits elements"| node_element_setup
node_beam_setup -->|"updates"| node_system_state
node_element_setup -->|"updates"| node_system_state
node_user -->|"drags elements"| node_system_state
node_system_state -->|"simulates"| node_propagation
node_propagation -->|"applies matrices"| node_matrix_models
node_propagation -->|"derives parameters"| node_beam_metrics
node_propagation -->|"provides plot data"| node_canvas_controller
node_canvas_controller -->|"draws"| node_canvas_view
node_canvas_controller -->|"requests update"| node_propagation
node_beam_metrics -->|"supplies results"| node_plot_views
node_plot_views -->|"renders with"| node_plotly
node_beam_metrics -->|"summarizes"| node_parameter_table
node_beam_metrics -->|"exports data"| node_csv_export
node_csv_export -->|"downloads file"| node_browser_download

click node_webpage "https://github.com/visuphy/gaussianbeam/blob/main/index.html"
click node_beam_setup "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_element_setup "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_system_state "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_matrix_models "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_propagation "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_beam_metrics "https://github.com/visuphy/gaussianbeam/blob/main/script.js"
click node_canvas_controller "https://github.com/visuphy/gaussianbeam/blob/main/interactiveCanvas.js"
click node_canvas_view "https://github.com/visuphy/gaussianbeam/blob/main/index.html"
click node_plot_views "https://github.com/visuphy/gaussianbeam/blob/main/index.html"
click node_parameter_table "https://github.com/visuphy/gaussianbeam/blob/main/index.html"
click node_csv_export "https://github.com/visuphy/gaussianbeam/blob/main/script.js"

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_webpage,node_beam_setup,node_element_setup,node_system_state,node_user,node_browser_download toneBlue
class node_matrix_models,node_propagation,node_beam_metrics toneAmber
class node_canvas_controller,node_canvas_view,node_plot_views toneMint
class node_parameter_table,node_csv_export toneRose
class node_plotly toneIndigo
```

## Components

### System Configuration

- [Simulator Page](https://github.com/visuphy/gaussianbeam/blob/main/index.html): `index.html`
- [Beam Parameters](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`
- [Element Editor](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`
- [Optical System State](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`

### Beam Simulation

- [ABCD Element Models](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`
- [Beam Propagation](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`
- [Beam Metrics](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`

### Visualization

- [Canvas Controller](https://github.com/visuphy/gaussianbeam/blob/main/interactiveCanvas.js): `interactiveCanvas.js`
- [Interactive Canvas](https://github.com/visuphy/gaussianbeam/blob/main/index.html): `index.html`
- [Beam Plots](https://github.com/visuphy/gaussianbeam/blob/main/index.html): `index.html`

### Results and Export

- [System Table](https://github.com/visuphy/gaussianbeam/blob/main/index.html): `index.html`
- [CSV Export](https://github.com/visuphy/gaussianbeam/blob/main/script.js): `script.js`

### Other components

- **Optics User**
- **Plotly.js**
- **Browser Download**

## Connections

- Optics User → Simulator Page: opens (evidence: `README.md`)
- Optics User → Beam Parameters: configures (evidence: `README.md`)
- Optics User → Element Editor: edits elements (evidence: `README.md`)
- Beam Parameters → Optical System State: updates (evidence: `README.md`)
- Element Editor → Optical System State: updates (evidence: `README.md`)
- Optics User → Optical System State: drags elements (evidence: `README.md`)
- Optical System State → Beam Propagation: simulates (evidence: `README.md`)
- Beam Propagation → ABCD Element Models: applies matrices (evidence: `script.js`)
- Beam Propagation → Beam Metrics: derives parameters (evidence: `README.md`)
- Beam Propagation → Canvas Controller: provides plot data (evidence: `script.js`)
- Canvas Controller → Interactive Canvas: draws (evidence: `README.md`)
- Canvas Controller → Beam Propagation: requests update (evidence: `interactiveCanvas.js`)
- Beam Metrics → Beam Plots: supplies results (evidence: `README.md`)
- Beam Plots → Plotly.js: renders with (evidence: `README.md`)
- Beam Metrics → System Table: summarizes (evidence: `README.md`)
- Beam Metrics → CSV Export: exports data (evidence: `README.md`)
- CSV Export → Browser Download: downloads file (evidence: `script.js`)
