# codedeficient/3d-particle-simulator-water architecture

> Architecture diagram of the GitHub repository codedeficient/3d-particle-simulator-water, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codedeficient/3d-particle-simulator-water
- Repository: https://github.com/codedeficient/3d-particle-simulator-water

## Overview

##### Main Components
- Entry Point (index.html): This file sets up the basic HTML structure and likely embeds or references the p5.js library (via CDN) and the custom JavaScript.
- Simulation Logic (sketch.js): Contains the core logic for the 3D particle system. This includes initialization of particles, implementing fluid simulation behavior, mouse tracking, and optimization techniques.
- External Library (p5.js): The project depends on p5.js for rendering, creative coding constructs, and handling of user interactions.
- Browser Environment: The entire system runs within a web browser that provides WebGL support for hardware-accelerated rendering.
- (Implied) Local Server: While not part of the source code, the README mentions that a local server (via Python, Node.js, or VS Code live server) is necessary to execute the project effectively.

##### Relationships and Interactions
- The browser loads index.html, which sets up the canvas and initializes the environment.
- index.html includes or links to sketch.js along with the p5.js library loaded from a CDN.
- sketch.js uses p5.js functions to build the simulation: rendering frames, handling mouse moves, updating particle positions, and applying optimizations (like chunked updates and frustum culling).
- The performance techniques within the code ensure that the computation load is managed dynamically, feeding into the rendering pipeline provided by p5.js.

##### Important Architectural Patterns and Design Principles
- Modular Design: Although the project is small, the separation of the static HTML (for structure) and the dynamic simulation (in sketch.js) reflects separation of concerns.
- Real-time Processing: The simulation demonstrates continuous updates per frame, handling real-time interactions in a performance-sensitive context.
- Event-Driven Interactions: The system captures mouse inputs and uses them to drive the simulation.
- Optimization Techniques: Notable patterns include chunked updates, adaptive processing based on frame rate, and culling non-visible particles.

##### Relevant Technologies and Frameworks
- JavaScript is the main programming language.
- p5.js is the key library providing drawing, animation, and interaction capabilities.
- HTML5 (index.html) is used as the hosting document.
- WebGL (through p5.js) supports the 3D and performance requirements of the simulator.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Browser Environment"
        A["index.html (Entry Point)"]:::static
        B["sketch.js (Simulation Logic)\n[Chunked Updates, Frustum Culling]"]:::dynamic
    end
    C["p5.js Library"]:::external
    E["Local Server"]:::server
    D["User (Mouse Input)"]:::user

    E -->|"serves"| A
    A -->|"initializes"| B
    A -->|"references"| C
    B -->|"uses"| C
    D -->|"triggers"| B

    click A "https://github.com/codedeficient/3d-particle-simulator-water/blob/main/index.html"
    click B "https://github.com/codedeficient/3d-particle-simulator-water/blob/main/sketch.js"

    classDef static fill:#a2d9ce,stroke:#1abc9c,stroke-width:2px;
    classDef dynamic fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef external fill:#fad7a0,stroke:#f39c12,stroke-width:2px;
    classDef user fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef server fill:#d6dbdf,stroke:#566573,stroke-width:2px;
```
