This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Redstring is a React-based cognitive interface for constructing and navigating networks of conceptual nodes. It implements a sophisticated graph-based system where nodes can contain other graphs, enabling hierarchical recursion and composition.
- React 18 with functional components and hooks
- Zustand for state management (
src/store/graphStore.jsx) - React DnD for drag-and-drop interactions
- Vite for build tooling with hot reload
- Vitest for testing
- Framer Motion for animations
- Web Workers for canvas operations (
src/canvasWorker.js)
Prototype/Instance Model: The system uses a dual-layer architecture:
- Node Prototypes (
nodePrototypesMap): Define the "type" of a node (name, color, description, definitions) - Node Instances (
graph.instancesMap): Position and scale data for prototype instances within specific graphs - Edges connect instance IDs, not prototype IDs
Context-Aware Definitions: Nodes can have multiple definition graphs, with context-specific active definitions tracked via nodeDefinitionIndices Map using "nodeId-graphId" composite keys.
Recursive Graph Structure: Nodes can define graphs, and graphs can contain instances of nodes, enabling infinite recursive nesting.
The main orchestration component handling:
- SVG-based graph rendering
- Mouse/touch/keyboard interactions
- Pan/zoom with sophisticated input device detection
- State management coordination
- PieMenu system for contextual actions
- Drag-and-drop operations
Zustand store with SaveCoordinator middleware managing:
- Graph and node prototype data (using Maps for performance)
- UI state (active graph, expanded nodes, saved nodes)
- Tab management for right panel
- Context-aware definition tracking
- SaveCoordinator Middleware: Batches state changes and coordinates saves to prevent performance issues during interactions
- Graph.js: Graph class with nodes/edges Maps
- Node.js: Node class extending Entry with position/definition data
- Edge.js: Edge class with directional arrow system
The handleWheel function in NodeCanvas.jsx implements sophisticated cross-platform input detection:
- Mac Trackpad: Ctrl+scroll triggers zoom, fractional deltas trigger pan
- Mouse Wheel: Large integer deltas trigger zoom
- Pattern Analysis: Maintains rolling history of delta values for reliable device identification
Complex state management for contextual menus:
selectedNodeIdForPieMenu: Target node for menuisTransitioningPieMenu: Animation state managementonExitAnimationComplete: Callback for animation coordination- Dynamic button generation based on node context
- Universe Files:
.redstringformat for complete workspace state - Auto-save: Debounced saves to prevent data loss
- RedstringMenu: Animated header menu with nested submenus for file operations
- Recent Files: Dynamic loading of recent
.redstringfiles
- Context-aware descriptions that adapt to active definition graphs
- Dynamic height calculation using DOM measurement
- "Chin" expansion effect for expanded nodes
- Seamless panel-canvas synchronization
- Live SPARQL Queries: Direct-fetch SPARQL client for real-time queries to Wikidata, DBpedia, and other semantic web endpoints
- Federated Knowledge Import: Mass knowledge cluster import system that discovers semantic relationships and builds comprehensive knowledge graphs
- Cognitive Augmentation: Semantic web infrastructure acts as invisible substrate, reducing free recall burden while increasing discovery opportunities
- Connection Browser: Interface for browsing and selectively materializing semantic web relationships as native Redstring nodes and connections
- Semantic-to-Native Translation: RDF triplets automatically converted to Redstring-native visual elements using appropriate colors and styling
- SaveCoordinator: Centralized save management that coordinates local file saves and Git commits
- Micro-Batching Middleware: Batches rapid state changes within the same event loop tick to prevent excessive hash calculations
- Drag-Aware Saves: Detects drag operations via
isDraggingandphasecontext flags, deferring saves until interaction completes - Viewport Exclusion: Pan/zoom changes excluded from hash calculation to prevent unnecessary saves
- FNV-1a Hashing: Fast hash algorithm for change detection on large state objects
- Context Options: All store actions accept
contextOptionsparameter to control save behavior (isDragging,phase,finalize)
Tests are located in test/ directory:
core/: Unit tests for Graph, Node, Edge classesstore/: Store functionality tests- Component tests alongside components (e.g.,
NodeCanvas.test.jsx)
- State Updates: Always use Zustand store actions, never mutate state directly
- Map Usage: Store uses Maps for performance - ensure proper serialization for file I/O
- Context Awareness: Use composite keys (
"nodeId-graphId") for context-specific state - Animation Coordination: Respect PieMenu animation lifecycle and state transitions
- Input Handling: Consider device-specific behavior in interaction code
- Recursive Safety: Handle infinite nesting cases in graph traversal logic
- Save Context Options: When calling store actions during drag operations, pass
contextOptionswithisDraggingandphaseflags to prevent save-induced performance issues
- Hydrated Nodes: Combine prototype + instance data using
getHydratedNodesForGraphselector - Definition Navigation: Use
onNavigateDefinitioncallbacks for context-aware definition switching - Cleanup: Use
cleanupOrphanedDatafor removing unreferenced prototypes/graphs - Edge Directionality: Arrows stored as Set of node IDs in
edge.directionality.arrowsToward - Composite Keys: Pattern of
"nodeId-graphId"for context-specific state tracking
src/NodeCanvas.jsx: Main rendering and interaction logicsrc/store/graphStore.jsx: State management and data model with SaveCoordinator middlewaresrc/services/SaveCoordinator.js: Centralized save coordination with performance optimizationssrc/core/Graph.js: Core graph data structuresrc/Panel.jsx: Right panel interfacesrc/PieMenu.jsx: Contextual menu systemsrc/services/sparqlClient.js: Direct-fetch SPARQL client for semantic web queriessrc/services/knowledgeFederation.js: Mass knowledge import and cluster analysissrc/services/semanticWebQuery.js: Unified semantic enrichment servicesrc/components/SemanticEditor.jsx: Semantic web integration interfaceaiinstructions.txt: Detailed project philosophy and comprehensive development patternsSAVE_COORDINATOR_README.md: Documentation for save coordination system