# tsoding/formula architecture

> Architecture diagram of the GitHub repository tsoding/formula, 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/tsoding/formula
- Repository: https://github.com/tsoding/formula

## Overview

This is a small browser-based 3D graphics demonstration accompanying a video. Its workflow is a timer-driven animation: the page's canvas is cleared, model vertices are rotated and translated, perspective-projected into screen coordinates, and polygon edges are drawn. The README identifies the penger model as sourced externally; the tree and excerpts do not show how index.html loads scripts or selects between the cube and penger data, so those links are omitted.

Main entry points: [`index.js`](https://github.com/tsoding/formula/blob/main/index.js) (Animation frame loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_geometry["Model Geometry"]
  node_cube["Cube mesh<br/>[cube.js]"]
  node_penger["Penger mesh<br/>[penger.js]"]
end

subgraph group_render["Animation and Rendering"]
  node_canvas["Canvas setup and drawing<br/>[index.js]"]
  node_frame["Animation frame loop<br/>[index.js]"]
  node_projection["Transform and projection<br/>[index.js]"]
end

node_viewer(("Browser viewer"))

node_viewer -->|"starts animation"| node_frame
node_frame -->|"clears and draws"| node_canvas
node_frame -->|"transforms vertices"| node_projection
node_projection -->|"supplies screen points"| node_canvas

click node_canvas "https://github.com/tsoding/formula/blob/main/index.js"
click node_frame "https://github.com/tsoding/formula/blob/main/index.js"
click node_projection "https://github.com/tsoding/formula/blob/main/index.js"
click node_cube "https://github.com/tsoding/formula/blob/main/cube.js"
click node_penger "https://github.com/tsoding/formula/blob/main/penger.js"

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_cube,node_penger,node_viewer toneBlue
class node_canvas,node_frame,node_projection toneAmber
```

## Components

### Model Geometry

- [Cube mesh](https://github.com/tsoding/formula/blob/main/cube.js): `cube.js`
- [Penger mesh](https://github.com/tsoding/formula/blob/main/penger.js): `penger.js`

### Animation and Rendering

- [Canvas setup and drawing](https://github.com/tsoding/formula/blob/main/index.js): `index.js`
- [Animation frame loop](https://github.com/tsoding/formula/blob/main/index.js): `index.js`
- [Transform and projection](https://github.com/tsoding/formula/blob/main/index.js): `index.js`

### Other components

- **Browser viewer**

## Connections

- Browser viewer → Animation frame loop: starts animation (evidence: `index.js`)
- Animation frame loop → Canvas setup and drawing: clears and draws (evidence: `index.js`)
- Animation frame loop → Transform and projection: transforms vertices (evidence: `index.js`)
- Transform and projection → Canvas setup and drawing: supplies screen points (evidence: `index.js`)
