# sokmontrey/dynamical-js architecture

> Architecture diagram of the GitHub repository sokmontrey/dynamical-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sokmontrey/dynamical-js
- Repository: https://github.com/sokmontrey/dynamical-js

## Overview

##### Main Architectural Components

The system should be represented as a layered architecture with the following main components:

a. Frontend Layer (Next.js Application)
- UI Components
- Simulation Canvas
- Control Panels
- State Management

b. Core Simulation Engine
- Physics Engine
- Body Management
- Mode Management
- Input Handling

##### Key Relationships

a. Component Hierarchy:
- Main Application Container
- Simulation Canvas ↔ Physics Engine
- Control Panels ↔ State Management
- Mode Manager ↔ Body Manager

b. Data Flow:
- User Input → Input Manager → Mode Manager
- Physics Engine → Body Manager → Renderer
- State Management → UI Components

##### Detailed Component Breakdown

**Frontend Layer:**
- UI Components
- Main Components
- SimulationCanvas
- PropertyPanel
- BodyTreePanel
- SimulationControls
- Common Components
- Input Controls
- UI Elements

**Core Layer:**
- Managers
- BodyManager
- InputManager
- LoopManager
- ModeManager
- Physics Engine
- Body Types
- Point Mass
- Circular Kinematic
- Rigid Constraint
- Simulation Core
- Rendering System
- BodyRenderer
- ModeRenderer
- Canvas Management

##### Implementation Details

Key implementation aspects:
- Next.js app structure
- Hook system integration
- Physics simulation loop
- Body interaction system
- Mode switching mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[UI Layer]
        MC[Main Components]
        CC[Common Components]
        IC["Input Controls"]:::component
        
        subgraph MainComponents
            SC["Simulation Canvas"]:::component
            PP["Property Panel"]:::component
            BTP["Body Tree Panel"]:::component
            SCS["Simulation Controls"]:::component
        end
        
        UI --> MC
        UI --> CC
        UI --> IC
        MC --> MainComponents
    end
    
    subgraph Core
        PE["Physics Engine"]:::component
        CM["Canvas Management"]:::component
        DS["Drawing System"]:::component
        
        PE --> CM
        PE --> DS
    end
    
    subgraph Managers
        BM["Body Manager"]:::component
        IM["Input Manager"]:::component
        LM["Loop Manager"]:::component
        MM["Mode Manager"]:::component
    end
    
    subgraph BodyTypes
        PM["Point Mass"]:::component
        CK["Circular Kinematic"]:::component
        RC["Rigid Constraint"]:::component
    end
    
    subgraph ModeSystem
        CreateM["Create Modes"]:::component
        MoveM["Move Mode"]:::component
        ModeC["Mode Core"]:::component
    end
    
    subgraph RenderingSystem
        BR["Body Renderer"]:::component
        MR["Mode Renderer"]:::component
    end
    
    subgraph StateManagement
        SS["Simulation States"]:::component
        Hooks["Physics Simulation Hooks"]:::component
    end
    
    subgraph Utils
        MU["Math Utilities"]:::component
        VO["Vector Operations"]:::component
        Style["Styling"]:::component
    end
    
    %% Relationships
    SC --> PE
    PE --> BM
    BM --> BR
    IM --> MM
    MM --> ModeC
    PE --> RenderingSystem
    StateManagement --> UI
    
    %% Click Events
    click SC "https://github.com/sokmontrey/dynamical-js/blob/master/src/components/main-component/SimulationCanvas.tsx"
    click PP "https://github.com/sokmontrey/dynamical-js/blob/master/src/components/main-component/PropertyPanel.tsx"
    click BTP "https://github.com/sokmontrey/dynamical-js/blob/master/src/components/main-component/BodyTreePanel.tsx"
    click SCS "https://github.com/sokmontrey/dynamical-js/blob/master/src/components/main-component/SimulationControls.tsx"
    click IC "https://github.com/sokmontrey/dynamical-js/tree/master/src/components/input/"
    click PE "https://github.com/sokmontrey/dynamical-js/tree/master/src/core/"
    click CM "https://github.com/sokmontrey/dynamical-js/blob/master/src/core/Canvas.ts"
    click DS "https://github.com/sokmontrey/dynamical-js/blob/master/src/core/Draw.ts"
    click PM "https://github.com/sokmontrey/dynamical-js/blob/master/src/body/point-mass/Body.ts"
    click CK "https://github.com/sokmontrey/dynamical-js/blob/master/src/body/circular-kinematic/Body.ts"
    click RC "https://github.com/sokmontrey/dynamical-js/blob/master/src/body/rigid-constraint/Body.ts"
    click BM "https://github.com/sokmontrey/dynamical-js/blob/master/src/manager/BodyManager.ts"
    click IM "https://github.com/sokmontrey/dynamical-js/blob/master/src/manager/InputManager.ts"
    click LM "https://github.com/sokmontrey/dynamical-js/blob/master/src/manager/LoopManager.ts"
    click MM "https://github.com/sokmontrey/dynamical-js/blob/master/src/manager/ModeManager.ts"
    click CreateM "https://github.com/sokmontrey/dynamical-js/tree/master/src/mode/create-mode/"
    click MoveM "https://github.com/sokmontrey/dynamical-js/tree/master/src/mode/move-mode/"
    click ModeC "https://github.com/sokmontrey/dynamical-js/blob/master/src/core/Mode.ts"
    click BR "https://github.com/sokmontrey/dynamical-js/blob/master/src/core/BodyRenderer.ts"
    click MR "https://github.com/sokmontrey/dynamical-js/blob/master/src/core/ModeRenderer.ts"
    click SS "https://github.com/sokmontrey/dynamical-js/tree/master/src/states/"
    click Hooks "https://github.com/sokmontrey/dynamical-js/blob/master/src/hooks/usePhysicsSimulation.ts"
    click MU "https://github.com/sokmontrey/dynamical-js/blob/master/src/utils/BasicMath.ts"
    click VO "https://github.com/sokmontrey/dynamical-js/blob/master/src/utils/Vector.ts"
    click Style "https://github.com/sokmontrey/dynamical-js/tree/master/src/style/"
    
    %% Styling
    classDef component fill:#f9f,stroke:#333,stroke-width:2px
    classDef default fill:#fff,stroke:#333,stroke-width:2px
    
    %% Legend
    subgraph Legend
        L1[UI Components]
        L2[Core Components]
        L3[Managers]
        L4[Physics Components]
    end
```
