# the-applicable/physics-engine architecture

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

- Interactive diagram: https://gitdiagram.com/the-applicable/physics-engine
- Repository: https://github.com/the-applicable/physics-engine

## Overview

This is a browser-based physics simulation: users configure and populate a 3D scene, then observe a C++ physics engine run through WebAssembly. The graph separates the React interface and controls, scene/input responsibilities, and native simulation internals. The sampled source shows App wiring and parts of the C++ engine; PhysicsScene and Sidebar implementation details were not sampled, so their internal relationships are limited to explicit README documentation.

Main entry points: [`src/physics/engine.cpp`](https://github.com/the-applicable/physics-engine/blob/master/src/physics/engine.cpp) (Physics world API), [`src/App.tsx`](https://github.com/the-applicable/physics-engine/blob/master/src/App.tsx) (App orchestration), [`src/physics/core/CollisionDetector.h`](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/CollisionDetector.h) (Collision detection), [`src/physics/core/ContactResolver.h`](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/ContactResolver.h) (Contact resolution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Application UI"]
  node_app["App orchestration<br/>[App.tsx]"]
  node_sidebar["Simulation controls<br/>[Sidebar.tsx]"]
end

subgraph group_scene["Scene and Input"]
  node_scene_view["3D physics scene<br/>[PhysicsScene.tsx]"]
  node_keyboard["Keyboard input"]
  node_gamepad["Gamepad input<br/>[GamepadHandler.tsx]"]
  node_mouse["Mouse interaction<br/>[MouseHandler.tsx]"]
end

subgraph group_wasm["WebAssembly Runtime"]
  node_wasm_loader["WASM loader<br/>[physics.js]"]
  node_wasm_binary["Physics WASM module<br/>[physics.wasm]"]
end

subgraph group_physics["Physics Engine"]
  node_world["Physics world API<br/>[engine.cpp]"]
  node_rigid_body["Rigid body dynamics<br/>[RigidBody.h]"]
  node_collision["Collision detection"]
  node_contact["Contact resolution<br/>[ContactResolver.h]"]
  node_constraint["Body constraints<br/>[Constraint.h]"]
  node_contact_data["Contact data<br/>[Contact.h]"]
  node_shape_geometry["Collision geometry"]
  node_vector_math["Vector math<br/>[Vector3.h]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"renders controls"| node_sidebar
node_app -->|"renders scene"| node_scene_view
node_app -->|"loads module"| node_wasm_loader
node_scene_view -.->|"uses physics API"| node_world
node_wasm_loader -->|"loads binary"| node_wasm_binary
node_world -->|"creates and updates"| node_rigid_body
node_world -->|"checks collisions"| node_collision
node_world -->|"creates contacts"| node_contact
node_world -->|"resolves contacts"| node_contact
node_world -->|"resolves via"| node_contact
node_world -->|"resolves constraints"| node_constraint
node_collision -->|"tests shapes"| node_shape_geometry
node_collision -->|"fills contact"| node_contact_data
node_world -->|"uses vectors"| node_vector_math

click node_app "https://github.com/the-applicable/physics-engine/blob/master/src/App.tsx"
click node_sidebar "https://github.com/the-applicable/physics-engine/blob/master/src/components/Sidebar.tsx"
click node_scene_view "https://github.com/the-applicable/physics-engine/blob/master/src/components/PhysicsScene.tsx"
click node_keyboard "https://github.com/the-applicable/physics-engine/blob/master/src/components/KeyboardHandler.tsx"
click node_gamepad "https://github.com/the-applicable/physics-engine/blob/master/src/components/GamepadHandler.tsx"
click node_mouse "https://github.com/the-applicable/physics-engine/blob/master/src/components/MouseHandler.tsx"
click node_wasm_loader "https://github.com/the-applicable/physics-engine/blob/master/public/wasm/physics.js"
click node_wasm_binary "https://github.com/the-applicable/physics-engine/blob/master/public/wasm/physics.wasm"
click node_world "https://github.com/the-applicable/physics-engine/blob/master/src/physics/engine.cpp"
click node_rigid_body "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/RigidBody.h"
click node_collision "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/CollisionDetector.h"
click node_contact "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/ContactResolver.h"
click node_constraint "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Constraint.h"
click node_contact_data "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Contact.h"
click node_shape_geometry "https://github.com/the-applicable/physics-engine/tree/master/src/physics/geometry"
click node_vector_math "https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Vector3.h"

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_app,node_sidebar,node_user toneBlue
class node_scene_view,node_keyboard,node_gamepad,node_mouse toneAmber
class node_wasm_loader,node_wasm_binary toneMint
class node_world,node_rigid_body,node_collision,node_contact,node_constraint,node_contact_data,node_shape_geometry,node_vector_math toneRose
```

## Components

### Application UI

- [App orchestration](https://github.com/the-applicable/physics-engine/blob/master/src/App.tsx): `src/App.tsx`
- [Simulation controls](https://github.com/the-applicable/physics-engine/blob/master/src/components/Sidebar.tsx): `src/components/Sidebar.tsx`

### Scene and Input

- [3D physics scene](https://github.com/the-applicable/physics-engine/blob/master/src/components/PhysicsScene.tsx): `src/components/PhysicsScene.tsx`
- [Keyboard input](https://github.com/the-applicable/physics-engine/blob/master/src/components/KeyboardHandler.tsx): `src/components/KeyboardHandler.tsx`
- [Gamepad input](https://github.com/the-applicable/physics-engine/blob/master/src/components/GamepadHandler.tsx): `src/components/GamepadHandler.tsx`
- [Mouse interaction](https://github.com/the-applicable/physics-engine/blob/master/src/components/MouseHandler.tsx): `src/components/MouseHandler.tsx`

### WebAssembly Runtime

- [WASM loader](https://github.com/the-applicable/physics-engine/blob/master/public/wasm/physics.js): `public/wasm/physics.js`
- [Physics WASM module](https://github.com/the-applicable/physics-engine/blob/master/public/wasm/physics.wasm): `public/wasm/physics.wasm`

### Physics Engine

- [Physics world API](https://github.com/the-applicable/physics-engine/blob/master/src/physics/engine.cpp): `src/physics/engine.cpp`
- [Rigid body dynamics](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/RigidBody.h): `src/physics/core/RigidBody.h`
- [Collision detection](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/CollisionDetector.h): `src/physics/core/CollisionDetector.h`
- [Contact resolution](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/ContactResolver.h): `src/physics/core/ContactResolver.h`
- [Body constraints](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Constraint.h): `src/physics/core/Constraint.h`
- [Contact data](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Contact.h): `src/physics/core/Contact.h`
- [Collision geometry](https://github.com/the-applicable/physics-engine/tree/master/src/physics/geometry): `src/physics/geometry`
- [Vector math](https://github.com/the-applicable/physics-engine/blob/master/src/physics/core/Vector3.h): `src/physics/core/Vector3.h`

### Other components

- **User**

## Connections

- User → App orchestration: uses
- App orchestration → Simulation controls: renders controls (evidence: `src/App.tsx`)
- App orchestration → 3D physics scene: renders scene (evidence: `src/App.tsx`)
- App orchestration → WASM loader: loads module (evidence: `src/App.tsx`)
- 3D physics scene → Physics world API: uses physics API (evidence: `README.md`)
- WASM loader → Physics WASM module: loads binary (evidence: `public/wasm/physics.js`)
- Physics world API → Rigid body dynamics: creates and updates (evidence: `src/physics/engine.cpp`)
- Physics world API → Collision detection: checks collisions (evidence: `src/physics/engine.cpp`)
- Physics world API → Contact resolution: creates contacts (evidence: `src/physics/engine.cpp`)
- Physics world API → Contact resolution: resolves contacts (evidence: `src/physics/engine.cpp`)
- Physics world API → Contact resolution: resolves via (evidence: `src/physics/engine.cpp`)
- Physics world API → Body constraints: resolves constraints (evidence: `src/physics/engine.cpp`)
- Collision detection → Collision geometry: tests shapes (evidence: `src/physics/core/CollisionDetector.h`)
- Collision detection → Contact data: fills contact (evidence: `src/physics/core/CollisionDetector.h`)
- Physics world API → Vector math: uses vectors (evidence: `src/physics/engine.cpp`)
