# kuser-shared/ncview architecture

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

- Interactive diagram: https://gitdiagram.com/kuser-shared/ncview
- Repository: https://github.com/kuser-shared/ncview

## Overview

ncview is an interactive CNC G-code visualizer. The principal workflow is selecting a file, parsing it into moves, deriving toolpath geometry and timing, then displaying and scrubbing the result. The graph preserves the documented parser, geometry, camera, grid, rendering, and ImGui capabilities. Edges use the supplied app excerpt, SOURCE INDEX references, or README; unsampled loader-to-parser and playback-to-estimator calls are marked unverified rather than asserted.

Main entry points: [`src/app/app.cpp`](https://github.com/kuser-shared/ncview/blob/main/src/app/app.cpp) (App loop), [`src/render/renderer.cpp`](https://github.com/kuser-shared/ncview/blob/main/src/render/renderer.cpp) (Toolpath renderer), [`src/app/loader.cpp`](https://github.com/kuser-shared/ncview/blob/main/src/app/loader.cpp) (File loader), [`src/gcode/move.h`](https://github.com/kuser-shared/ncview/blob/main/src/gcode/move.h) (Move model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["G-code input"]
  node_loader["File loader<br/>[loader.cpp]"]
  node_lexer["G-code lexer<br/>[lexer.cpp]"]
  node_parser["G-code parser<br/>[parser.cpp]"]
  node_moves["Move model<br/>[move.h]"]
end

subgraph group_domain["Toolpath domain"]
  node_flatten["Arc flattening<br/>[flatten.cpp]"]
  node_bounds["Toolpath bounds<br/>[bounds.cpp]"]
  node_cycle["Cycle estimator<br/>[cycle_time.cpp]"]
  node_playback["Playback timeline<br/>[playback.cpp]"]
end

subgraph group_presentation["Visualization"]
  node_camera["Orbit camera<br/>[camera.cpp]"]
  node_math["Vector matrices<br/>[mat4.cpp]"]
  node_grid["Ground grid<br/>[grid.cpp]"]
  node_renderer["Toolpath renderer<br/>[renderer.cpp]"]
  node_shader["Shader program<br/>[shader.cpp]"]
  node_overlay["ImGui overlay<br/>[overlay.cpp]"]
end

subgraph group_runtime["Application runtime"]
  node_app["App loop<br/>[app.cpp]"]
  node_file_dialog["File dialog<br/>[file_dialog.cpp]"]
end

node_user(("CNC user"))

node_user -->|"uses"| node_app
node_app -->|"opens file"| node_file_dialog
node_app -->|"starts and polls"| node_loader
node_loader -->|"uses"| node_lexer
node_loader -.->|"parses file"| node_parser
node_parser -->|"produces moves"| node_moves
node_moves -->|"flattens arcs"| node_flatten
node_moves -->|"computes bounds"| node_bounds
node_flatten -->|"provides segments"| node_cycle
node_app -->|"builds timeline"| node_playback
node_playback -.->|"estimates duration"| node_cycle
node_app -->|"updates camera"| node_camera
node_app -->|"builds and draws"| node_grid
node_app -->|"uploads and draws"| node_renderer
node_renderer -->|"uses program"| node_shader
node_app -->|"draws interface"| node_overlay
node_overlay -->|"controls timeline"| node_playback
node_camera -->|"builds transforms"| node_math
node_renderer -->|"uses matrices"| node_math
node_renderer -->|"renders segments"| node_flatten
node_grid -->|"sizes grid"| node_bounds

click node_app "https://github.com/kuser-shared/ncview/blob/main/src/app/app.cpp"
click node_file_dialog "https://github.com/kuser-shared/ncview/blob/main/src/platform/file_dialog.cpp"
click node_loader "https://github.com/kuser-shared/ncview/blob/main/src/app/loader.cpp"
click node_lexer "https://github.com/kuser-shared/ncview/blob/main/src/gcode/lexer.cpp"
click node_parser "https://github.com/kuser-shared/ncview/blob/main/src/gcode/parser.cpp"
click node_moves "https://github.com/kuser-shared/ncview/blob/main/src/gcode/move.h"
click node_flatten "https://github.com/kuser-shared/ncview/blob/main/src/geometry/flatten.cpp"
click node_bounds "https://github.com/kuser-shared/ncview/blob/main/src/geometry/bounds.cpp"
click node_cycle "https://github.com/kuser-shared/ncview/blob/main/src/estimate/cycle_time.cpp"
click node_playback "https://github.com/kuser-shared/ncview/blob/main/src/app/playback.cpp"
click node_camera "https://github.com/kuser-shared/ncview/blob/main/src/app/camera.cpp"
click node_math "https://github.com/kuser-shared/ncview/blob/main/src/math/mat4.cpp"
click node_grid "https://github.com/kuser-shared/ncview/blob/main/src/render/grid.cpp"
click node_renderer "https://github.com/kuser-shared/ncview/blob/main/src/render/renderer.cpp"
click node_shader "https://github.com/kuser-shared/ncview/blob/main/src/render/shader.cpp"
click node_overlay "https://github.com/kuser-shared/ncview/blob/main/src/ui/overlay.cpp"

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_loader,node_lexer,node_parser,node_moves,node_user toneBlue
class node_flatten,node_bounds,node_cycle,node_playback toneAmber
class node_camera,node_math,node_grid,node_renderer,node_shader,node_overlay toneMint
class node_app,node_file_dialog toneRose
```

## Components

### G-code input

- [File loader](https://github.com/kuser-shared/ncview/blob/main/src/app/loader.cpp): `src/app/loader.cpp`
- [G-code lexer](https://github.com/kuser-shared/ncview/blob/main/src/gcode/lexer.cpp): `src/gcode/lexer.cpp`
- [G-code parser](https://github.com/kuser-shared/ncview/blob/main/src/gcode/parser.cpp): `src/gcode/parser.cpp`
- [Move model](https://github.com/kuser-shared/ncview/blob/main/src/gcode/move.h): `src/gcode/move.h`

### Toolpath domain

- [Arc flattening](https://github.com/kuser-shared/ncview/blob/main/src/geometry/flatten.cpp): `src/geometry/flatten.cpp`
- [Toolpath bounds](https://github.com/kuser-shared/ncview/blob/main/src/geometry/bounds.cpp): `src/geometry/bounds.cpp`
- [Cycle estimator](https://github.com/kuser-shared/ncview/blob/main/src/estimate/cycle_time.cpp): `src/estimate/cycle_time.cpp`
- [Playback timeline](https://github.com/kuser-shared/ncview/blob/main/src/app/playback.cpp): `src/app/playback.cpp`

### Visualization

- [Orbit camera](https://github.com/kuser-shared/ncview/blob/main/src/app/camera.cpp): `src/app/camera.cpp`
- [Vector matrices](https://github.com/kuser-shared/ncview/blob/main/src/math/mat4.cpp): `src/math/mat4.cpp`
- [Ground grid](https://github.com/kuser-shared/ncview/blob/main/src/render/grid.cpp): `src/render/grid.cpp`
- [Toolpath renderer](https://github.com/kuser-shared/ncview/blob/main/src/render/renderer.cpp): `src/render/renderer.cpp`
- [Shader program](https://github.com/kuser-shared/ncview/blob/main/src/render/shader.cpp): `src/render/shader.cpp`
- [ImGui overlay](https://github.com/kuser-shared/ncview/blob/main/src/ui/overlay.cpp): `src/ui/overlay.cpp`

### Application runtime

- [App loop](https://github.com/kuser-shared/ncview/blob/main/src/app/app.cpp): `src/app/app.cpp`
- [File dialog](https://github.com/kuser-shared/ncview/blob/main/src/platform/file_dialog.cpp): `src/platform/file_dialog.cpp`

### Other components

- **CNC user**

## Connections

- CNC user → App loop: uses (evidence: `README.md`)
- App loop → File dialog: opens file (evidence: `src/app/app.cpp`)
- App loop → File loader: starts and polls (evidence: `src/app/app.cpp`)
- File loader → G-code lexer: uses (evidence: `src/app/loader.cpp`)
- File loader → G-code parser: parses file
- G-code parser → Move model: produces moves
- Move model → Arc flattening: flattens arcs
- Move model → Toolpath bounds: computes bounds
- Arc flattening → Cycle estimator: provides segments
- App loop → Playback timeline: builds timeline (evidence: `src/app/app.cpp`)
- Playback timeline → Cycle estimator: estimates duration
- App loop → Orbit camera: updates camera (evidence: `src/app/app.cpp`)
- App loop → Ground grid: builds and draws (evidence: `src/app/app.cpp`)
- App loop → Toolpath renderer: uploads and draws (evidence: `src/app/app.cpp`)
- Toolpath renderer → Shader program: uses program
- App loop → ImGui overlay: draws interface (evidence: `src/app/app.cpp`)
- ImGui overlay → Playback timeline: controls timeline (evidence: `src/ui/overlay.cpp`)
- Orbit camera → Vector matrices: builds transforms
- Toolpath renderer → Vector matrices: uses matrices
- Toolpath renderer → Arc flattening: renders segments
- Ground grid → Toolpath bounds: sizes grid
