# streamlen/sortingalgorithmvisualizer architecture

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

- Interactive diagram: https://gitdiagram.com/streamlen/sortingalgorithmvisualizer
- Repository: https://github.com/streamlen/sortingalgorithmvisualizer

## Overview

##### Overall Project Structure
- The project is organized into separate directories for each visualization type. The “Sorting” directory holds the sorting algorithm visualizer (with sub-files for different algorithms, utility functions, CSS, and its own HTML page), and the “QuadTree in Javascript” directory contains its own HTML, CSS, and JavaScript implementation.
- In addition, there are top-level shared CSS and JavaScript files (for navigation, etc.) as well as a global index.html, suggesting that there is a common home page or navigation framework that ties the different visualizers together.

##### Identifying Main Components
a. User Interface:
- Global Home Page (index.html) which likely acts as an entry point.
- Navigation Bar: Found in the “css” (home.css, nav.css) and “js” (nav.js) files; this provides links between the home page, Sorting visualizer, and QuadTree visualizer.
b. Sorting Algorithm Visualizer:
- Sorting HTML Page (sorting.html).
- Sorting JavaScript Files: These include bubbleSortFlex.js, countingSort.js, insertionSort.js, selectionSort.js, and a common utils.js. Each file implements a specific sorting technique.
- Sorting CSS File: Styling specific to the sorting visualizer is found under “Sorting/css/index.css”.
c. QuadTree Visualizer:
- QuadTree HTML Page (index.html inside the “QuadTree in Javascript” folder).
- QuadTree CSS and JavaScript: “css/index.css” for styles, and “js/quadtree.js” and “js/sketch.js” for the drawing logic and possibly animation.

##### Relationships and Data Flow
- The Navigation Component (using global nav.js and nav.css) directs users to different visualizations.
- Within the Sorting module, user interactions (such as initiating a sort, tweaking visual parameters, or stepping through an algorithm) trigger calls to specific algorithm functions. The results update the DOM, with the visual output styled via sorting.css.
- In parallel, the QuadTree module processes spatial data internally in quadtree.js and renders using sketch.js (possibly leveraging an HTML canvas element) once users navigate to that section.
- There is a clear separation between the two visualization modules, but they share common UI elements and potentially configuration options from the global index.html.

##### Architecture & Patterns
- Modular Design: Each visualization is kept in its own directory—indicating a modular approach. This separation makes it easier to extend or swap components independently.
- Presentation/Logic Separation: HTML and CSS files define the UI layout and styling, while JavaScript files contain the visualization logic (e.g., sorting logic or quadtree processing).
- Clear Data Flow: User actions on the UI trigger JavaScript-based computations (sorting steps or spatial decompositions) which in turn update visual elements.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Navigation & Home Page"
        nav_index["index.html (Global Home Page)"]:::html
        nav_css1["css/home.css (Home Styling)"]:::css
        nav_css2["css/nav.css (Navigation Styling)"]:::css
        nav_js["js/nav.js (Navigation Logic)"]:::js
    end

    subgraph "Sorting Visualizer"
        sorting_html["Sorting/sorting.html (Sorting UI)"]:::html
        sorting_css["Sorting/css/index.css (Sorting CSS)"]:::css
        bubble["Sorting/js/bubbleSortFlex.js"]:::js
        counting["Sorting/js/countingSort.js"]:::js
        insertion["Sorting/js/insertionSort.js"]:::js
        selection["Sorting/js/selectionSort.js"]:::js
        utils["Sorting/js/utils.js"]:::js
        sorting_index["Sorting/js/index.js"]:::js
    end

    subgraph "QuadTree Visualizer"
        quad_html["QuadTree in Javascript/index.html (QuadTree UI)"]:::html
        quad_css["QuadTree in Javascript/css/index.css (QuadTree CSS)"]:::css
        quadtree["QuadTree in Javascript/js/quadtree.js"]:::js
        sketch["QuadTree in Javascript/js/sketch.js"]:::js
    end

    %% Global Navigation arrows
    nav_index -->|"NavigateToSorting"| sorting_html
    nav_index -->|"NavigateToQuadTree"| quad_html

    %% Sorting Visualizer flow
    sorting_html -->|"StartSorting"| bubble
    sorting_html -->|"StartSorting"| counting
    sorting_html -->|"StartSorting"| insertion
    sorting_html -->|"StartSorting"| selection

    bubble -->|"RenderVisualization"| sorting_css
    counting -->|"RenderVisualization"| sorting_css
    insertion -->|"RenderVisualization"| sorting_css
    selection -->|"RenderVisualization"| sorting_css

    sorting_html -->|"ProvidesUtils"| utils
    sorting_html -->|"EntryPoint"| sorting_index

    %% QuadTree Visualizer flow
    quad_html -->|"InitQuadTree"| quadtree
    quad_html -->|"InitSketch"| sketch

    quadtree -->|"RenderVisualization"| quad_css
    sketch -->|"RenderVisualization"| quad_css

    %% Click Events for Navigation & Home Page
    click nav_index "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/index.html"
    click nav_css1 "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/css/home.css"
    click nav_css2 "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/css/nav.css"
    click nav_js "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/js/nav.js"

    %% Click Events for Sorting Visualizer
    click sorting_html "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/sorting.html"
    click sorting_css "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/css/index.css"
    click bubble "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/bubbleSortFlex.js"
    click counting "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/countingSort.js"
    click insertion "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/insertionSort.js"
    click selection "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/selectionSort.js"
    click utils "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/utils.js"
    click sorting_index "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/Sorting/js/index.js"

    %% Click Events for QuadTree Visualizer
    click quad_html "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/QuadTree in Javascript/index.html"
    click quad_css "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/QuadTree in Javascript/css/index.css"
    click quadtree "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/QuadTree in Javascript/js/quadtree.js"
    click sketch "https://github.com/streamlen/sortingalgorithmvisualizer/blob/main/QuadTree in Javascript/js/sketch.js"

    %% Class Definitions
    classDef html fill:#f9f,stroke:#333,stroke-width:2px;
    classDef css fill:#ccf,stroke:#333,stroke-width:2px;
    classDef js fill:#cfc,stroke:#333,stroke-width:2px;

    class nav_index,sorting_html,quad_html html;
    class nav_css1,nav_css2,sorting_css,quad_css css;
    class nav_js,bubble,counting,insertion,selection,utils,sorting_index,quadtree,sketch js;

    %% Additional Styles
    style nav_index fill:#f9f,stroke:#333,stroke-width:2px;
    style nav_css1 fill:#ccf,stroke:#333,stroke-width:2px;
    style nav_css2 fill:#ccf,stroke:#333,stroke-width:2px;
    style nav_js fill:#cfc,stroke:#333,stroke-width:2px;

    style sorting_html fill:#f9f,stroke:#333,stroke-width:2px;
    style sorting_css fill:#ccf,stroke:#333,stroke-width:2px;
    style bubble fill:#cfc,stroke:#333,stroke-width:2px;
    style counting fill:#cfc,stroke:#333,stroke-width:2px;
    style insertion fill:#cfc,stroke:#333,stroke-width:2px;
    style selection fill:#cfc,stroke:#333,stroke-width:2px;
    style utils fill:#cfc,stroke:#333,stroke-width:2px;
    style sorting_index fill:#cfc,stroke:#333,stroke-width:2px;

    style quad_html fill:#f9f,stroke:#333,stroke-width:2px;
    style quad_css fill:#ccf,stroke:#333,stroke-width:2px;
    style quadtree fill:#cfc,stroke:#333,stroke-width:2px;
    style sketch fill:#cfc,stroke:#333,stroke-width:2px;
```
