# dgreenheck/threejs-particle-fluids architecture

> Architecture diagram of the GitHub repository dgreenheck/threejs-particle-fluids, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dgreenheck/threejs-particle-fluids
- Repository: https://github.com/dgreenheck/threejs-particle-fluids

## Overview

Three.js Particle Fluids is a WebGPU particle-physics library for simulating and rendering liquids, soft bodies, cloth, and smoke. The principal workflow is to configure a Simulation, add particle-based materials or obstacles, advance simulation steps, and render the resulting scene. Internally, shared particle state and solver infrastructure support specialized material systems, spatial queries, and collision handling. The graph reflects documented capabilities and sampled construction/import evidence; several subsystem internals and the Simulation step implementation were not excerpted, so some connections are intentionally omitted or marked unverified.

Main entry points: [`src/simulation/Simulation.ts`](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/simulation/Simulation.ts) (Simulation), [`src/core/particles.ts`](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/particles.ts) (Particle State), [`src/fluids/FluidSystem.ts`](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/FluidSystem.ts) (Fluid Solver), [`src/gas/GasSystem.ts`](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/GasSystem.ts) (Gas and Smoke)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Simulation API"]
  node_simulation["Simulation<br/>[Simulation.ts]"]
  node_handles["Material Handles<br/>[handles.ts]"]
end

subgraph group_engine["Particle Engine"]
  node_particles[("Particle State<br/>[particles.ts]")]
  node_solver["Solver Loop<br/>[loop.ts]"]
  node_grid["Neighbor Grid<br/>[HashGrid.ts]"]
  node_collisions["Collision Systems<br/>[PrimitiveSet.ts]"]
  node_contacts["Contact Solver<br/>[solve.ts]"]
end

subgraph group_materials["Material Solvers"]
  node_fluid["Fluid Solver<br/>[FluidSystem.ts]"]
  node_viscosity["Viscosity Solver<br/>[ViscositySolver.ts]"]
  node_softbody["Softbody Solver<br/>[SoftbodySystem.ts]"]
  node_cloth["Cloth Solver<br/>[ClothSystem.ts]"]
  node_gas["Gas and Smoke<br/>[GasSystem.ts]"]
  node_heat["Heat Transport<br/>[heat.ts]"]
end

subgraph group_rendering["Rendering and Geometry"]
  node_sdf["SDF Baking<br/>[bake.ts]"]
  node_fluid_surface["Fluid Surface"]
  node_surface_field["Surface Field<br/>[SurfaceField.ts]"]
  node_gas_render["Gas Renderers"]
  node_particle_render["Particle Renderer<br/>[particles.ts]"]
end

node_user(("Application"))
node_webgpu["WebGPU Renderer"]

node_user -->|"configures"| node_simulation
node_simulation -->|"manages"| node_handles
node_simulation -->|"creates"| node_particles
node_simulation -.->|"steps with"| node_solver
node_simulation -.->|"constructs"| node_fluid
node_simulation -->|"constructs"| node_softbody
node_simulation -->|"constructs"| node_cloth
node_simulation -.->|"configures"| node_collisions
node_fluid -->|"updates"| node_particles
node_fluid -->|"builds neighbors"| node_grid
node_fluid -.->|"supports viscosity"| node_viscosity
node_softbody -->|"solves against"| node_particles
node_cloth -.->|"constrains"| node_particles
node_gas -->|"uses"| node_particles
node_gas -->|"uses"| node_heat
node_gas -->|"uses fluid API"| node_fluid
node_collisions -->|"tests against"| node_particles
node_contacts -->|"solves contacts"| node_particles
node_solver -.->|"advances"| node_particles
node_sdf -->|"creates fields for"| node_collisions
node_fluid -->|"renders through"| node_fluid_surface
node_fluid_surface -->|"samples"| node_surface_field
node_gas -.->|"renders through"| node_gas_render
node_simulation -->|"creates debug view"| node_particle_render
node_particle_render -->|"reads buffers"| node_particles
node_user -->|"renders scene"| node_webgpu

