# kabirsync/particlegarden architecture

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

- Interactive diagram: https://gitdiagram.com/kabirsync/particlegarden
- Repository: https://github.com/kabirsync/particlegarden

## Overview

##### Main System Components

A. Frontend Application Layer
- React Application Core
- Simulation Engine
- UI Components
- Theme System
- Worker System

B. Simulation Core
- Material System
- Behavior System
- Grid Management
- Particle Management

##### Component Relationships

**[Frontend Application Layer]**

- [React Core (App.tsx)]

- [Simulation Engine]
- [Grid System]
- [Particle System]
- [Material System]
- [Behavior System]

- [UI Layer]
- [Material Options]
- [Simulation Controls]
- [Drawing Tools]

- [Theme System]

- [Worker System]

##### Specific Implementation Details

a) Simulation Core:
- Relationship between materials (src/components/simulation/materials)
- Behavior patterns (src/components/simulation/behaviours)
- Demonstrate particle movement and interactions

b) Material System:
- Inheritance from base Material class
- Different material types (Sand, Water, Fire, etc.)
- Behavior associations

c) UI Components:
- Material selection and controls
- Drawing tools and options
- Simulation settings

##### Key Architectural Patterns to Highlight

- Component-based architecture (React)
- Behavior pattern system for particle movement
- State management for simulation
- Worker-based processing for performance
- Theme provider pattern for styling

##### Technical Details

- TypeScript as the primary language
- React for UI framework
- Three.js for rendering
- Web Workers for background processing
- Tailwind CSS for styling

##### Data Flow Indicators

- User input → Simulation state
- Particle behavior calculations
- Material interactions
- Worker communication
- Theme propagation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        App["React Application Core"]
        SimEngine["Simulation Engine"]
        UI["UI Layer"]
        Theme["Theme System"]
        Worker["Worker System"]
    end

    subgraph SimulationCore
        Grid["Grid Management"]
        ParticleSystem["Particle Management"]
        MaterialSystem["Material System"]
        BehaviorSystem["Behavior System"]
    end

    subgraph UIComponents
        MaterialOpt["Material Options"]
        SimControls["Simulation Controls"]
        DrawTools["Drawing Tools"]
    end

    %% Main relationships
    App --> SimEngine
    App --> UI
    App --> Theme
    App --> Worker

    %% Simulation relationships
    SimEngine --> Grid
    SimEngine --> ParticleSystem
    SimEngine --> MaterialSystem
    SimEngine --> BehaviorSystem

    %% UI relationships
    UI --> MaterialOpt
    UI --> SimControls
    UI --> DrawTools

    %% Component interactions
    MaterialSystem <--> BehaviorSystem
    Grid <--> ParticleSystem
    MaterialOpt --> MaterialSystem
    SimControls --> SimEngine
    DrawTools --> Grid

    %% Styling
    classDef core fill:#2b6cb0,stroke:#1d4ed8,color:white
    classDef sim fill:#059669,stroke:#047857,color:white
    classDef ui fill:#d97706,stroke:#b45309,color:white
    classDef theme fill:#eab308,stroke:#ca8a04,color:white
    classDef worker fill:#7c3aed,stroke:#6d28d9,color:white

    class App,SimEngine core
    class Grid,ParticleSystem,MaterialSystem,BehaviorSystem sim
    class UI,MaterialOpt,SimControls,DrawTools ui
    class Theme theme
    class Worker worker

    %% Click events
    click App "https://github.com/kabirsync/particlegarden/blob/main/src/App.tsx"
    click SimEngine "https://github.com/kabirsync/particlegarden/blob/main/src/components/simulation/Simulation.tsx"
    click Grid "https://github.com/kabirsync/particlegarden/blob/main/src/components/simulation/Grid.ts"
    click MaterialSystem "https://github.com/kabirsync/particlegarden/tree/main/src/components/simulation/materials"
    click BehaviorSystem "https://github.com/kabirsync/particlegarden/tree/main/src/components/simulation/behaviours"
    click UI "https://github.com/kabirsync/particlegarden/tree/main/src/components/ui"
    click Theme "https://github.com/kabirsync/particlegarden/blob/main/src/components/theme/ThemeContext.tsx"
    click Worker "https://github.com/kabirsync/particlegarden/blob/main/src/workers/saveWorker.ts"
    click DrawTools "https://github.com/kabirsync/particlegarden/tree/main/src/components/simulation/options"
    click SimControls "https://github.com/kabirsync/particlegarden/blob/main/src/components/simulation/options/SimulationOptionsButton.tsx"
    click MaterialOpt "https://github.com/kabirsync/particlegarden/blob/main/src/components/simulation/options/MaterialOptions.tsx"
```
