# vvt3/audio-visualiser architecture

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

- Interactive diagram: https://gitdiagram.com/vvt3/audio-visualiser
- Repository: https://github.com/vvt3/audio-visualiser

## Overview

1. **Project shape**
   - This is a single-page browser app built with **React + Vite** on the UI side and a **vanilla JavaScript rendering/audio engine** on the runtime side.
   - The core architectural boundary is between **React-managed controls/state** and an **independent animation/render loop** that runs on `<canvas>`.

2. **Entry and bootstrapping**
   - `index.html` and `src/main.jsx` form the app entry path.
   - `main.jsx` mounts the React tree into the page, and `App.jsx` becomes the top-level coordinator for the visualizer.

3. **UI layer**
   - `src/components/MusicInput.jsx` is the user interaction boundary for selecting an audio file.
   - `src/components/Canvas.jsx` is the bridge between React and the graphics engine: React provides the host element and any needed state, while the engine performs actual drawing.
   - `App.jsx` likely orchestrates these components and holds the minimal state needed to connect upload, playback, and rendering.

4. **Rendering engine**
   - `src/engine/audio.js` contains the non-React logic for audio analysis and animation support.
   - Based on the README, this engine is responsible for:
     - decoding/analyzing uploaded audio via the **Web Audio API**
     - generating procedural track data
     - driving the animation loop with `requestAnimationFrame`
     - rendering the rollercoaster scene to **HTML5 Canvas**

5. **Main data flow**
   - User selects an audio file in `MusicInput`.
   - That file is passed into the audio engine.
   - The engine analyzes frequency/time-domain data and converts it into motion/track behavior.
   - `Canvas` displays the resulting animated scene, including the cart moving along the generated path.

6. **Separation of responsibilities**
   - React is used for **stateful UI and layout** only.
   - The engine is deliberately kept outside React so the high-frequency visual updates do not cause React re-renders.
   - This is a key performance boundary and likely the most important architectural decision in the repo.

7. **Visual generation model**
   - The current implementation uses a **procedural sine-wave-based track** according to the README.
   - The intended evolution is to replace that placeholder with track motion derived more directly from audio frequency bands, so the engine acts as a real-time translator from sound to geometry.

8. **Animation/runtime behavior**
   - The visualizer is a live browser simulation, not a static render.
   - The loop is driven by `requestAnimationFrame`, which suggests the engine continuously updates track/cart position and redraws the canvas in sync with browser refresh timing.

9. **Styling and layout**
   - `src/index.css`, `tailwind.config.js`, and `postcss.config.js` indicate the app uses **Tailwind CSS** for presentation.
   - Styling is separate from the simulation logic, which keeps the visualizer’s layout/header/control chrome distinct from the canvas renderer.

10. **Build/tooling boundary**
   - `vite.config.js` defines the development/build pipeline.
   - This is a frontend-only project with no backend service, database, or persistent storage in the current architecture.

11. **Assets**
   - `assets/screenshots` contains documentation/demo imagery rather than runtime inputs.
   - There is no evidence of server-hosted assets or remote APIs in the current design.

12. **How to diagram it**
   - Draw three main boxes:
     - **React UI**: `App`, `MusicInput`, `Canvas`
     - **Audio/Render Engine**: `audio.js`, waveform/track generation, animation loop
     - **Browser Platform**: Web Audio API, Canvas API, requestAnimationFrame
   - The arrows should flow from **file upload → audio analysis → procedural track/motion → canvas rendering**, with React only coordinating the handoff and layout.

