How pratikpankaj07/dsa-visualizer works
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: App.jsx App shell · useAlgorithmPlayer.js Player hook · DijkstraPage.jsx Dijkstra · RatInMazePage.jsx Maze
Components 17
Runtime
Browser and Vite entrypoint
- Browser · Client-side React app runs entirely in the browser
- Vite · Dev server and bundling boundary
vite.config.js
UI Layer
App shell, pages, and shared interaction components
- Entry · Mounts the React application
src/main.jsx - App shell · Top-level UI composition and view switching
src/App.jsx - App styles · Global app layout and styling
src/App.css - Global styles · Base document and shared styling
src/index.css - Home · Landing page for the visualizer
src/pages/Home.jsx - Dijkstra · Shortest-path visualization screen
src/pages/DijkstraPage.jsx - Maze · Rat in a Maze visualization screen
src/pages/RatInMazePage.jsx - Knapsack · Knapsack DP visualization screen
src/pages/KnapsackPage.jsx - DSU · Disjoint-set visualization screen
src/pages/DSUPage.jsx - Controls · Playback and interaction controls shared across visualizers
src/components/Controls.jsx - Player hook · Advances algorithm steps and manages playback state
src/hooks/useAlgorithmPlayer.js
Algorithms
Pure algorithm engines and simulation state generation
- Dijkstra logic · Generates shortest-path simulation states
src/algorithms/dijkstra.js - Maze logic · Generates recursive maze exploration states
src/algorithms/ratInMaze.js - Knapsack logic · Generates DP table and decision states
src/algorithms/knapsack.js - DSU logic · Generates union-find state transitions
src/algorithms/dsu.js
Connections 26
- 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