# bepu/bepuphysics2 architecture

> Architecture diagram of the GitHub repository bepu/bepuphysics2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bepu/bepuphysics2
- Repository: https://github.com/bepu/bepuphysics2

## Overview

BepuPhysics v2 is a C# 3D rigid-body physics engine. A typical user defines shapes and bodies, advances a simulation, and reads updated poses or query results. Its domain stages include collision candidate detection, contact generation, constraint solving, and sleeping/waking; it also supports CCD and scene-wide ray and sweep queries. The graph emphasizes these runtime responsibilities and the SIMD, memory, and scheduling layers that support them. Several subsystem links are documented by the README but their orchestration code was not sampled, so those links are marked unverified.

Main entry points: [`BepuPhysics/Simulation.cs`](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Simulation.cs) (Simulation), [`BepuPhysics/Solver.cs`](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Solver.cs) (Solver), [`BepuPhysics/Bodies.cs`](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Bodies.cs) (Bodies), [`BepuPhysics/CollisionDetection/NarrowPhase.cs`](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/CollisionDetection/NarrowPhase.cs) (Narrow phase)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_world["World State"]
  node_simulation["Simulation<br/>[Simulation.cs]"]
  node_bodies["Bodies<br/>[Bodies.cs]"]
  node_statics["Static geometry<br/>[Statics.cs]"]
  node_shapes["Shape registry<br/>[Shapes.cs]"]
  node_shape_types["Shape types"]
end

subgraph group_collision["Collision and Queries"]
  node_broadphase["Broad phase<br/>[BroadPhase.cs]"]
  node_narrowphase["Narrow phase<br/>[NarrowPhase.cs]"]
  node_collision_tasks["Collision tasks"]
  node_ccd["Continuous collision"]
  node_queries["Scene queries"]
  node_tree["Spatial tree<br/>[Tree.cs]"]
end

subgraph group_solver["Constraint Solver"]
  node_solver["Solver<br/>[Solver.cs]"]
  node_constraint_types["Constraint processors<br/>[TypeProcessor.cs]"]
  node_sleep["Island sleep<br/>[IslandSleeper.cs]"]
  node_awakener["Island wake<br/>[IslandAwakener.cs]"]
  node_timestepper["Timestepper"]
end

subgraph group_runtime["Runtime Foundations"]
  node_wide_math["SIMD math<br/>[Vector3Wide.cs]"]
  node_memory[("Buffer pooling<br/>[BufferPool.cs]")]
  node_collections["Pooled collections<br/>[QuickList.cs]"]
  node_scheduler["Task scheduler<br/>[TaskStack.cs]"]
  node_worker["Worker state<br/>[Worker.cs]"]
end

node_user(("Physics client"))

node_user -.->|"configures and advances"| node_simulation
node_simulation -.->|"updates"| node_bodies
node_simulation -.->|"manages"| node_statics
node_simulation -.->|"steps"| node_solver
node_bodies -->|"computes bounds"| node_shapes
node_bodies -->|"adds active bounds"| node_broadphase
node_shapes -.->|"dispatches by type"| node_shape_types
node_broadphase -.->|"selects candidate pairs"| node_narrowphase
node_narrowphase -.->|"dispatches tests"| node_collision_tasks
node_narrowphase -.->|"produces contact constraints"| node_solver
node_simulation -.->|"supports continuous collision"| node_ccd
node_simulation -.->|"offers ray and sweep queries"| node_queries
node_queries -.->|"traverses"| node_tree
node_solver -->|"creates processors"| node_constraint_types
node_solver -->|"accesses body state"| node_bodies
node_solver -->|"uses island awakening"| node_awakener
node_timestepper -.->|"advances solve"| node_solver
node_simulation -.->|"steps through"| node_timestepper
node_simulation -.->|"supports low-cost sleep"| node_sleep
node_constraint_types -->|"solves against"| node_bodies
node_solver -->|"allocates from"| node_memory
node_constraint_types -->|"uses SIMD vectors"| node_wide_math
node_scheduler -->|"uses worker state"| node_worker
node_worker -->|"allocates worker buffers"| node_memory
node_worker -->|"tracks allocated jobs"| node_collections
node_collections -->|"resizes through pool"| node_memory