Main entry points: [`src/App.jsx`](https://github.com/vvt3/audio-visualiser/blob/main/src/App.jsx) (App), [`src/engine/audio.js`](https://github.com/vvt3/audio-visualiser/blob/main/src/engine/audio.js) (audio.js), [`src/main.jsx`](https://github.com/vvt3/audio-visualiser/blob/main/src/main.jsx) (main.jsx), [`src/components/MusicInput.jsx`](https://github.com/vvt3/audio-visualiser/blob/main/src/components/MusicInput.jsx) (Music input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App shell"]
  node_index_html["index.html<br/>entry html<br/>[index.html]"]
  node_main_jsx["main.jsx<br/>bootstrap<br/>[main.jsx]"]
end

subgraph group_ui["UI layer"]
  node_app_jsx["App<br/>react coordinator<br/>[App.jsx]"]
  node_music_input["Music input<br/>file control<br/>[MusicInput.jsx]"]
  node_canvas_view["Canvas<br/>react bridge<br/>[Canvas.jsx]"]
end

subgraph group_engine["Audio engine"]
  node_audio_engine["audio.js<br/>engine core<br/>[audio.js]"]
  node_audio_analysis(("Analysis<br/>audio pipeline"))
  node_track_gen(("Track synth<br/>procedural motion"))
  node_anim_loop(("Animation loop<br/>runtime loop"))
end

subgraph group_platform["Browser APIs"]
  node_web_audio{{"Web Audio API<br/>browser api"}}
  node_canvas_api{{"Canvas API<br/>browser api"}}
  node_raf{{"requestAnimationFrame<br/>browser timing"}}
end

subgraph group_tooling["Build and styles"]
  node_styles_css["index.css<br/>styles<br/>[index.css]"]
  node_vite_config["Vite config<br/>build config<br/>[vite.config.js]"]
  node_screenshots["Screenshots<br/>docs assets"]
end

node_index_html -->|"loads"| node_main_jsx
node_main_jsx -->|"mounts"| node_app_jsx
node_app_jsx -->|"renders"| node_music_input
node_app_jsx -->|"renders"| node_canvas_view
node_app_jsx -->|"uses"| node_styles_css
node_music_input -->|"passes file"| node_audio_engine
node_canvas_view -->|"hosts"| node_audio_engine
node_audio_engine -->|"analyzes"| node_audio_analysis
node_audio_analysis -->|"uses"| node_web_audio
node_audio_engine -->|"generates"| node_track_gen
node_track_gen -->|"updates"| node_anim_loop
node_anim_loop -->|"driven by"| node_raf
node_anim_loop -->|"draws to"| node_canvas_api
node_audio_engine -->|"renders"| node_canvas_api
node_app_jsx -->|"coordinates"| node_audio_engine
node_screenshots -.->|"documents"| node_app_jsx
node_vite_config -->|"bundles"| node_main_jsx

click node_index_html "https://github.com/vvt3/audio-visualiser/blob/main/index.html"
click node_main_jsx "https://github.com/vvt3/audio-visualiser/blob/main/src/main.jsx"
click node_app_jsx "https://github.com/vvt3/audio-visualiser/blob/main/src/App.jsx"
click node_music_input "https://github.com/vvt3/audio-visualiser/blob/main/src/components/MusicInput.jsx"
click node_canvas_view "https://github.com/vvt3/audio-visualiser/blob/main/src/components/Canvas.jsx"
click node_styles_css "https://github.com/vvt3/audio-visualiser/blob/main/src/index.css"
click node_vite_config "https://github.com/vvt3/audio-visualiser/blob/main/vite.config.js"
click node_audio_engine "https://github.com/vvt3/audio-visualiser/blob/main/src/engine/audio.js"
click node_screenshots "https://github.com/vvt3/audio-visualiser/tree/main/assets/screenshots"

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_main_jsx toneBlue
class node_app_jsx,node_music_input,node_canvas_view toneAmber
class node_audio_engine,node_audio_analysis,node_track_gen,node_anim_loop toneMint
class node_web_audio,node_canvas_api,node_raf toneRose
class node_styles_css,node_vite_config,node_screenshots toneIndigo
```

## Components

### App shell

React entry and top-level coordination

- [index.html](https://github.com/vvt3/audio-visualiser/blob/main/index.html): entry html · Page shell that loads the app · `index.html`
- [main.jsx](https://github.com/vvt3/audio-visualiser/blob/main/src/main.jsx): bootstrap · Mounts the React tree · `src/main.jsx`

### UI layer

User controls and canvas host

- [App](https://github.com/vvt3/audio-visualiser/blob/main/src/App.jsx): react coordinator · Top-level UI coordinator for upload, playback, and rendering · `src/App.jsx`
- [Music input](https://github.com/vvt3/audio-visualiser/blob/main/src/components/MusicInput.jsx): file control · User boundary for selecting audio files · `src/components/MusicInput.jsx`
- [Canvas](https://github.com/vvt3/audio-visualiser/blob/main/src/components/Canvas.jsx): react bridge · Hands off drawing to the engine while hosting the canvas element · `src/components/Canvas.jsx`

### Audio engine

Non-React analysis, motion, and animation logic

- [audio.js](https://github.com/vvt3/audio-visualiser/blob/main/src/engine/audio.js): engine core · Imperative audio-visual runtime outside React · `src/engine/audio.js`
- **Analysis**: audio pipeline · Decodes and inspects uploaded audio data
- **Track synth**: procedural motion · Turns analyzed audio into track and cart motion
- **Animation loop**: runtime loop · Continuously updates and redraws with requestAnimationFrame

### Browser APIs

Canvas, audio, and frame-timing primitives

- **Web Audio API**: browser api · Audio decoding and frequency/time-domain access
- **Canvas API**: browser api · Immediate-mode 2D drawing target
- **requestAnimationFrame**: browser timing · Browser refresh-synced update driver

### Build and styles

Frontend build pipeline and presentation layer

- [index.css](https://github.com/vvt3/audio-visualiser/blob/main/src/index.css): styles · Global presentation and layout styling · `src/index.css`
- [Vite config](https://github.com/vvt3/audio-visualiser/blob/main/vite.config.js): build config · Development and production bundling setup · `vite.config.js`
- [Screenshots](https://github.com/vvt3/audio-visualiser/tree/main/assets/screenshots): docs assets · Demo imagery for documentation · `assets/screenshots`

## Connections

- index.html → main.jsx: loads · Browser loads the React entry point
- main.jsx → App: mounts · Bootstraps the top-level React component
- App → Music input: renders · Provides upload controls
- App → Canvas: renders · Provides the visualizer surface
- App → index.css: uses · Shares global layout and presentation styling
- Music input → audio.js: passes file · Selected audio is handed to the engine
- Canvas → audio.js: hosts · Canvas host is wired to the render engine
- audio.js → Analysis: analyzes · Engine decodes and inspects audio content
- Analysis → Web Audio API: uses · Relies on browser audio decoding and analysis
- audio.js → Track synth: generates · Converts analysis into motion and geometry
- Track synth → Animation loop: updates · Produces frame-by-frame scene state
- Animation loop → requestAnimationFrame: driven by · Frame updates are synchronized to browser refresh
- Animation loop → Canvas API: draws to · Renders the animated scene on canvas
- audio.js → Canvas API: renders · Direct canvas drawing occurs outside React
- App → audio.js: coordinates · App mediates the handoff between UI and runtime
- Screenshots → App: documents · Repository media shows the visualizer output
- Vite config → main.jsx: bundles · Build pipeline includes the app entry