click node_simulation "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/simulation/Simulation.ts"
click node_handles "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/simulation/handles.ts"
click node_particles "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/particles.ts"
click node_solver "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/loop.ts"
click node_grid "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/hashGrid/HashGrid.ts"
click node_collisions "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/collision/PrimitiveSet.ts"
click node_contacts "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/contact/solve.ts"
click node_fluid "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/FluidSystem.ts"
click node_viscosity "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/ViscositySolver.ts"
click node_softbody "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/softbody/SoftbodySystem.ts"
click node_cloth "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/cloth/ClothSystem.ts"
click node_gas "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/GasSystem.ts"
click node_heat "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/heat.ts"
click node_sdf "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/sdf/bake.ts"
click node_fluid_surface "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/render/FluidSurfaceRenderer.ts"
click node_surface_field "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/render/SurfaceField.ts"
click node_gas_render "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/render/GasVolumeRenderer.ts"
click node_particle_render "https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/render/particles.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_simulation,node_handles toneBlue
class node_particles,node_solver,node_grid,node_collisions,node_contacts toneAmber
class node_fluid,node_viscosity,node_softbody,node_cloth,node_gas,node_heat toneMint
class node_sdf,node_fluid_surface,node_surface_field,node_gas_render,node_particle_render toneRose
class node_user,node_webgpu toneIndigo
```

## Components

### Simulation API

- [Simulation](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/simulation/Simulation.ts): `src/simulation/Simulation.ts`
- [Material Handles](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/simulation/handles.ts): `src/simulation/handles.ts`

### Particle Engine

- [Particle State](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/particles.ts): `src/core/particles.ts`
- [Solver Loop](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/loop.ts): `src/core/loop.ts`
- [Neighbor Grid](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/hashGrid/HashGrid.ts): `src/core/hashGrid/HashGrid.ts`
- [Collision Systems](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/collision/PrimitiveSet.ts): `src/core/collision/PrimitiveSet.ts`
- [Contact Solver](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/core/contact/solve.ts): `src/core/contact/solve.ts`

### Material Solvers

- [Fluid Solver](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/FluidSystem.ts): `src/fluids/FluidSystem.ts`
- [Viscosity Solver](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/ViscositySolver.ts): `src/fluids/ViscositySolver.ts`
- [Softbody Solver](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/softbody/SoftbodySystem.ts): `src/softbody/SoftbodySystem.ts`
- [Cloth Solver](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/cloth/ClothSystem.ts): `src/cloth/ClothSystem.ts`
- [Gas and Smoke](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/GasSystem.ts): `src/gas/GasSystem.ts`
- [Heat Transport](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/heat.ts): `src/gas/heat.ts`

### Rendering and Geometry

- [SDF Baking](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/sdf/bake.ts): `src/sdf/bake.ts`
- [Fluid Surface](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/render/FluidSurfaceRenderer.ts): `src/fluids/render/FluidSurfaceRenderer.ts`
- [Surface Field](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/fluids/render/SurfaceField.ts): `src/fluids/render/SurfaceField.ts`
- [Gas Renderers](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/gas/render/GasVolumeRenderer.ts): `src/gas/render/GasVolumeRenderer.ts`
- [Particle Renderer](https://github.com/dgreenheck/threejs-particle-fluids/blob/main/src/render/particles.ts): `src/render/particles.ts`

### Other components

- **Application**
- **WebGPU Renderer**

## Connections

- Application → Simulation: configures (evidence: `README.md`)
- Simulation → Material Handles: manages (evidence: `src/simulation/Simulation.ts`)
- Simulation → Particle State: creates (evidence: `src/simulation/Simulation.ts`)
- Simulation → Solver Loop: steps with
- Simulation → Fluid Solver: constructs
- Simulation → Softbody Solver: constructs (evidence: `src/simulation/Simulation.ts`)
- Simulation → Cloth Solver: constructs (evidence: `src/simulation/Simulation.ts`)
- Simulation → Collision Systems: configures
- Fluid Solver → Particle State: updates (evidence: `src/fluids/FluidSystem.ts`)
- Fluid Solver → Neighbor Grid: builds neighbors (evidence: `src/fluids/FluidSystem.ts`)
- Fluid Solver → Viscosity Solver: supports viscosity
- Softbody Solver → Particle State: solves against (evidence: `src/softbody/SoftbodySystem.ts`)
- Cloth Solver → Particle State: constrains
- Gas and Smoke → Particle State: uses (evidence: `src/gas/GasSystem.ts`)
- Gas and Smoke → Heat Transport: uses (evidence: `src/gas/GasSystem.ts`)
- Gas and Smoke → Fluid Solver: uses fluid API (evidence: `src/gas/GasSystem.ts`)
- Collision Systems → Particle State: tests against (evidence: `src/core/collision/PrimitiveSet.ts`)
- Contact Solver → Particle State: solves contacts (evidence: `src/core/contact/solve.ts`)
- Solver Loop → Particle State: advances
- SDF Baking → Collision Systems: creates fields for (evidence: `src/sdf/bake.ts`)
- Fluid Solver → Fluid Surface: renders through (evidence: `src/fluids/render/FluidSurfaceRenderer.ts`)
- Fluid Surface → Surface Field: samples (evidence: `src/fluids/render/FluidSurfaceRenderer.ts`)
- Gas and Smoke → Gas Renderers: renders through
- Simulation → Particle Renderer: creates debug view (evidence: `src/simulation/Simulation.ts`)
- Particle Renderer → Particle State: reads buffers (evidence: `src/render/particles.ts`)
- Application → WebGPU Renderer: renders scene (evidence: `README.md`)
