Overview
The Interest Store is a Zustand-based state management solution that handles the 3D graph structure of interests and sub-interests. It manages nodes, links, and provides methods for adding and manipulating the graph.Store Interface
Data Structures
InterestNode
InterestLink
Store Methods
addNode
Adds a single node to the graph with automatic positioning and styling.The text label for the node
The ID of the parent node. If provided, creates a link and positions near parent. If null, positions near origin.
The newly created node object with generated ID and calculated position
- Generates a random 7-character ID
- Assigns a random color from the predefined palette
- Sets radius to 1.2 for root nodes (no parent), 0.6 for child nodes
- Positions node near parent (±0.25 units offset) or near origin (±1 unit)
- Automatically creates a link if parentId is provided
- Initializes velocity to zero
addNodes
Batch adds multiple nodes as children of a parent.Array of label strings for the new nodes
The ID of the parent node that all new nodes will connect to
- Iterates through labels and calls
addNodefor each - All nodes share the same parent
- Used when expanding a node with AI-generated sub-interests
setNodes
Replaces the entire nodes array with a new set.The new array of nodes to set
- Overwrites existing nodes completely
- Does not affect links (be careful of orphaned links)
- Useful for loading saved state or resetting to a specific configuration
clear
Resets the store to empty state. Behavior:- Clears all nodes
- Clears all links
- Returns graph to initial empty state
Color Palette
Nodes are randomly assigned colors from this predefined palette:Usage Examples
Creating a Root Node
Expanding a Node
Accessing Graph Data
Resetting the Graph
Position and Physics
The store initializes node positions but does not handle physics simulation. ThePhysicsEngine component in ThreeGraph.tsx modifies node positions and velocities on each frame:
- Spring forces pull connected nodes toward ideal distance (3.5 units)
- Repulsion forces push all nodes apart
- Center attraction gently pulls nodes toward origin
- Damping gradually reduces velocity
Source Code Location
store/useInterestStore.ts:1-96