click node_simulation "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Simulation.cs"
click node_bodies "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Bodies.cs"
click node_statics "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Statics.cs"
click node_shapes "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Collidables/Shapes.cs"
click node_shape_types "https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/Collidables"
click node_broadphase "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/CollisionDetection/BroadPhase.cs"
click node_narrowphase "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/CollisionDetection/NarrowPhase.cs"
click node_collision_tasks "https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/CollisionDetection/CollisionTasks"
click node_ccd "https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/CollisionDetection"
click node_queries "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Simulation_Queries.cs"
click node_tree "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Trees/Tree.cs"
click node_solver "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Solver.cs"
click node_constraint_types "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Constraints/TypeProcessor.cs"
click node_sleep "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/IslandSleeper.cs"
click node_awakener "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/IslandAwakener.cs"
click node_timestepper "https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/DefaultTimestepper.cs"
click node_wide_math "https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Vector3Wide.cs"
click node_memory "https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Memory/BufferPool.cs"
click node_collections "https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Collections/QuickList.cs"
click node_scheduler "https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/TaskScheduling/TaskStack.cs"
click node_worker "https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/TaskScheduling/Worker.cs"

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_bodies,node_statics,node_shapes,node_shape_types,node_user toneBlue
class node_broadphase,node_narrowphase,node_collision_tasks,node_ccd,node_queries,node_tree toneAmber
class node_solver,node_constraint_types,node_sleep,node_awakener,node_timestepper toneMint
class node_wide_math,node_memory,node_collections,node_scheduler,node_worker toneRose
```

## Components

### World State

- [Simulation](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Simulation.cs): `BepuPhysics/Simulation.cs`
- [Bodies](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Bodies.cs): `BepuPhysics/Bodies.cs`
- [Static geometry](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Statics.cs): `BepuPhysics/Statics.cs`
- [Shape registry](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Collidables/Shapes.cs): `BepuPhysics/Collidables/Shapes.cs`
- [Shape types](https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/Collidables): `BepuPhysics/Collidables`

### Collision and Queries

- [Broad phase](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/CollisionDetection/BroadPhase.cs): `BepuPhysics/CollisionDetection/BroadPhase.cs`
- [Narrow phase](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/CollisionDetection/NarrowPhase.cs): `BepuPhysics/CollisionDetection/NarrowPhase.cs`
- [Collision tasks](https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/CollisionDetection/CollisionTasks): `BepuPhysics/CollisionDetection/CollisionTasks`
- [Continuous collision](https://github.com/bepu/bepuphysics2/tree/master/BepuPhysics/CollisionDetection): `BepuPhysics/CollisionDetection`
- [Scene queries](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Simulation_Queries.cs): `BepuPhysics/Simulation_Queries.cs`
- [Spatial tree](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Trees/Tree.cs): `BepuPhysics/Trees/Tree.cs`

### Constraint Solver

- [Solver](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Solver.cs): `BepuPhysics/Solver.cs`
- [Constraint processors](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/Constraints/TypeProcessor.cs): `BepuPhysics/Constraints/TypeProcessor.cs`
- [Island sleep](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/IslandSleeper.cs): `BepuPhysics/IslandSleeper.cs`
- [Island wake](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/IslandAwakener.cs): `BepuPhysics/IslandAwakener.cs`
- [Timestepper](https://github.com/bepu/bepuphysics2/blob/master/BepuPhysics/DefaultTimestepper.cs): `BepuPhysics/DefaultTimestepper.cs`

### Runtime Foundations

- [SIMD math](https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Vector3Wide.cs): `BepuUtilities/Vector3Wide.cs`
- [Buffer pooling](https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Memory/BufferPool.cs): `BepuUtilities/Memory/BufferPool.cs`
- [Pooled collections](https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/Collections/QuickList.cs): `BepuUtilities/Collections/QuickList.cs`
- [Task scheduler](https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/TaskScheduling/TaskStack.cs): `BepuUtilities/TaskScheduling/TaskStack.cs`
- [Worker state](https://github.com/bepu/bepuphysics2/blob/master/BepuUtilities/TaskScheduling/Worker.cs): `BepuUtilities/TaskScheduling/Worker.cs`

### Other components

- **Physics client**

## Connections

- Physics client → Simulation: configures and advances
- Simulation → Bodies: updates (evidence: `BepuPhysics/Simulation.cs`)
- Simulation → Static geometry: manages (evidence: `BepuPhysics/Simulation.cs`)
- Simulation → Solver: steps (evidence: `BepuPhysics/Simulation.cs`)
- Bodies → Shape registry: computes bounds (evidence: `BepuPhysics/Bodies.cs`)
- Bodies → Broad phase: adds active bounds (evidence: `BepuPhysics/Bodies.cs`)
- Shape registry → Shape types: dispatches by type (evidence: `BepuPhysics/Collidables/Shapes.cs`)
- Broad phase → Narrow phase: selects candidate pairs
- Narrow phase → Collision tasks: dispatches tests
- Narrow phase → Solver: produces contact constraints
- Simulation → Continuous collision: supports continuous collision (evidence: `BepuPhysics/Simulation.cs`)
- Simulation → Scene queries: offers ray and sweep queries
- Scene queries → Spatial tree: traverses
- Solver → Constraint processors: creates processors (evidence: `BepuPhysics/Solver.cs`)
- Solver → Bodies: accesses body state (evidence: `BepuPhysics/Solver.cs`)
- Solver → Island wake: uses island awakening (evidence: `BepuPhysics/Solver.cs`)
- Timestepper → Solver: advances solve
- Simulation → Timestepper: steps through (evidence: `BepuPhysics/Simulation.cs`)
- Simulation → Island sleep: supports low-cost sleep (evidence: `BepuPhysics/Simulation.cs`)
- Constraint processors → Bodies: solves against (evidence: `BepuPhysics/Constraints/TypeProcessor.cs`)
- Solver → Buffer pooling: allocates from (evidence: `BepuPhysics/Solver.cs`)
- Constraint processors → SIMD math: uses SIMD vectors (evidence: `BepuPhysics/Constraints/TypeProcessor.cs`)
- Task scheduler → Worker state: uses worker state (evidence: `BepuUtilities/TaskScheduling/TaskStack.cs`)
- Worker state → Buffer pooling: allocates worker buffers (evidence: `BepuUtilities/TaskScheduling/Worker.cs`)
- Worker state → Pooled collections: tracks allocated jobs (evidence: `BepuUtilities/TaskScheduling/Worker.cs`)
- Pooled collections → Buffer pooling: resizes through pool (evidence: `BepuUtilities/Collections/QuickList.cs`)
