# pratikpankaj07/dsa-visualizer architecture

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

- Interactive diagram: https://gitdiagram.com/pratikpankaj07/dsa-visualizer
- Repository: https://github.com/pratikpankaj07/dsa-visualizer

## Overview

1. **Overall shape**  
This is a single-page, front-end-only React application for algorithm visualization. There is no backend, database, or external API layer; all simulation state lives in the browser.

2. **App entry and shell**  
`src/main.jsx` mounts the React app into `index.html`, and `src/App.jsx` is the top-level composition point. `App.css` and `index.css` provide global layout/styling, while `vite.config.js` indicates the project is built and served with Vite.

3. **Navigation / screen structure**  
The UI is organized into a **Home page** plus one page per algorithm: Dijkstra, Rat in a Maze, Knapsack, and DSU. Based on the file structure, the app likely switches between these views inside the React tree rather than relying on a backend or multi-page server architecture.

4. **Page-level orchestration layer**  
Each file in `src/pages/` is a self-contained feature screen. These pages appear to own the algorithm-specific user inputs, local visualization state, and rendering of the algorithm’s canvas/table/graph/tree UI. Their paired CSS files suggest each visualization has its own layout and styling boundary.

5. **Shared interaction controls**  
`src/components/Controls.jsx` is the shared UI control surface for playback and interaction. This is the most obvious reusable boundary across all visualizers: play/pause, step, reset, speed adjustment, and similar simulation controls are likely centralized here so each page does not reimplement them.

6. **Algorithm playback engine**  
`src/hooks/useAlgorithmPlayer.js` is the core cross-cutting abstraction. It likely manages time-based stepping, play/pause state, speed, and iteration through generated algorithm states. Architecturally, it sits between the algorithm logic and the pages, turning a static list of steps into an animated experience.

7. **Algorithm logic layer**  
`src/algorithms/` contains the pure domain logic for each visualization: `dijkstra.js`, `ratInMaze.js`, `knapsack.js`, and `dsu.js`. These modules are the computational boundary of the app: they encode the algorithm behavior and produce the intermediate states that the UI animates.

8. **Data flow pattern**  
The main flow is: **user input on a page → page state updates → algorithm module generates simulation steps/state → `useAlgorithmPlayer` advances through those steps → page renders the current frame**. This separation is important because the UI is not computing the algorithms directly; it is consuming precomputed or incrementally generated states.

9. **Algorithm-specific state models**  
Each visualizer uses a different kind of state representation:
- **Dijkstra**: graph nodes, weighted edges, visited/frontier ordering, and shortest-path highlights.
- **Rat in a Maze**: grid cells, walls/open paths, recursive exploration, dead ends, and backtracking traces.
- **Knapsack**: items, capacity, and a DP table with take/skip decisions.
- **DSU**: parent/rank or parent/size arrays plus set-tree relationships.

10. **Learning-oriented rendering**  
The app is designed to expose algorithm internals rather than just final answers. That means the architecture emphasizes intermediate states, explanation-friendly highlights, and controllable playback over raw performance or server communication.

11. **Technology/runtime boundary**  
The implementation is plain JavaScript with React functional components, CSS, and the browser runtime. There is no indication of state management libraries, server rendering, or API integration, which keeps the architecture compact and client-centric.

12. **What to draw in an architecture diagram**  
A good diagram would show: browser/Vite app entry, `App` as the shell, page components as feature modules, `Controls` and `useAlgorithmPlayer` as shared interaction infrastructure, and the four files in `src/algorithms/` as isolated computation engines feeding page-specific visualizations.

Main entry points: [`src/App.jsx`](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/App.jsx) (App shell), [`src/hooks/useAlgorithmPlayer.js`](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/hooks/useAlgorithmPlayer.js) (Player hook), [`src/pages/DijkstraPage.jsx`](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/DijkstraPage.jsx) (Dijkstra), [`src/pages/RatInMazePage.jsx`](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/RatInMazePage.jsx) (Maze)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_browser(("Browser<br/>runtime"))
  node_vite["Vite<br/>build<br/>[vite.config.js]"]
