# ghost0t/billiardo_project architecture

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

- Interactive diagram: https://gitdiagram.com/ghost0t/billiardo_project
- Repository: https://github.com/ghost0t/billiardo_project

## Overview

This is a client-side 3D billiards/pool simulation with no visible backend or server-side subsystem. The application boots from `index.html`, which loads the JS entrypoint and the global `style.css` viewport layout.

The central coordinator is `src/main.js`. It is responsible for creating the scene objects, wiring together the simulation objects, and driving the render/update loop. The README indicates it owns the animation frame loop and a fixed sub-stepping scheme (`dt = 1/180s`, run three times per frame) to keep motion and collision handling stable.

The simulation is split into four main runtime objects:
- `Table.js` for the static arena and room setup
- `Ball.js` for each moving ball
- `Cue.js` for the player’s cue/aiming construct
- `Physics.js` for collision and motion resolution

`Table.js` is not just a surface; it also builds the surrounding room/environment. The file tree under `public/models/` contains the imported 3D assets used for this environment and props, including the billiard table, chandelier, couch, desk, chairs, punching bag, dartboard, and other scene items. This makes the scene more than a pure physics demo: it is a decorated 3D room with the pool table as the focal point.

`Ball.js` models each ball as a dynamic object with position, velocity, spin, and rotation state. The README calls out quaternion-based rotation and automatic texture updates, which implies each ball’s visual orientation is kept in sync with its physics state during the loop.

`Physics.js` is the core rules engine. It handles overlap correction, mass-based collision response, elastic impulse exchange, and motion decay from friction. It also appears to account for cushion contacts and pocket drops, which are reinforced by the bundled sound effects.

`Cue.js` is isolated as its own transform/group so aiming and striking can be manipulated independently of ball physics. The README’s “pivot isolation group” and “moveTo” note suggest the cue is positioned relative to the table/ball state rather than being a free-floating scene element.

The runtime data flow is:
`main.js` creates the table, physics engine, balls, and cue -> the animation loop advances time in substeps -> `Physics.js` updates ball interactions -> `Ball.js` objects receive new coordinates/rotation/spin -> the scene render reflects the updated state. This separation keeps scene construction, simulation, and visual representation distinct.

Audio is a separate presentation layer, not part of the physics core. The `src/assets/` WAV files (`ball_hit.wav`, `break_hit.wav`, `cushion_hit.wav`, `pocket_drop.wav`) are triggered by simulation events such as ball-ball contact, break impacts, rail hits, and pocketing.

The `public/models/` directory is the main asset boundary for imported geometry. The app depends on prebuilt `.glb` and `.fbx` models rather than generating geometry procedurally, except for the room/environment setup mentioned in the README.

In architecture terms, the key boundary is between:
- asset/scene setup (`Table.js` + `public/models/`)
- game-state simulation (`Physics.js`, `Ball.js`)
- player interaction (`Cue.js`)
- orchestration/render timing (`main.js`)

Overall, this is a single-page browser simulation organized around a deterministic physics loop and a 3D scene graph, with the table and room as static environment, balls as dynamic entities, and cue/audio as interaction layers.

