# chiroyupy/shadeflow architecture

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

- Interactive diagram: https://gitdiagram.com/chiroyupy/shadeflow
- Repository: https://github.com/chiroyupy/shadeflow

## Overview

ShadeFlow is a browser-based node shader editor: users build and inspect a graph, the app compiles it to typed IR and generates shader code, and WebGL2 runs GLSL for the result preview. The UI also supports project files, local autosave, node-level previews, and GLSL/WGSL/HLSL code views; the README documents examples and explanatory notes. Edges follow the sampled calls and explicit README architecture; some UI capabilities and implementation details are unsampled, so uncertain links are omitted.

Main entry points: [`src/App.tsx`](https://github.com/chiroyupy/shadeflow/blob/main/src/App.tsx) (App coordinator), [`src/editor/Editor.tsx`](https://github.com/chiroyupy/shadeflow/blob/main/src/editor/Editor.tsx) (Graph editor), [`src/store/fileActions.ts`](https://github.com/chiroyupy/shadeflow/blob/main/src/store/fileActions.ts) (Project and clipboard actions), [`src/core/compile/lower.ts`](https://github.com/chiroyupy/shadeflow/blob/main/src/core/compile/lower.ts) (Graph lowering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Editor interface"]
  node_app["App coordinator<br/>[App.tsx]"]
  node_editor["Graph editor<br/>[Editor.tsx]"]
  node_shade_node["Shader nodes<br/>[ShadeNode.tsx]"]
  node_node_preview["Node preview view<br/>[NodePreview.tsx]"]
  node_palette["Node palette<br/>[NodePalette.tsx]"]
  node_toolbar["Toolbar<br/>[Toolbar.tsx]"]
  node_code_panel["Code panel<br/>[CodePanel.tsx]"]
  node_context_menu["Context menu<br/>[ContextMenu.tsx]"]
end

subgraph group_state["Project and UI state"]
  node_graph_store["Graph store<br/>[graphStore.ts]"]
  node_ui_store["UI store<br/>[uiStore.ts]"]
  node_file_actions["Project and clipboard actions<br/>[fileActions.ts]"]
end

subgraph group_compiler["Graph compiler"]
  node_graph_model["Graph model<br/>[graph.ts]"]
  node_node_defs["Node definitions<br/>[definition.ts]"]
  node_node_registry["Node registry<br/>[registry.ts]"]
  node_typing["Port typing<br/>[typing.ts]"]
  node_lowering["Graph lowering<br/>[lower.ts]"]
  node_ir_builder["IR builder<br/>[builder.ts]"]
  node_ir["Typed IR<br/>[ir.ts]"]
  node_codegen["Code generation<br/>[emit.ts]"]
  node_glsl["GLSL backend<br/>[glsl.ts]"]
  node_wgsl["WGSL backend<br/>[wgsl.ts]"]
  node_hlsl["HLSL backend<br/>[hlsl.ts]"]
end

subgraph group_rendering["Shader rendering"]
  node_preview_hub["Node preview hub<br/>[previewHub.ts]"]
  node_result_preview["Result preview<br/>[Preview.tsx]"]
  node_shader_canvas["Shader canvas<br/>[ShaderCanvas.tsx]"]
  node_renderer["WebGL renderer<br/>[ShaderRenderer.ts]"]
  node_webgl["WebGL2 context<br/>[gl.ts]"]
end

node_user(("Shader author"))
node_browser_storage[("Browser local storage")]
node_project_files["JSON project files"]

node_user -->|"edits graph"| node_editor
node_app -->|"renders"| node_editor
node_editor -->|"edits graph state"| node_graph_store
node_editor -->|"renders nodes"| node_shade_node
node_shade_node -->|"renders preview"| node_node_preview
node_node_preview -->|"registers previews"| node_preview_hub
node_app -->|"compiles graph"| node_lowering
node_app -->|"generates GLSL"| node_glsl
node_app -->|"shows result"| node_result_preview
node_app -->|"renders"| node_toolbar
node_app -->|"renders"| node_palette
node_app -->|"renders"| node_code_panel
node_app -->|"renders"| node_context_menu
node_toolbar -->|"runs project actions"| node_file_actions
node_context_menu -->|"runs clipboard actions"| node_file_actions
node_file_actions -->|"replaces graph"| node_graph_store
node_file_actions -->|"sets notices"| node_ui_store
node_graph_store -->|"autosaves project"| node_browser_storage
node_graph_store -->|"parses and serializes"| node_project_files
node_file_actions -->|"imports and exports"| node_project_files
node_lowering -->|"reads graph"| node_graph_model
node_lowering -->|"looks up definitions"| node_node_registry
node_lowering -->|"builds instructions"| node_ir_builder
node_ir_builder -->|"constructs"| node_ir
node_node_registry -->|"registers definitions"| node_node_defs
node_editor -.->|"uses port validation"| node_typing
node_codegen -->|"reads instructions"| node_ir
node_glsl -->|"emits GLSL"| node_codegen
node_wgsl -->|"emits WGSL"| node_codegen
node_hlsl -->|"emits HLSL"| node_codegen
node_preview_hub -->|"subscribes to graph"| node_graph_store
node_preview_hub -->|"compiles node output"| node_lowering
node_result_preview -->|"renders canvas"| node_shader_canvas
node_shader_canvas -->|"draws shader"| node_renderer
node_renderer -->|"creates GL context"| node_webgl

click node_app "https://github.com/chiroyupy/shadeflow/blob/main/src/App.tsx"
click node_editor "https://github.com/chiroyupy/shadeflow/blob/main/src/editor/Editor.tsx"
click node_shade_node "https://github.com/chiroyupy/shadeflow/blob/main/src/editor/ShadeNode.tsx"
click node_node_preview "https://github.com/chiroyupy/shadeflow/blob/main/src/editor/NodePreview.tsx"
click node_palette "https://github.com/chiroyupy/shadeflow/blob/main/src/ui/NodePalette.tsx"
click node_toolbar "https://github.com/chiroyupy/shadeflow/blob/main/src/ui/Toolbar.tsx"
click node_code_panel "https://github.com/chiroyupy/shadeflow/blob/main/src/ui/CodePanel.tsx"
click node_context_menu "https://github.com/chiroyupy/shadeflow/blob/main/src/ui/ContextMenu.tsx"
click node_graph_store "https://github.com/chiroyupy/shadeflow/blob/main/src/store/graphStore.ts"
click node_ui_store "https://github.com/chiroyupy/shadeflow/blob/main/src/store/uiStore.ts"
click node_file_actions "https://github.com/chiroyupy/shadeflow/blob/main/src/store/fileActions.ts"
click node_graph_model "https://github.com/chiroyupy/shadeflow/blob/main/src/core/graph.ts"
click node_node_defs "https://github.com/chiroyupy/shadeflow/blob/main/src/core/nodes/definition.ts"
click node_node_registry "https://github.com/chiroyupy/shadeflow/blob/main/src/core/nodes/registry.ts"
click node_typing "https://github.com/chiroyupy/shadeflow/blob/main/src/core/typing.ts"
click node_lowering "https://github.com/chiroyupy/shadeflow/blob/main/src/core/compile/lower.ts"
click node_ir_builder "https://github.com/chiroyupy/shadeflow/blob/main/src/core/ir/builder.ts"
click node_ir "https://github.com/chiroyupy/shadeflow/blob/main/src/core/ir/ir.ts"
click node_codegen "https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/emit.ts"
click node_glsl "https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/glsl.ts"
click node_wgsl "https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/wgsl.ts"
click node_hlsl "https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/hlsl.ts"
click node_preview_hub "https://github.com/chiroyupy/shadeflow/blob/main/src/render/previewHub.ts"
click node_result_preview "https://github.com/chiroyupy/shadeflow/blob/main/src/ui/Preview.tsx"
click node_shader_canvas "https://github.com/chiroyupy/shadeflow/blob/main/src/render/ShaderCanvas.tsx"
click node_renderer "https://github.com/chiroyupy/shadeflow/blob/main/src/render/ShaderRenderer.ts"
click node_webgl "https://github.com/chiroyupy/shadeflow/blob/main/src/render/gl.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_app,node_editor,node_shade_node,node_node_preview,node_palette,node_toolbar,node_code_panel,node_context_menu toneBlue
class node_graph_store,node_ui_store,node_file_actions,node_browser_storage toneAmber
class node_graph_model,node_node_defs,node_node_registry,node_typing,node_lowering,node_ir_builder,node_ir,node_codegen,node_glsl,node_wgsl,node_hlsl toneMint
class node_preview_hub,node_result_preview,node_shader_canvas,node_renderer,node_webgl toneRose
class node_user,node_project_files toneIndigo
```

## Components

### Editor interface

- [App coordinator](https://github.com/chiroyupy/shadeflow/blob/main/src/App.tsx): `src/App.tsx`
- [Graph editor](https://github.com/chiroyupy/shadeflow/blob/main/src/editor/Editor.tsx): `src/editor/Editor.tsx`
- [Shader nodes](https://github.com/chiroyupy/shadeflow/blob/main/src/editor/ShadeNode.tsx): `src/editor/ShadeNode.tsx`
- [Node preview view](https://github.com/chiroyupy/shadeflow/blob/main/src/editor/NodePreview.tsx): `src/editor/NodePreview.tsx`
- [Node palette](https://github.com/chiroyupy/shadeflow/blob/main/src/ui/NodePalette.tsx): `src/ui/NodePalette.tsx`
- [Toolbar](https://github.com/chiroyupy/shadeflow/blob/main/src/ui/Toolbar.tsx): `src/ui/Toolbar.tsx`
- [Code panel](https://github.com/chiroyupy/shadeflow/blob/main/src/ui/CodePanel.tsx): `src/ui/CodePanel.tsx`
- [Context menu](https://github.com/chiroyupy/shadeflow/blob/main/src/ui/ContextMenu.tsx): `src/ui/ContextMenu.tsx`

### Project and UI state

- [Graph store](https://github.com/chiroyupy/shadeflow/blob/main/src/store/graphStore.ts): `src/store/graphStore.ts`
- [UI store](https://github.com/chiroyupy/shadeflow/blob/main/src/store/uiStore.ts): `src/store/uiStore.ts`
- [Project and clipboard actions](https://github.com/chiroyupy/shadeflow/blob/main/src/store/fileActions.ts): `src/store/fileActions.ts`

### Graph compiler

- [Graph model](https://github.com/chiroyupy/shadeflow/blob/main/src/core/graph.ts): `src/core/graph.ts`
- [Node definitions](https://github.com/chiroyupy/shadeflow/blob/main/src/core/nodes/definition.ts): `src/core/nodes/definition.ts`
- [Node registry](https://github.com/chiroyupy/shadeflow/blob/main/src/core/nodes/registry.ts): `src/core/nodes/registry.ts`
- [Port typing](https://github.com/chiroyupy/shadeflow/blob/main/src/core/typing.ts): `src/core/typing.ts`
- [Graph lowering](https://github.com/chiroyupy/shadeflow/blob/main/src/core/compile/lower.ts): `src/core/compile/lower.ts`
- [IR builder](https://github.com/chiroyupy/shadeflow/blob/main/src/core/ir/builder.ts): `src/core/ir/builder.ts`
- [Typed IR](https://github.com/chiroyupy/shadeflow/blob/main/src/core/ir/ir.ts): `src/core/ir/ir.ts`
- [Code generation](https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/emit.ts): `src/core/codegen/emit.ts`
- [GLSL backend](https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/glsl.ts): `src/core/codegen/glsl.ts`
- [WGSL backend](https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/wgsl.ts): `src/core/codegen/wgsl.ts`
- [HLSL backend](https://github.com/chiroyupy/shadeflow/blob/main/src/core/codegen/hlsl.ts): `src/core/codegen/hlsl.ts`

### Shader rendering

- [Node preview hub](https://github.com/chiroyupy/shadeflow/blob/main/src/render/previewHub.ts): `src/render/previewHub.ts`
- [Result preview](https://github.com/chiroyupy/shadeflow/blob/main/src/ui/Preview.tsx): `src/ui/Preview.tsx`
- [Shader canvas](https://github.com/chiroyupy/shadeflow/blob/main/src/render/ShaderCanvas.tsx): `src/render/ShaderCanvas.tsx`
- [WebGL renderer](https://github.com/chiroyupy/shadeflow/blob/main/src/render/ShaderRenderer.ts): `src/render/ShaderRenderer.ts`
- [WebGL2 context](https://github.com/chiroyupy/shadeflow/blob/main/src/render/gl.ts): `src/render/gl.ts`

### Other components

- **Shader author**
- **Browser local storage**
- **JSON project files**

## Connections

- Shader author → Graph editor: edits graph (evidence: `README.md`)
- App coordinator → Graph editor: renders (evidence: `src/App.tsx`)
- Graph editor → Graph store: edits graph state (evidence: `src/editor/Editor.tsx`)
- Graph editor → Shader nodes: renders nodes (evidence: `src/editor/Editor.tsx`)
- Shader nodes → Node preview view: renders preview (evidence: `src/editor/ShadeNode.tsx`)
- Node preview view → Node preview hub: registers previews (evidence: `src/editor/NodePreview.tsx`)
- App coordinator → Graph lowering: compiles graph (evidence: `src/App.tsx`)
- App coordinator → GLSL backend: generates GLSL (evidence: `src/App.tsx`)
- App coordinator → Result preview: shows result (evidence: `src/App.tsx`)
- App coordinator → Toolbar: renders (evidence: `src/App.tsx`)
- App coordinator → Node palette: renders (evidence: `src/App.tsx`)
- App coordinator → Code panel: renders (evidence: `src/App.tsx`)
- App coordinator → Context menu: renders (evidence: `src/App.tsx`)
- Toolbar → Project and clipboard actions: runs project actions (evidence: `src/ui/Toolbar.tsx`)
- Context menu → Project and clipboard actions: runs clipboard actions (evidence: `src/ui/ContextMenu.tsx`)
- Project and clipboard actions → Graph store: replaces graph (evidence: `src/store/fileActions.ts`)
- Project and clipboard actions → UI store: sets notices (evidence: `src/store/fileActions.ts`)
- Graph store → Browser local storage: autosaves project (evidence: `src/store/graphStore.ts`)
- Graph store → JSON project files: parses and serializes (evidence: `src/store/graphStore.ts`)
- Project and clipboard actions → JSON project files: imports and exports (evidence: `src/store/fileActions.ts`)
- Graph lowering → Graph model: reads graph (evidence: `src/core/compile/lower.ts`)
- Graph lowering → Node registry: looks up definitions (evidence: `src/core/compile/lower.ts`)
- Graph lowering → IR builder: builds instructions (evidence: `src/core/compile/lower.ts`)
- IR builder → Typed IR: constructs (evidence: `src/core/ir/builder.ts`)
- Node registry → Node definitions: registers definitions (evidence: `src/core/nodes/registry.ts`)
- Graph editor → Port typing: uses port validation (evidence: `src/editor/Editor.tsx`)
- Code generation → Typed IR: reads instructions (evidence: `src/core/codegen/emit.ts`)
- GLSL backend → Code generation: emits GLSL (evidence: `src/core/index.ts`)
- WGSL backend → Code generation: emits WGSL (evidence: `src/core/codegen/wgsl.ts`)
- HLSL backend → Code generation: emits HLSL (evidence: `src/core/index.ts`)
- Node preview hub → Graph store: subscribes to graph (evidence: `src/render/previewHub.ts`)
- Node preview hub → Graph lowering: compiles node output (evidence: `src/render/previewHub.ts`)
- Result preview → Shader canvas: renders canvas (evidence: `src/ui/Preview.tsx`)
- Shader canvas → WebGL renderer: draws shader (evidence: `src/ui/Preview.tsx`)
- WebGL renderer → WebGL2 context: creates GL context (evidence: `src/render/ShaderRenderer.ts`)
