The goal of this task was to build an interactive, canvas-based graph editor using ReactFlow, with clean state management and a clear separation between UI components and business logic.
The application allows users to:
- Add and drag nodes on a canvas
- Connect nodes using edges
- Select a node and edit its properties via an inspector panel
- Keep the canvas and inspector in sync reliably
- Chosen for fast development, strong typing, and modern tooling
- TypeScript helps catch UI and state mismatches early
- Used for rendering the interactive graph canvas
- Provides built-in support for dragging, connecting nodes, zooming, and fitView
- Custom logic is layered on top using controlled nodes and edges
- A centralized store (
useGraphStore) manages nodes, edges, and selection state - Avoids prop-drilling and keeps the canvas, sidebar, and inspector synchronized
- Simple, predictable state updates using immutable patterns
The global store manages:
nodesandedges- Selected node ID
- Node updates (label, status, load, config)
- ReactFlow callbacks (
onNodesChange,onEdgesChange,onConnect)
All graph mutations flow through this store, ensuring a single source of truth.
- Renders the ReactFlow canvas
- Receives nodes, edges, and callbacks directly from the store
- Handles user interactions like dragging and connecting nodes
- Reacts to the currently selected node
- Displays editable fields (name, status, load)
- Updates node data via store actions
- Demonstrates controlled inputs and two-way data binding
- Contains global actions like adding a node and fitting the view
- Keeps canvas interactions intuitive and discoverable
- Inspector is only active when a node is selected to reduce clutter
- Default node data is provided to avoid empty or invalid states
- Dashed animated edges help visually distinguish connections
- Layout keeps canvas as the primary focus with secondary controls on the side
- Focused on correctness, clarity, and maintainability rather than advanced styling
- Avoided unnecessary abstractions to keep the code readable
- Designed to be easily extensible (custom node types, persistence, validation)
This solution demonstrates:
- Clean separation of concerns
- Correct usage of ReactFlow as a controlled canvas
- Thoughtful state management using Zustand
- Practical UI decisions aligned with real-world graph editors
The architecture is intentionally simple, predictable, and easy to reason about, making it suitable for further extension in production scenarios.