end

subgraph group_ui["UI Layer"]
  node_main["Entry<br/>bootstrap<br/>[main.jsx]"]
  node_app["App shell<br/>composition<br/>[App.jsx]"]
  node_appcss["App styles<br/>[App.css]"]
  node_globalcss["Global styles<br/>[index.css]"]
  node_home["Home<br/>page<br/>[Home.jsx]"]
  node_dijkstra["Dijkstra<br/>page<br/>[DijkstraPage.jsx]"]
  node_maze["Maze<br/>page<br/>[RatInMazePage.jsx]"]
  node_knapsack["Knapsack<br/>page<br/>[KnapsackPage.jsx]"]
  node_dsu["DSU<br/>page<br/>[DSUPage.jsx]"]
  node_controls["Controls<br/>shared ui<br/>[Controls.jsx]"]
  node_player["Player hook<br/>state hook"]
end

subgraph group_algos["Algorithms"]
  node_dijkstraalgo["Dijkstra logic<br/>algorithm<br/>[dijkstra.js]"]
  node_mazealgo["Maze logic<br/>algorithm<br/>[ratInMaze.js]"]
  node_knapsackalgo["Knapsack logic<br/>algorithm<br/>[knapsack.js]"]
  node_dsualgo["DSU logic<br/>algorithm<br/>[dsu.js]"]
end

node_browser -->|"served by"| node_vite
node_vite -->|"loads"| node_main
node_main -->|"mounts"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_dijkstra
node_app -->|"routes to"| node_maze
node_app -->|"routes to"| node_knapsack
node_app -->|"routes to"| node_dsu
node_app -->|"styles"| node_appcss
node_app -->|"styles"| node_globalcss
node_dijkstra -->|"uses"| node_controls
node_maze -->|"uses"| node_controls
node_knapsack -->|"uses"| node_controls
node_dsu -->|"uses"| node_controls
node_dijkstra -->|"drives"| node_player
node_maze -->|"drives"| node_player
node_knapsack -->|"drives"| node_player
node_dsu -->|"drives"| node_player
node_dijkstra -->|"computes"| node_dijkstraalgo
node_maze -->|"computes"| node_mazealgo
node_knapsack -->|"computes"| node_knapsackalgo
node_dsu -->|"computes"| node_dsualgo
node_player -->|"steps through"| node_dijkstraalgo
node_player -->|"steps through"| node_mazealgo
node_player -->|"steps through"| node_knapsackalgo
node_player -->|"steps through"| node_dsualgo