Main entry points: [`src/main.js`](https://github.com/ghost0t/billiardo_project/blob/main/src/main.js) (Main loop), [`src/Physics.js`](https://github.com/ghost0t/billiardo_project/blob/main/src/Physics.js) (Physics), [`src/Ball.js`](https://github.com/ghost0t/billiardo_project/blob/main/src/Ball.js) (Ball), [`src/Cue.js`](https://github.com/ghost0t/billiardo_project/blob/main/src/Cue.js) (Cue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["App Shell"]
  node_index_html["index.html<br/>entry document<br/>[index.html]"]
  node_style_css["Style<br/>viewport css<br/>[style.css]"]
end

subgraph group_runtime["Runtime"]
  node_main_js["Main loop<br/>orchestrator<br/>[main.js]"]
  node_table_js["Table<br/>scene setup<br/>[Table.js]"]
  node_ball_js(("Ball<br/>dynamic entity<br/>[Ball.js]"))
  node_cue_js["Cue<br/>interaction rig<br/>[Cue.js]"]
  node_physics_js["Physics<br/>rules engine<br/>[Physics.js]"]
end

subgraph group_assets["Assets"]
  node_models[("3D models<br/>scene assets")]
  node_sounds["Sound effects<br/>audio assets"]
end

node_index_html -->|"loads"| node_main_js
node_index_html -->|"applies"| node_style_css
node_main_js -->|"creates"| node_table_js
node_main_js -->|"creates"| node_ball_js
node_main_js -->|"creates"| node_cue_js
node_main_js -->|"drives"| node_physics_js
node_main_js -->|"uses"| node_models
node_main_js -->|"triggers"| node_sounds
node_table_js -->|"assembles"| node_models
node_physics_js -->|"updates"| node_ball_js
node_physics_js -->|"reads"| node_cue_js
node_cue_js -->|"strikes"| node_ball_js
node_ball_js -->|"emits"| node_sounds
node_physics_js -->|"emits"| node_sounds

click node_index_html "https://github.com/ghost0t/billiardo_project/blob/main/index.html"
click node_style_css "https://github.com/ghost0t/billiardo_project/blob/main/src/style.css"
click node_main_js "https://github.com/ghost0t/billiardo_project/blob/main/src/main.js"
click node_table_js "https://github.com/ghost0t/billiardo_project/blob/main/src/Table.js"
click node_ball_js "https://github.com/ghost0t/billiardo_project/blob/main/src/Ball.js"
click node_cue_js "https://github.com/ghost0t/billiardo_project/blob/main/src/Cue.js"
click node_physics_js "https://github.com/ghost0t/billiardo_project/blob/main/src/Physics.js"
click node_sounds "https://github.com/ghost0t/billiardo_project/tree/main/src/assets"

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_index_html,node_style_css toneBlue
class node_main_js,node_table_js,node_ball_js,node_cue_js,node_physics_js toneAmber
class node_models,node_sounds toneMint
```

## Components

### App Shell

Browser entrypoint and viewport styling.

- [index.html](https://github.com/ghost0t/billiardo_project/blob/main/index.html): entry document · Boots the client-side app and loads the runtime bundle. · `index.html`
- [Style](https://github.com/ghost0t/billiardo_project/blob/main/src/style.css): viewport css · Global layout and presentation for the 3D viewport. · `src/style.css`

### Runtime

Scene construction, simulation loop, and interactive game objects.

- [Main loop](https://github.com/ghost0t/billiardo_project/blob/main/src/main.js): orchestrator · Creates the scene objects and drives the fixed-step animation loop. · `src/main.js`
- [Table](https://github.com/ghost0t/billiardo_project/blob/main/src/Table.js): scene setup · Builds the billiard table and surrounding room/environment. · `src/Table.js`
- [Ball](https://github.com/ghost0t/billiardo_project/blob/main/src/Ball.js): dynamic entity · Represents each ball's position, velocity, spin, and rotation. · `src/Ball.js`
- [Cue](https://github.com/ghost0t/billiardo_project/blob/main/src/Cue.js): interaction rig · Handles aiming and striking as a separate transform from the balls. · `src/Cue.js`
- [Physics](https://github.com/ghost0t/billiardo_project/blob/main/src/Physics.js): rules engine · Resolves collisions, cushion contacts, pocket drops, and friction. · `src/Physics.js`

### Assets

Prebuilt 3D models and audio cues used by the scene.

- **3D models**: scene assets · Imported glb/fbx geometry for the table, room props, and decor.
- [Sound effects](https://github.com/ghost0t/billiardo_project/tree/main/src/assets): audio assets · Collision, cushion, break, and pocket audio triggered by simulation events. · `src/assets`

## Connections

- index.html → Main loop: loads · Bootstraps the JavaScript entrypoint.
- index.html → Style: applies · Loads the global viewport styling.
- Main loop → Table: creates · Builds the static arena and room.
- Main loop → Ball: creates · Instantiates the moving balls.
- Main loop → Cue: creates · Sets up the aiming and striking rig.
- Main loop → Physics: drives · Runs the deterministic fixed-step simulation loop.
- Main loop → 3D models: uses · Loads the imported scene geometry.
- Main loop → Sound effects: triggers · Plays impact and pocket audio from simulation events.
- Table → 3D models: assembles · Uses table and room props to build the scene.
- Physics → Ball: updates · Computes new ball motion and state.
- Physics → Cue: reads · Uses cue state when resolving strikes.
- Cue → Ball: strikes · Transfers aiming input into ball motion.
- Ball → Sound effects: emits · Ball collisions and pocketing generate audio events.
- Physics → Sound effects: emits · Collision and rail contacts trigger sound effects.
