# o0phoenix0o/algorithm-visualizer architecture

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

- Interactive diagram: https://gitdiagram.com/o0phoenix0o/algorithm-visualizer
- Repository: https://github.com/o0phoenix0o/algorithm-visualizer

## Overview

##### Project type and purpose
- This is a single‐page, front-end web application (“Algorithm Visualizer”) built with plain HTML5, CSS3, and ES6+ JavaScript.
- Its goal is to let users select, step through, and visually explore classic algorithms (sorting, searching, graphs, trees) via animated canvas renderings and real-time logging.

##### File structure
- Top-level:
- index.html – the entry point and UI scaffold
- Algorithms/ – pure algorithm implementations organized by category (Sorting, Searching, Graphs, Trees, Base)
- Core/ – rendering engine (canvas.js), logging (logger.js), controller glue (script.js), and drawing helpers (sketch.js)
- Data/ – algorithm metadata and configuration (algoData.js & JSON)
- Styles/ – UI styling (style.css) and logger styling (logger.css)
- Patterns: modules are strictly separated by concern—algorithm logic vs. rendering vs. UI vs. data. No backend or database: all runs in the browser.

##### Inspect README for technical details
- Tech stack: HTML5, CSS3, JavaScript (ES6+), Canvas API
- Highlights: interactive UI, step-by-step execution, adjustable speed, modular codebase

a. Main components
- Browser / Host Environment
- UI Layer (index.html + Styles)
- Controller Layer (script.js): manages user events, orchestrates the flow
- Core Services:
– Canvas Renderer (canvas.js + sketch.js)
– Logger Service (logger.js)
- Algorithm Modules (Algorithms/…): sorting, searching, graph, tree engines
- Data Store (algoData.json & algoData.js)
- (Optional) Assets folder if images/SVGs are used
b. Relationships & interactions
1. User clicks/selects algorithm in UI → Controller receives event
2. Controller loads algorithm metadata from Data Store
3. Controller invokes chosen Algorithm Module’s API to generate steps
4. For each algorithm step:
– Controller calls Logger Service to append step info
– Controller listens for playback controls (play/pause/next/prev)
5. UI updates controls and displays code & explanation panels
c. Architectural patterns & principles
- Modular separation of concerns (UI vs. control vs. rendering vs. algorithm logic vs. data)
- Single-page application (SPA) pattern, no server back-end
- Data-driven configuration (algoData.json) for extensibility
d. Key technologies
- HTML5 elements for layout and controls
- CSS3 for styling and theming
- JavaScript ES6 modules for each directory
- Canvas API (2D) for dynamic drawing
- Logger uses DOM manipulation for real-time feedback

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        UI["index.html"]:::ui
        StylesCSS["style.css"]:::ui
        StylesLogger["logger.css"]:::ui
    end

    subgraph "Controller Layer"
        Controller["script.js"]:::controller
    end

    subgraph "Core Services"
        subgraph "Canvas Renderer"
            Canvas["canvas.js"]:::core
            Sketch["sketch.js"]:::core
        end
        Logger["logger.js"]:::core
    end

    subgraph "Algorithm Modules"
        subgraph "Sorting"
            BSort["bubbleSort.js"]:::algo
            HSort["heapSort.js"]:::algo
            ISort["insertionSort.js"]:::algo
            MSort["mergeSort.js"]:::algo
            QSort["quickSort.js"]:::algo
            SSort["selectionSort.js"]:::algo
        end
        subgraph "Searching"
            BSearch["binarySearch.js"]:::algo
            Hash["hashing.js"]:::algo
            LSearch["linearSearch.js"]:::algo
        end
        subgraph "Graphs"
            BFS["BFS.js"]:::algo
            DFS["DFS.js"]:::algo
            Dijkstra["Dijkstra.js"]:::algo
            Kruskal["Kruskal.js"]:::algo
            Prim["Prim.js"]:::algo
            GBase["GraphBase.js"]:::algo
        end
        subgraph "Trees"
            BST["BST.js"]:::algo
            Trav["Traversal.js"]:::algo
            TBase["TreeBase.js"]:::algo
        end
        subgraph "Base"
            Base["Base.js"]:::algo
        end
    end

    subgraph "Data Store"
        AlgoJSON["algoData.json"]:::data
        AlgoJS["algoData.js"]:::data
    end

    UI -->|"user action"| Controller
    Controller -->|"load config"| AlgoJS
    AlgoJS -->|"provide metadata"| Controller
    Controller -->|"invoke algorithm"| Base
    Controller -->|"execute step"| Canvas
    Controller -->|"execute step"| Logger
    Controller -->|"listen controls"| UI
    Canvas -->|"draw frame"| UI
    Logger -->|"log event"| UI

    classDef ui fill:#87CEEB,stroke:#000,stroke-width:1px;
    classDef controller fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef core fill:#32CD32,stroke:#000,stroke-width:1px;
    classDef algo fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef data fill:#D3D3D3,stroke:#000,stroke-width:1px;

    click UI "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/index.html"
    click StylesCSS "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Styles/style.css"
    click StylesLogger "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Styles/logger.css"
    click Controller "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Core/script.js"
    click Canvas "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Core/canvas.js"
    click Sketch "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Core/sketch.js"
    click Logger "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Core/logger.js"
    click BSort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/bubbleSort.js"
    click HSort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/heapSort.js"
    click ISort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/insertionSort.js"
    click MSort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/mergeSort.js"
    click QSort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/quickSort.js"
    click SSort "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Sorting/selectionSort.js"
    click BSearch "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Searching/binarySearch.js"
    click Hash "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Searching/hashing.js"
    click LSearch "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Searching/linearSearch.js"
    click BFS "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/BFS.js"
    click DFS "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/DFS.js"
    click Dijkstra "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/Dijkstra.js"
    click Kruskal "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/Kruskal.js"
    click Prim "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/Prim.js"
    click GBase "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Graphs/GraphBase.js"
    click BST "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Trees/BST.js"
    click Trav "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Trees/Traversal.js"
    click TBase "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Trees/TreeBase.js"
    click Base "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Algorithms/Base/Base.js"
    click AlgoJSON "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Data/algoData.json"
    click AlgoJS "https://github.com/o0phoenix0o/algorithm-visualizer/blob/main/Data/algoData.js"
```