click node_vite "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/vite.config.js"
click node_main "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/main.jsx"
click node_app "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/App.jsx"
click node_appcss "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/App.css"
click node_globalcss "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/index.css"
click node_home "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/Home.jsx"
click node_dijkstra "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/DijkstraPage.jsx"
click node_maze "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/RatInMazePage.jsx"
click node_knapsack "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/KnapsackPage.jsx"
click node_dsu "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/DSUPage.jsx"
click node_controls "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/components/Controls.jsx"
click node_player "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/hooks/useAlgorithmPlayer.js"
click node_dijkstraalgo "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/dijkstra.js"
click node_mazealgo "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/ratInMaze.js"
click node_knapsackalgo "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/knapsack.js"
click node_dsualgo "https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/dsu.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_vite toneBlue
class node_main,node_app,node_appcss,node_globalcss,node_home,node_dijkstra,node_maze,node_knapsack,node_dsu,node_controls,node_player toneAmber
class node_dijkstraalgo,node_mazealgo,node_knapsackalgo,node_dsualgo toneMint
```

## Components

### Runtime

Browser and Vite entrypoint

- **Browser**: runtime · Client-side React app runs entirely in the browser
- [Vite](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/vite.config.js): build · Dev server and bundling boundary · `vite.config.js`

### UI Layer

App shell, pages, and shared interaction components

- [Entry](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/main.jsx): bootstrap · Mounts the React application · `src/main.jsx`
- [App shell](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/App.jsx): composition · Top-level UI composition and view switching · `src/App.jsx`
- [App styles](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/App.css): style · Global app layout and styling · `src/App.css`
- [Global styles](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/index.css): style · Base document and shared styling · `src/index.css`
- [Home](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/Home.jsx): page · Landing page for the visualizer · `src/pages/Home.jsx`
- [Dijkstra](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/DijkstraPage.jsx): page · Shortest-path visualization screen · `src/pages/DijkstraPage.jsx`
- [Maze](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/RatInMazePage.jsx): page · Rat in a Maze visualization screen · `src/pages/RatInMazePage.jsx`
- [Knapsack](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/KnapsackPage.jsx): page · Knapsack DP visualization screen · `src/pages/KnapsackPage.jsx`
- [DSU](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/pages/DSUPage.jsx): page · Disjoint-set visualization screen · `src/pages/DSUPage.jsx`
- [Controls](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/components/Controls.jsx): shared ui · Playback and interaction controls shared across visualizers · `src/components/Controls.jsx`
- [Player hook](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/hooks/useAlgorithmPlayer.js): state hook · Advances algorithm steps and manages playback state · `src/hooks/useAlgorithmPlayer.js`

### Algorithms

Pure algorithm engines and simulation state generation

- [Dijkstra logic](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/dijkstra.js): algorithm · Generates shortest-path simulation states · `src/algorithms/dijkstra.js`
- [Maze logic](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/ratInMaze.js): algorithm · Generates recursive maze exploration states · `src/algorithms/ratInMaze.js`
- [Knapsack logic](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/knapsack.js): algorithm · Generates DP table and decision states · `src/algorithms/knapsack.js`
- [DSU logic](https://github.com/pratikpankaj07/dsa-visualizer/blob/master/src/algorithms/dsu.js): algorithm · Generates union-find state transitions · `src/algorithms/dsu.js`

## Connections

- Browser → Vite: served by · Vite provides the frontend runtime and build pipeline
- Vite → Entry: loads · Bootstraps the app from the HTML entrypoint
- Entry → App shell: mounts · Renders the React application root
- App shell → Home: routes to · Home is one of the primary views
- App shell → Dijkstra: routes to · Dijkstra page is selected within the app shell
- App shell → Maze: routes to · Maze page is selected within the app shell
- App shell → Knapsack: routes to · Knapsack page is selected within the app shell
- App shell → DSU: routes to · DSU page is selected within the app shell
- App shell → App styles: styles · App-level layout and composition styling
- App shell → Global styles: styles · Shared global document styling
- Dijkstra → Controls: uses · Shared playback and interaction controls
- Maze → Controls: uses · Shared playback and interaction controls
- Knapsack → Controls: uses · Shared playback and interaction controls
- DSU → Controls: uses · Shared playback and interaction controls
- Dijkstra → Player hook: drives · Animation state is advanced through the playback hook
- Maze → Player hook: drives · Animation state is advanced through the playback hook
- Knapsack → Player hook: drives · Animation state is advanced through the playback hook
- DSU → Player hook: drives · Animation state is advanced through the playback hook
- Dijkstra → Dijkstra logic: computes · Produces Dijkstra simulation states
- Maze → Maze logic: computes · Produces maze exploration states
- Knapsack → Knapsack logic: computes · Produces knapsack DP states
- DSU → DSU logic: computes · Produces union-find states
- Player hook → Dijkstra logic: steps through · Consumes generated algorithm frames for playback
- Player hook → Maze logic: steps through · Consumes generated algorithm frames for playback
- Player hook → Knapsack logic: steps through · Consumes generated algorithm frames for playback
- Player hook → DSU logic: steps through · Consumes generated algorithm frames for playback
