# varphi-online/wgraphc architecture

> Architecture diagram of the GitHub repository varphi-online/wgraphc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varphi-online/wgraphc
- Repository: https://github.com/varphi-online/wgraphc

## Overview

##### Frontend Layer
- HTML5 Canvas component for visualization
- TypeScript interfaces (from src/*.ts files)
- UI components (metaUI)

##### WebAssembly Bridge
- This in the middle as an intermediate layer
- Wasm.ts bridge file that handles WASM-JS communication
- Pkg/ directory components that facilitate the bridge

##### Rust Core (Backend)
- Split into two main modules:
a. Parser Module
b. Graph Module

##### Component Relationships

**[HTML5 Canvas] ←→ [Graph Renderer (TS)]**
- ↑               ↑

**[MetaUI (TS)] ←→ [WASM Bridge]**
- ↑

- [Rust Core (WASM)]
- /              \
**[Parser Module]    [Graph Module]**

##### Detailed Breakdown

Parser Module (Show as a subsystem):
- Lexer (lexer.rs)
- Tokenizer (tokenizer.rs)
- Evaluator (evaluator.rs)
- AST Structures (structs/)

Graph Module (Show as a subsystem):
- Grapher (grapher.rs)
- Variables (variables.rs)

Important Implementation Details to Note:
- Transformation pipeline from mathematical expression to visualization
- Complex number handling capabilities
- Grid system and viewport management
- Relationship between the canvas rendering and WASM calculations

Key Technical Considerations:
- UI rendering (TypeScript/JavaScript)
- Mathematical computations (Rust/WASM)
- Expression parsing and evaluation (Rust)

##### Performance Flow
- How expressions are parsed
- Where complex calculations occur
- Demonstrate the rendering pipeline

Remember to:
- Keep the main components clearly separated
- WebAssembly boundary explicitly
- Notes about key mathematical operations
- Where complex number handling occurs

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef wasm fill:#2ecc71,stroke:#27ae60,color:white
    classDef rust fill:#e67e22,stroke:#d35400,color:white
    classDef data fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        Canvas["HTML5 Canvas"]
        GraphRenderer["Graph Renderer"]
        MetaUI["Meta UI Components"]
    end
    
    %% WASM Bridge Layer
    subgraph Bridge
        WasmBridge["WebAssembly Bridge"]
        WasmOutput["WASM Output"]
    end
    
    %% Rust Core Layer
    subgraph RustCore
        CoreLib["Core Library"]
        
        subgraph ParserModule["Parser Module"]
            Lexer["Lexer"]
            Tokenizer["Tokenizer"]
            Evaluator["Evaluator"]
            AST["AST Structures"]
            ExprHandler["Expression Handler"]
            TokenMgr["Token Manager"]
            OpHandler["Operator Handler"]
            ValueProc["Value Processor"]
        end
        
        subgraph GraphModule["Graph Module"]
            Grapher["Grapher"]
            Variables["Variables"]
        end
    end
    
    %% Relationships
    Canvas --> GraphRenderer
    GraphRenderer --> WasmBridge
    MetaUI --> WasmBridge
    WasmBridge --> WasmOutput
    WasmOutput --> CoreLib
    
    CoreLib --> ParserModule
    CoreLib --> GraphModule
    
    Lexer --> Tokenizer
    Tokenizer --> AST
    AST --> Evaluator
    ExprHandler --> Evaluator
    TokenMgr --> Tokenizer
    OpHandler --> Evaluator
    ValueProc --> Evaluator
    
    Evaluator --> Grapher
    Variables --> Grapher
    
    %% Click Events
    click GraphRenderer "https://github.com/varphi-online/wgraphc/blob/main/src/graph.ts"
    click MetaUI "https://github.com/varphi-online/wgraphc/blob/main/src/metaUI.ts"
    click Canvas "https://github.com/varphi-online/wgraphc/blob/main/index.html"
    click WasmBridge "https://github.com/varphi-online/wgraphc/blob/main/src/wasm.ts"
    click WasmOutput "https://github.com/varphi-online/wgraphc/blob/main/pkg/wgraphcal_bg.wasm"
    click ParserModule "https://github.com/varphi-online/wgraphc/blob/main/src/parser/mod.rs"
    click Lexer "https://github.com/varphi-online/wgraphc/blob/main/src/parser/lexer.rs"
    click Tokenizer "https://github.com/varphi-online/wgraphc/blob/main/src/parser/tokenizer.rs"
    click Evaluator "https://github.com/varphi-online/wgraphc/blob/main/src/parser/evaluator.rs"
    click AST "https://github.com/varphi-online/wgraphc/blob/main/src/parser/structs/abstract_syntax_tree.rs"
    click GraphModule "https://github.com/varphi-online/wgraphc/blob/main/src/graph/mod.rs"
    click Grapher "https://github.com/varphi-online/wgraphc/blob/main/src/graph/grapher.rs"
    click Variables "https://github.com/varphi-online/wgraphc/blob/main/src/graph/variables.rs"
    click ExprHandler "https://github.com/varphi-online/wgraphc/blob/main/src/parser/expressions.rs"
    click CoreLib "https://github.com/varphi-online/wgraphc/blob/main/src/lib.rs"
    click TokenMgr "https://github.com/varphi-online/wgraphc/blob/main/src/parser/structs/token.rs"
    click OpHandler "https://github.com/varphi-online/wgraphc/blob/main/src/parser/structs/operator.rs"
    click ValueProc "https://github.com/varphi-online/wgraphc/blob/main/src/parser/structs/value.rs"
    
    %% Style Applications
    class Canvas,GraphRenderer,MetaUI frontend
    class WasmBridge,WasmOutput wasm
    class CoreLib,Lexer,Tokenizer,Evaluator,AST,ExprHandler,TokenMgr,OpHandler,ValueProc,Grapher,Variables rust
    class ParserModule,GraphModule data
```
