# muhaibshamsher/mst-kruskal-and-prims architecture

> Architecture diagram of the GitHub repository muhaibshamsher/mst-kruskal-and-prims, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muhaibshamsher/mst-kruskal-and-prims
- Repository: https://github.com/muhaibshamsher/mst-kruskal-and-prims

## Overview

##### Project Type and Purpose
- This is a full-stack, computationally intensive web application that uses WebAssembly to run high-performance MST algorithms (Prim’s and Kruskal’s) written in C++.

##### File Structure
- There are two main sections in the file tree:
- The “Algorithms” directory holds the C++ source files (kruskal.cpp, prims.cpp), related header files in the “Project” directory (kruskal.h, prims.h), and supplementary files like graph.txt and images which likely illustrate the algorithm process or graph data.
- The “Project” directory contains web-specific assets: main.cpp (possibly with application’s entry point for WebAssembly integration), HTML (output.html), JavaScript (output.js and script.js), CSS (style.css), and the compiled WebAssembly module (output.wasm).
- Supporting files like Project PPT and Project Report provide documentation and further context.

##### README for Architectural Insights
- The README clarifies that the application bridges browser-based visualization (via HTML/JS/CSS) with performance-critical calculations executed through WebAssembly.
- It explains the use of two MST algorithms (Prim’s and Kruskal’s) to generate the pipeline network while comparing their performance.
- WebAssembly is central to providing cross-browser compatibility and real-time performance on complex computations.

##### Main Components and Their Relationships
a. Components:
- Web Frontend: HTML page (output.html), CSS (style.css), and JavaScript files (script.js, output.js) responsible for user interaction, input handling, and visualizing the pipeline network.
- WASM Integration: The WebAssembly module (output.wasm) containing the compiled C++ algorithms (from Algorithms/kruskal.cpp and Algorithms/prims.cpp, with corresponding headers in Project) is the core computational engine.
- MST Algorithms: Both Prim’s and Kruskal’s algorithms are embodied in the C++ code. They run in the WASM environment and compute the minimum spanning tree.
- Data Inputs: Graph data (potentially stored in Algorithms/graph.txt) which represents the 2D coordinates for houses and is the basis for MST calculation.
- Additional assets: Documentation, images for visualization, and supplementary files (PPT, report) that outline design and performance comparisons.

b. Relationships and Data Flow:
- The user interacts with the web interface (HTML/CSS/JS) which triggers events (via script.js) that lead to calls to the WebAssembly module.
- Data (graph data) may be loaded into the browser environment and passed as input to the underlying MST algorithm functions via JS-WASM calls.
- The WebAssembly module executes the MST algorithms in C++ (leveraging both Prim’s and Kruskal’s approaches), then returns the computed MST (both in cost and structure) back to the JavaScript layer.
- The JavaScript layer handles the results, compares performance and cost metrics, and updates the web interface (possibly re-rendering the visualization using DOM manipulation or canvas) to show the optimized pipeline network.

- Separation of concerns:
- Integration using WebAssembly: Emphasize that performance-intensive tasks are offloaded to the WASM module.
- Mention that two MST algorithms are deployed concurrently or compared, indicating modularity in how algorithm implementations can be interchanged or benchmarked.
- Cross-browser compatibility and performance optimization goals provided by leveraging WebAssembly.

##### Final Recommendations
- Clear labels for each major component.
- Decision points such as selecting the optimal MST based on cost and performance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    subgraph "User Interaction"
        U["User"]:::user
    end

    %% Frontend Layer
    subgraph "Frontend"
        HTML["output.html"]:::frontend
        CSS["style.css"]:::frontend
        JS["script.js"]:::frontend
        JS2["output.js"]:::frontend
    end

    %% WASM Integration Layer
    subgraph "WASM Integration"
        WASM["WebAssembly Module"]:::wasm
        MAIN["main.cpp"]:::wasm
    end

    %% MST Algorithms Layer
    subgraph "MST Algorithms"
        PRIM_CPP["Prim's Algorithm (prims.cpp)"]:::algorithms
        KRUSKAL_CPP["Kruskal's Algorithm (kruskal.cpp)"]:::algorithms
        PRIM_H["prims.h"]:::algorithms
        KRUSKAL_H["kruskal.h"]:::algorithms
    end

    %% Data & Assets Layer
    subgraph "Data & Assets"
        GRAPH["Graph Data Source (graph.txt)"]:::data
        VIS_ALGO1["Visualization Assets (Algorithms/Images)"]:::data
        VIS_ALGO2["Visualization Assets (Project/Images)"]:::data
        DOC_PPT["Project PPT.pptx"]:::docs
        DOC_REPORT["Project Report.pdf"]:::docs
        DOC_README["README.md"]:::docs
    end

    %% Connections
    U -->|"interacts_with"| HTML
    HTML -->|"triggers_script"| JS
    JS -->|"calls_WASM"| WASM
    MAIN -->|"initializes"| WASM
    GRAPH -->|"supplies_data"| WASM
    WASM -->|"executes_Prim"| PRIM_CPP
    WASM -->|"executes_Kruskal"| KRUSKAL_CPP
    PRIM_CPP -->|"returns_result"| WASM
    KRUSKAL_CPP -->|"returns_result"| WASM
    WASM -->|"updates_output"| JS2
    JS2 -->|"updates_UI"| HTML
    VIS_ALGO1 -->|"renders_visuals"| HTML
    VIS_ALGO2 -->|"renders_visuals"| HTML

    %% Click Events for Frontend Components
    click HTML "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/output.html"
    click CSS "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/style.css"
    click JS "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/script.js"
    click JS2 "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/output.js"

    %% Click Events for WASM Integration Components
    click WASM "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/output.wasm"
    click MAIN "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/main.cpp"

    %% Click Events for MST Algorithms Implementation
    click PRIM_CPP "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Algorithms/prims.cpp"
    click KRUSKAL_CPP "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Algorithms/kruskal.cpp"
    click PRIM_H "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/prims.h"
    click KRUSKAL_H "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project/kruskal.h"

    %% Click Events for Data & Assets Components
    click GRAPH "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Algorithms/graph.txt"
    click VIS_ALGO1 "https://github.com/muhaibshamsher/mst-kruskal-and-prims/tree/main/Algorithms/Images"
    click VIS_ALGO2 "https://github.com/muhaibshamsher/mst-kruskal-and-prims/tree/main/Project/Images"
    click DOC_PPT "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project PPT.pptx"
    click DOC_REPORT "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/Project Report.pdf"
    click DOC_README "https://github.com/muhaibshamsher/mst-kruskal-and-prims/blob/main/README.md"

    %% Styles
    classDef user fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef wasm fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef algorithms fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef data fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef docs fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
