/ ArchitectureOverview.md
ArchitectureOverview.md
  1  # DreamVault Architecture Overview
  2  
  3  ## Component Structure
  4  
  5  ### 1. DreamTalk and DreamSong
  6  - Functional components
  7  - Purely presentational (JSX/CSS)
  8  - Responsible for displaying media content and formatting
  9  
 10  #### DreamTalk
 11  - Displays media files (images, videos)
 12  - Uses React hooks for dynamic content
 13  - Receives media file path and display logic as props
 14  
 15  #### DreamSong
 16  - Displays repository metadata and additional information
 17  - Analogous to DreamTalk in structure and purpose
 18  
 19  ### 2. DreamNode3D (Three.js Object)
 20  - Custom Three.js Object3D subclass
 21  - Represents the 3D structure of a DreamNode
 22  - Responsibilities:
 23    - Manages CSS3DObject for visual representation
 24    - Handles interaction planes for raycasting
 25    - Manages its own position, rotation, and scale in 3D space
 26  
 27  ### 3. DreamNode (React Component)
 28  - Functional component with hooks
 29  - Corresponds to a git repository in the DreamVault
 30  - Responsibilities:
 31    - Creates and manages a DreamNode3D instance
 32    - Uses effects to read metadata from the git repository
 33    - Manages React state and props
 34    - Handles self-contained user interactions (e.g., hover effects) at the React level
 35    - Updates DreamNode3D based on state changes
 36    - Communicates significant events (e.g., clicks) to DreamGraph
 37  
 38  ### 4. DreamSpace
 39  - Main 3D space component
 40  - Uses Three.js for the overall 3D environment
 41  - Manages the Three.js scene, camera, and renderer
 42  - Uses CSS3DRenderer from Three.js to integrate CSS3DObjects
 43  - Handles raycasting for mouse interactions
 44  - Renders DreamNode components
 45  
 46  ### 5. DreamGraph
 47  - Central conductor component for the entire 3D space
 48  - Manages the overall structure and major transformations of DreamNodes
 49  - Responsibilities:
 50    - Maintains the state for all DreamNodes in the scene
 51    - Decides on and initiates major transformations (e.g., repositioning, major scale changes)
 52    - Handles complex interactions that affect multiple DreamNodes
 53    - Provides a centralized event system for communication between DreamNodes and the overall graph
 54    - Manages the high-level user interactions with the entire graph
 55  
 56  ## Integration of React and Three.js
 57  
 58  - DreamNode3D (Three.js object) is created and managed by the DreamNode React component
 59  - React handles component lifecycle and state management
 60  - Three.js handles 3D rendering and low-level interactions
 61  - Use of useRef hook to maintain reference to Three.js objects in React components
 62  - Use of useEffect hook to manage Three.js object lifecycle and updates
 63  
 64  ## State Management
 65  
 66  - React components manage their own local state using useState hook
 67  - DreamSpace manages the overall scene state
 68  - State changes in React components trigger updates to Three.js objects
 69  
 70  ## Interaction Flow
 71  
 72  1. DreamNode initialization:
 73     - DreamNode React component creates a DreamNode3D instance
 74     - Uses useEffect hook to scan repository on mount
 75     - Adds DreamNode3D to the Three.js scene
 76  
 77  2. User interaction:
 78     - User interacts with the DreamNode in 3D space
 79     - DreamSpace handles raycasting to detect interactions
 80     - Interactions are passed to the appropriate DreamNode component
 81     - DreamNode updates its state and the corresponding DreamNode3D object
 82  
 83  3. DreamNode updates:
 84     - DreamNode receives new props or state
 85     - React handles efficient re-rendering of any 2D UI elements
 86     - DreamNode updates its DreamNode3D object, which updates the 3D representation
 87  
 88  ## Key Principles
 89  
 90  1. React Paradigms: Utilize functional components and hooks for efficient state management and side effects.
 91  2. Separation of Concerns: Clear distinction between React components (DreamNode) and Three.js objects (DreamNode3D).
 92  3. Three.js Integration: Use Three.js with CSS3DRenderer for efficient 3D representation of HTML content.
 93  4. Unidirectional Data Flow: Maintain React's unidirectional data flow for predictable state updates.
 94  5. Cohesive 3D Objects: DreamNode3D encapsulates all 3D-related properties and behaviors.
 95  
 96  ## Implementation Strategy
 97  
 98  1. Implement DreamNode3D as a custom Three.js Object3D subclass
 99  2. Develop DreamNode as a React functional component that manages a DreamNode3D instance
100  3. Refactor DreamSpace to work with the new DreamNode and DreamNode3D structure
101  4. Implement raycasting in DreamSpace that interacts with DreamNode3D objects
102  5. Ensure smooth integration between React state management and Three.js object updates
103  6. Optimize performance for handling multiple DreamNodes in 3D space
104  7. Implement advanced features like 3D positioning, rotation, and scaling of DreamNodes
105  
106  This architecture creates a scalable and efficient system that leverages the strengths of both React and Three.js. It allows for complex 3D visualizations of git repositories while maintaining the benefits of React's component-based architecture and state management.