# moses-beniyel/sorting-visualizer architecture

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

- Interactive diagram: https://gitdiagram.com/moses-beniyel/sorting-visualizer
- Repository: https://github.com/moses-beniyel/sorting-visualizer

## Overview

##### Project Type & Purpose
- Type: Full-front-end React single-page application (no custom backend).

##### File Structure & README Insights
- Top-level:
- public/ – static index.html, manifest, robots.txt
- src/ – React components, styles, assets, context provider, test files
- package.json/package-lock.json – Node.js dependencies & scripts
- Key components in src/:
- App.js – root component
- contextProvider.jsx – React Context for global state (array size, speed, current algorithm, array data)
- algorithm modules – bubbleSort/, mergeSort/, insertionSort/, selectionSort/
- codeSnippet/ – displays pseudo-code or source code
- complexity/ – displays time/space complexity info
- navbar.js – UI header & controls
- assets/ – audio file for swap sound
- README notes: built with React.js, CSS animations, deployed live (e.g., Vercel).

##### Main Components & Responsibilities
A. Browser / Hosting Layer
- Static files served (public/index.html, CSS, JS bundles)
- Deployed via Vercel or any static-hosting service
B. React Application
1. Root & Layout
- App.js: sets up layout, imports ContextProvider
- Navbar: controls for array size, speed, regenerate button
2. State Management
- ContextProvider: holds global state & dispatch actions
3. Visualization Panel
- Algorithm components: each sorting folder implements the sorting logic & CSS animations
- Assets: swap.wav triggered on element swaps
4. Info Panels
- CodeSnippet: shows current algorithm code
- Complexity: displays theoretical complexity
5. Interactions & Data Flow
- User → Navbar controls → Context state update → triggers algorithm run → visualization update → CSS animations & sound
C. Build & Dev Pipeline
- Node.js + npm scripts (npm start, npm build)
- Webpack/Babel (via Create-React-App) bundling, hot reload in dev
- package.json lists dependencies (react, react-dom, etc.)

##### Relationships & Data Flows
- User actions → ContextProvider dispatch
- Context state → Algorithm modules (input array, speed)
- Algorithm modules → Visualization Panel updates (React re-render)
- Visualization → CSS animations & swap.wav playback
- Selection in Navbar → triggers CodeSnippet & Complexity Panel updates
- Static asset access: public/index.html → loads main JS/CSS bundles

##### Architectural Patterns & Principles
- Component-based UI (React)
- Unidirectional data flow (Context API, reducer pattern)
- Separation of concerns:
- Presentation (CSS, animations)
- Logic (sorting algorithms)
- State (ContextProvider)
- Single-page app: all routing (if any) handled client-side

##### Must-Include Elements
- Clear labels on all components/containers
- Static Hosting Layer
- React App & its sub-components
- Build/Dev Tools

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Static Hosting Layer
    subgraph "Static Hosting Layer" 
        direction TB
        Browser["Browser"]:::external
        PublicFiles["public/index.html\npublic/manifest.json\npublic/robots.txt"]:::static
    end

    %% Build & Dev Pipeline
    subgraph "Build & Dev Tools" 
        direction TB
        PackageJSON["package.json\npackage-lock.json"]:::build
        TestSetup["src/App.test.js\nsrc/setupTests.js\nsrc/reportWebVitals.js"]:::build
    end

    %% React Application
    subgraph "React Application" 
        direction TB
        Entry["src/index.js\nsrc/index.css"]:::entry
        App["src/App.js\nsrc/App.css"]:::root
        Context["ContextProvider"]:::state
        Navbar["Navbar"]:::ui
        subgraph "Visualization Panel" 
            direction TB
            Bubble["BubbleSort Module"]:::logic
            Merge["MergeSort Module"]:::logic
            Insertion["InsertionSort Module"]:::logic
            Selection["SelectionSort Module"]:::logic
            Asset["swap.wav"]:::asset
        end
        subgraph "Info Panels" 
            direction TB
            CodeSnippet["CodeSnippet Panel"]:::ui
            Complexity["Complexity Panel"]:::ui
        end
    end

    %% Relationships
    Browser -->|"loads static files"| PublicFiles
    PublicFiles -->|"serves JS/CSS bundles"| Entry
    PackageJSON -->|"npm build / start"| Entry
    TestSetup -->|"runs tests"| Entry

    Entry -->|"renders"| App
    App -->|"wraps with"| Context
    Context -->|"provides state to"| Navbar
    Context -->|"provides state to"| Bubble
    Context -->|"provides state to"| Merge
    Context -->|"provides state to"| Insertion
    Context -->|"provides state to"| Selection
    Navbar -->|"dispatch(action)"| Context
    Context -->|"passes props/state"| CodeSnippet
    Context -->|"passes props/state"| Complexity

    Bubble -->|"updates UI"| App
    Merge -->|"updates UI"| App
    Insertion -->|"updates UI"| App
    Selection -->|"updates UI"| App

    Bubble -->|"CSS animation"| App
    Merge -->|"CSS animation"| App
    Insertion -->|"CSS animation"| App
    Selection -->|"CSS animation"| App

    Bubble -->|"play swap.wav"| Asset
    Merge -->|"play swap.wav"| Asset
    Insertion -->|"play swap.wav"| Asset
    Selection -->|"play swap.wav"| Asset

    %% Click events
    click PublicFiles "https://github.com/moses-beniyel/sorting-visualizer/blob/main/public/index.html"
    click PackageJSON "https://github.com/moses-beniyel/sorting-visualizer/blob/main/package.json"
    click TestSetup "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/App.test.js"
    click Entry "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/index.js"
    click App "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/App.js"
    click Context "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/contextProvider.jsx"
    click Navbar "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/navbar.js"
    click Bubble "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/bubbleSort/bubbleSort.js"
    click Merge "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/mergeSort/mergesort.js"
    click Insertion "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/insertionSort/insertionSort.js"
    click Selection "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/selectionSort/selectionSort.js"
    click CodeSnippet "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/codeSnippet/CodeSnippet.js"
    click Complexity "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/complexity/complexity.js"
    click Asset "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/assets/swap.wav"
    click PackageJSON "https://github.com/moses-beniyel/sorting-visualizer/blob/main/package-lock.json"
    click Entry "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/index.css"
    click App "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/App.css"
    click Navbar "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/navbar.css"
    click Bubble "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/bubbleSort/bubbleSort.css"
    click Merge "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/mergeSort/mergeSort.css"
    click Insertion "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/insertionSort/insertionSort.css"
    click Selection "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/selectionSort/selectionSort.css"
    click CodeSnippet "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/codeSnippet/CodeSnippet.css"
    click Complexity "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/complexity/complexity.css"
    click TestSetup "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/setupTests.js"
    click TestSetup "https://github.com/moses-beniyel/sorting-visualizer/blob/main/src/reportWebVitals.js"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef static fill:#ddd,stroke:#333,stroke-width:1px
    classDef build fill:#bbb,stroke:#333,stroke-width:1px
    classDef entry fill:#eee,stroke:#333,stroke-width:1px
    classDef root fill:#efe,stroke:#333,stroke-width:1px
    classDef state fill:#cfc,stroke:#333,stroke-width:1px
    classDef ui fill:#bbf,stroke:#333,stroke-width:1px
    classDef logic fill:#fc8,stroke:#333,stroke-width:1px
    classDef asset fill:#ccc,stroke:#333,stroke-width:1px
```
