# actbit/graphvisualizer architecture

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

- Interactive diagram: https://gitdiagram.com/actbit/graphvisualizer
- Repository: https://github.com/actbit/graphvisualizer

## Overview

##### Main Components
- Frontend/UI Layer: Represented by the GraphVisualizer directory. This layer includes:
⁃ Razor pages/components (e.g., App.razor, MainLayout.razor, various Pages like Home.razor, Graph.razor) that build the UI.
⁃ Static client-side assets (in wwwroot) such as CSS files, JavaScript files (including graph.js and cytoscape scripts), and service-worker files.
⁃ Services (e.g., ScriptLoaderService.cs) that handle client-side scripts and possibly asynchronous operations.
- Domain/Business Logic Layer: Represented by GraphLibrary.
⁃ Core classes such as Node.cs, Edge.cs, and GraphAction.cs. This is the backbone of the graph data model and processing of algorithms.
- Code-Compilation/Execution Component: Within GraphVisualizer there is Compiler.cs and other classes (like CodeChange.cs and InObject.cs) that seem responsible for compiling/executing user-defined algorithms written in C#, then linking back to the GraphLibrary.
- External Libraries & Integrations:
⁃ cytoscape.js (in wwwroot/cytoscape): Handles visual rendering of graphs.
⁃ ZstdSharp and dotnet: Providing compression and other runtime utilities.
- Persistence/URL Sharing: The README describes that graph data and code are saved within a generated URL, so include a component to represent the URL-based state persistence and sharing mechanism.

##### Representing Interactions and Data Flow
- That users interact with the UI (via the web browser) where operations such as node/edge additions, deletions, and algorithm script entry occur.
- The UI layer triggers calls to domain logic in GraphLibrary classes (for example, when a user adds a node or runs an algorithm).
- Demonstrate how the Compiler.cs processes and hands off the user’s submitted C# code (derived from GraphAction) to execute algorithmic steps.
- Integration of external libraries – for example, cytoscape.js receiving data from GraphLibrary and rendering the interactive graph.
- That the URL generation component takes the current state and encodes it for later retrieval.

##### Architectural Patterns & Design Principles
- The separation of concerns is evident: UI (presentation) is cleanly separated from the domain logic (GraphLibrary).
- The system employs an MVC/MVVM-like approach by isolating user interactions (views and services) from business logic and graph manipulations.
- There is an element of extensibility since users can write or modify algorithm code that extends the abstract GraphAction class.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User("User/Browser"):::external

    %% Frontend/Web UI Layer
    subgraph "Frontend/Web UI"
        UI1("App.razor"):::frontend
        UI2("MainLayout.razor"):::frontend
        UI3("NavMenu.razor"):::frontend
        UI4("Pages: Home.razor"):::frontend
        UI5("Pages: Graph.razor"):::frontend
        UI6("Pages: Counter.razor"):::frontend
        UI7("Pages: Weather.razor"):::frontend
        UI8("Static Assets (wwwroot)"):::frontend
        UI8a("graph.js"):::frontend
        UI9("ScriptLoaderService.cs"):::frontend
    end

    %% Graph Domain Library Layer
    subgraph "Graph Domain Library"
        GL1("Node.cs"):::domain
        GL2("Edge.cs"):::domain
        GL3("GraphAction.cs"):::domain
    end

    %% Compiler/Execution Engine Component
    subgraph "Compiler/Execution Engine"
        CE1("Compiler.cs"):::compiler
        CE2("CodeChange.cs"):::compiler
        CE3("InObject.cs"):::compiler
    end

    %% External Services & Integrations
    subgraph "External Services"
        ES1("cytoscape esm"):::external
        ES2("cytoscape umd"):::external
        ES3("Utilities (ZstdSharp,dotnet)"):::external
    end

    %% Persistence/URL Sharing Component
    subgraph "Persistence/URL Generator"
        P1("Program.cs"):::persistence
        P2("Configuration (libman.json)"):::persistence
    end

    %% Data Flow / Connections
    User -->|"input"| UI1
    UI1 -->|"modifyGraph"| GL3
    CE1 -->|"executesAlgorithm"| GL3
    GL3 -->|"graphUpdate"| UI1
    UI9 -->|"loadScripts"| CE1
    UI1 -->|"renderGraph"| ES1
    UI1 -->|"saveState"| P1

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef compiler fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef persistence fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Click Events for Frontend/UI Layer
    click UI1 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/App.razor"
    click UI2 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Layout/MainLayout.razor"
    click UI3 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Layout/NavMenu.razor"
    click UI4 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Pages/Home.razor"
    click UI5 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Pages/Graph.razor"
    click UI6 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Pages/Counter.razor"
    click UI7 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Pages/Weather.razor"
    click UI8 "https://github.com/actbit/graphvisualizer/tree/master/GraphVisualizer/wwwroot"
    click UI8a "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/wwwroot/graph.js"
    click UI9 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Services/ScriptLoaderService.cs"

    %% Click Events for Domain/Business Logic Layer
    click GL1 "https://github.com/actbit/graphvisualizer/blob/master/GraphLibrary/Node.cs"
    click GL2 "https://github.com/actbit/graphvisualizer/blob/master/GraphLibrary/Edge.cs"
    click GL3 "https://github.com/actbit/graphvisualizer/blob/master/GraphLibrary/GraphAction.cs"

    %% Click Events for Code-Compilation/Execution Component
    click CE1 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Compiler.cs"
    click CE2 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/CodeChange.cs"
    click CE3 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/InObject.cs"

    %% Click Events for External Libraries & Integrations
    click ES1 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/wwwroot/cytoscape/cytoscape.esm.mjs"
    click ES2 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/wwwroot/cytoscape/cytoscape.umd.js"

    %% Click Events for Persistence/URL Sharing Component
    click P1 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/Program.cs"
    click P2 "https://github.com/actbit/graphvisualizer/blob/master/GraphVisualizer/libman.json"
```
