# hemantmm/sorting-visualizer architecture

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

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

## Overview

##### Project type and purpose
- This is a Next.js-based, client-focused web application for visualizing and comparing sorting algorithms.
- It’s primarily a front-end Single Page Application (SPA) with Server-Side Rendering (SSR) capabilities provided by Next.js. Users interact with UI controls (sliders, selectors) to configure and run different sorting algorithms.

##### File structure
- Top-level config and build files:
- next.config.mjs, tsconfig.json, tailwind.config.ts, postcss.config.mjs
- package.json / lockfile
- “public/”: static assets (images, favicon, etc.)
- “src/app/”: Next.js App Router directory
- layout.tsx – root layout for all pages
- page.tsx – main entry page with the visualizer
- “src/components/”: reusable UI elements
- Input/Select.tsx, Input/Slider.tsx
- “src/context/Visualizer.tsx”: React Context for application state and control logic
- “src/algorithms/”: pure TypeScript modules implementing five sorting algorithms
- “src/lib/”: shared types (types.ts) and utility functions (utils.ts)

##### README for additional insights
- Confirms it’s a Next.js “create-next-app” bootstrap
- No backend or external APIs—entirely client/state driven
- Uses next/font for optimized font loading, Tailwind CSS for styling
- Deployment target: Vercel

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    Browser["Browser"]:::external

    %% Server-side
    subgraph "Server-side"
        NextServer["Next.js Server (SSR + Static)"]:::server
    end

    %% Client Application
    subgraph "Client Application"
        ReactApp["React App (hydrated client bundle)"]:::client
        subgraph "UI Components" 
            Slider["Slider.tsx"]:::ui
            Select["Select.tsx"]:::ui
            VisualDisplay["Visual Display"]:::ui
        end
        VizContext["Visualizer Context (state & control logic)"]:::logic
    end

    %% Algorithm Engine
    subgraph "Sorting Algorithms" 
        bubbleSort["bubbleSort.ts"]:::logic
        insertionSort["insertionSort.ts"]:::logic
        mergeSort["mergeSort.ts"]:::logic
        quickSort["quickSort.ts"]:::logic
        selectionSort["selectionSort.ts"]:::logic
    end

    %% Shared Libraries & Utilities
    subgraph "Shared Lib & Utilities"
        Types["types.ts"]:::logic
        Utils["utils.ts"]:::logic
    end

    %% Styling & Assets
    subgraph "Styling & Assets"
        StylingAssets["Tailwind, CSS, public/"]:::assets
    end

    %% Connections
    Browser -->|"HTTP GET /"| NextServer
    NextServer -->|"HTML + JS bundle"| Browser
    Browser -->|"hydrated app load"| ReactApp
    ReactApp -->|"initialize"| VizContext
    VizContext -->|"invoke sorting"| bubbleSort
    VizContext -->|"invoke sorting"| insertionSort
    VizContext -->|"invoke sorting"| mergeSort
    VizContext -->|"invoke sorting"| quickSort
    VizContext -->|"invoke sorting"| selectionSort
    bubbleSort -->|"steps"| VizContext
    insertionSort -->|"steps"| VizContext
    mergeSort -->|"steps"| VizContext
    quickSort -->|"steps"| VizContext
    selectionSort -->|"steps"| VizContext
    VizContext -->|"state updates"| Slider
    VizContext -->|"state updates"| Select
    Slider -->|"user events"| VizContext
    Select -->|"user events"| VizContext
    ReactApp -->|"imports CSS"| StylingAssets
    NextServer -->|"serves static"| StylingAssets
    VizContext -->|"uses types/utils"| Types
    VizContext -->|"uses types/utils"| Utils
    bubbleSort -->|"uses utils/types"| Types
    insertionSort -->|"uses utils/types"| Types
    mergeSort -->|"uses utils/types"| Types
    quickSort -->|"uses utils/types"| Types
    selectionSort -->|"uses utils/types"| Types

    %% Click Events
    click NextServer "https://github.com/hemantmm/sorting-visualizer/blob/master/next.config.mjs"
    click NextServer "https://github.com/hemantmm/sorting-visualizer/blob/master/postcss.config.mjs"
    click NextServer "https://github.com/hemantmm/sorting-visualizer/tree/master/public/"
    click ReactApp "https://github.com/hemantmm/sorting-visualizer/blob/master/src/app/layout.tsx"
    click ReactApp "https://github.com/hemantmm/sorting-visualizer/blob/master/src/app/page.tsx"
    click ReactApp "https://github.com/hemantmm/sorting-visualizer/blob/master/src/app/globals.css"
    click VizContext "https://github.com/hemantmm/sorting-visualizer/blob/master/src/context/Visualizer.tsx"
    click bubbleSort "https://github.com/hemantmm/sorting-visualizer/blob/master/src/algorithms/bubbleSort.ts"
    click insertionSort "https://github.com/hemantmm/sorting-visualizer/blob/master/src/algorithms/insertionSort.ts"
    click mergeSort "https://github.com/hemantmm/sorting-visualizer/blob/master/src/algorithms/mergeSort.ts"
    click quickSort "https://github.com/hemantmm/sorting-visualizer/blob/master/src/algorithms/quickSort.ts"
    click selectionSort "https://github.com/hemantmm/sorting-visualizer/blob/master/src/algorithms/selectionSort.ts"
    click Slider "https://github.com/hemantmm/sorting-visualizer/blob/master/src/components/Input/Slider.tsx"
    click Select "https://github.com/hemantmm/sorting-visualizer/blob/master/src/components/Input/Select.tsx"
    click StylingAssets "https://github.com/hemantmm/sorting-visualizer/blob/master/tailwind.config.ts"
    click StylingAssets "https://github.com/hemantmm/sorting-visualizer/tree/master/public/"
    click Types "https://github.com/hemantmm/sorting-visualizer/blob/master/src/lib/types.ts"
    click Utils "https://github.com/hemantmm/sorting-visualizer/blob/master/src/lib/utils.ts"

    %% Styles
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef server fill:#B3D4FC,stroke:#333,stroke-width:1px
    classDef client fill:#C7F9CC,stroke:#333,stroke-width:1px
    classDef ui fill:#FFD8A9,stroke:#333,stroke-width:1px
    classDef logic fill:#E2E8F0,stroke:#333,stroke-width:1px
    classDef assets fill:#F0E68C,stroke:#333,stroke-width:1px
```
