- Fork, create a feature branch and open a pull request against
main. - Add tests and documentation for new features.
- link to the issue you're trying to solve
- Keep requirement checklists updated in PRs so reviewers can verify scope quickly
- Interactive graph editor (Builder) to add nodes and edges with validation.
- JSON import/export compatible with the app schema.
- Framework: Next.js (App Router), React, TypeScript, Tailwind CSS.
- UI library: shadcn components only. Install components with commands like:
pnpm dlx shadcn@latest add buttonpnpm dlx shadcn@latest add selectpnpm dlx shadcn@latest add slider
- Rendering choice: SVG for MVP (vector graphics).
- Rationale: intuitive DOM interactivity, easy styling with Tailwind, straightforward highlighting/animation, good for up to a few hundred elements.
- Canvas considered for future when graphs are very large or need low-level performance rendering.
- Dependencies: keep to a strict minimum; avoid heavy graph libraries.
- TypeScript: strict mode preferred.
npm installnpm run dev
The pathfinding visualization is built on a decoupled architecture that separates the core algorithm logic from the UI rendering. This makes it easy to add new algorithms without changing the UI code. Pure algorithm functions emit trace events, a tracer records the log, a stepper produces visualization states, and UI renders with SVG.
To add a new pathfinding algorithm:
- Create the Algorithm File: Create a new file in
lib/algorithms/core/yourAlgo.ts. - Implement the Algorithm: Implement your algorithm as a pure function with the
PathfindingAlgorithmsignature fromlib/algorithms/types.ts. Calltracefunction for progress events. - Register the Algorithm: In
components/GraphSimulator.tsx, (ALGORITHMSandALGORITHM_NAMES).
- The UI will surface it in the dropdown automatically.
Example:
In lib/algorithms/core/a-star.ts:
import { PathfindingAlgorithm } from '../types';
export const astar: PathfindingAlgorithm = (graph, startId, endId, trace) => {
// trace({ type: 'visit', nodeId: 'A', distance: 10 });
return { path: [], distances: {} };
};In components/GraphSimulator.tsx:
// 1. Import the algorithm
import { astar } from '@/lib/algorithms/core/astar';
// 2. Add it to the maps
const ALGORITHMS: Record<string, PathfindingAlgorithm> = {
dijkstra,
astar, // Add your new algorithm here
};
const ALGORITHM_NAMES: Record<AlgorithmKey, string> = {
dijkstra: 'Dijkstra',
astar: 'A* Search', // And add its display name here
};-
metadata: { directed: boolean; weighted: boolean; name?: string; description?: string }
-
nodes: Array<{ id: string; x: number; y: number; label?: string }> with normalized coordinates in the range [0,1].
-
edges: Array<{ from: string; to: string; weight: number; label?: string }>.
Example:
{
"metadata": { "directed": false, "weighted": true, "name": "Sample" },
"nodes": [
{ "id": "A", "x": 0.1, "y": 0.2, "label": "Start" },
{ "id": "B", "x": 0.7, "y": 0.4 },
{ "id": "C", "x": 0.4, "y": 0.8, "label": "End" }
],
"edges": [
{ "from": "A", "to": "B", "weight": 2 },
{ "from": "A", "to": "C", "weight": 5 },
{ "from": "C", "to": "B", "weight": 1 }
]
}- Tech stack set: Next.js (App Router), React, TypeScript, Tailwind, shadcn
- Rendering backend: SVG chosen and implemented
- Graph schema v1 implemented (graph-level directed/weighted; no per-edge directed override)
- Load sample graph from public/graphs/sample.json
- Import graph (JSON) on the simulator page with validation and toasts (Sonner)
- Dijkstra algorithm implemented with stepper state machine
- Animation controls: Play/Pause, Step, Reset, Speed
- Visual states: current, frontier, visited/finalized, relaxed edges, final path
- Distances shown near nodes
- Start/End selection by clicking nodes (with rings)
- Queue/frontier panel shown
- Minimal pastel UI via shadcn components
- Cross-page graph cache (Builder ↔ Simulator) via localStorage with validation
- Clear graph action in Builder; fallback to sample on simulator
- Contextual tooltips for key actions (Visualizer: click nodes to set start/end; Builder: drag nodes to reposition)
- Keyboard shortcuts (Space, N, R)
- Unit tests for Dijkstra and validators
- Accessibility pass (focus states, aria labels, contrast review)
- Performance validation at stated scale (200/400 elements)
- Optional overlays beyond frontier list (e.g., distances table)
- Visual simulator for shortest‑path algorithms; users select start/end and watch stepwise animation.
-
Load graph JSON, validate schema and weights, and render via SVG with nodes, edges, and weight labels.
-
Controls: Play/Pause, Step, Reset, Speed; node states: frontier, current, visited/finalized, relaxed, final path.
Queue/frontier panel and distance labels near nodes for clarity.
-
Minimal pastel theme with shadcn components; toasts for feedback via Sonner.
-
Tooltips for key actions; keyboard shortcuts (Space, N, R) are optional.
- Smooth interaction for graphs up to ~200 nodes and ~400 edges with SVG.
- Unit tests for all algorithms
- Schema validation when importing
- Page scaffold at
/builderwith header and navigation back to Home - Metadata form (directed, weighted, name, description)
- Add Node form (id, x, y, optional label)
- Add Edge form (from, to, weight, optional label)
- Lists section for nodes and edges with delete actions
- Import JSON (file picker) with validation and toasts (Sonner)
- Export JSON (validates and downloads)
- Local cache sync with Simulator via localStorage (auto-load/save, clear action)
- Background grid in canvas with coordinate ticks (builder-only, subtle and elegant)
- Drag-and-drop nodes on canvas with normalized coordinate updates
- Live inline validation on forms for all constraints (some checks present, complete coverage pending)
- Edit existing node/edge via selection (beyond delete)
- Prevent magic numbers by moving remaining sizes to
lib/graph/graph_constants.ts - Accessibility/keyboard affordances for builder interactions
- Optional: panning/zoom (deferred), grid/snap (deferred)
- Interactive page at /builder to create and edit graphs conforming to the schema, with a clean shadcn + Tailwind UI and minimal dependencies.
-
Forms to add nodes (id, x, y, label) and edges (from, to, weight, label), edit metadata (directed, weighted, name, description), drag nodes on canvas, and export/import JSON.
-
Subtle SVG grid with normalized ticks; coordinates are normalized to and persist on drag.
- Unique, non‑empty node ids; edges reference existing nodes; finite non‑negative weights for Dijkstra; if unweighted, use weight = 1 on export.
- Inline validation messages; non‑blocking toasts for success/fail; focus states and aria labels.
- Define sizes, strokes, grid steps and colors in a constants module used by canvas and builder.
- Export a validated *.json matching the schema; suggested filename: name‑v1.json; import validates and loads or reports errors without mutating state.
- LocalStorage cache with version and timestamp; Simulator ↔ Builder auto‑loads and persists if valid; Clear Graph resets to sample.
- Advanced layout, panning/zoom, undo/redo, bulk editing, and large‑scale rendering are deferred enhancements.
- Use Sonner for non‑blocking toasts with shadcn; see component docs for setup and usage in Next.js.