How interstellers/audiovisualiser works
Project type and purpose
• This is a small full‑stack Node.js web application whose sole purpose is to serve a static web page that plays an audio file and draws its waveform/spectrum as an SVG‑based visualisation in the browser.
• The server side uses Express (in src/server/server.js) and Jade templates to render views; the client side (in src/client/) implements the AudioVisualizer, SvgBar, SvgBarChart and orchestration logic in visualiser.js.
Key architectural components
a. Frontend (Client‑side)
• AudioVisualizer.js: wraps the Web Audio API for capturing frequency/time data.
• SvgBar & SvgBarChart: generate and update SVG rectangles per audio data frame.
• visualiser.js: ties the UI, event handlers, audio source fetching and SVG updates together.
• Static assets under public/: CSS, images, the MP3 audio files, and vendor libraries (Mocha, Chai) for tests.
b. Backend (Server‑side)
• server.js: an Express app that serves both dynamic views (Jade) and static assets.
• Views under src/server/views/: Jade templates for the main visualizer page and any test pages.
c. Build & Test
• Gruntfile.js: defines the “web” task to launch a development server, serve files, possibly reload.
• specs/: client tests (Mocha in-browser harness) and server tests (node‑based with Mocha/Chai).
d. External dependencies
• Express, Jade (Pug), Grunt, Web Audio API (browser), Mocha, Chai.
Relationships & Data Flows
• The browser sends HTTP GET → Express server (server.js).
• Express chooses a Jade view (visualizer.jade), renders HTML + JS references + CSS, and responds.
• Browser loads static assets (style.css, visualiser.js, SvgBarChart.js, etc.) and the audio file (source.mp3 / tokyo.mp3).
• visualiser.js initializes AudioVisualizer, pulling PCM/frequency data from the Web Audio API.
• AudioVisualizer pushes data frames to SvgBarChart, which updates the SVG DOM in real time.
• Tests are separate: client tests run in an HTML page served under specs/client; server tests run via npm test or mocha CLI.
Architectural patterns & principles
• Separation of concerns:
• Server side handles routing & templating (Express + Jade)
• Client side handles data processing & rendering (Web Audio API + SVG)
• Static assets are served from a dedicated directory (public/)
• Layered architecture: Presentation (browser UI), Application (Express routes & controllers), Static resource layer.
• Client‑side:
• visualiser.html (rendered from Jade)
• visualiser.js → initializes AudioVisualizer and SvgBarChart
• public/audio/*.mp3
• public/styles/style.css
• public/vendors/js/mocha.js + chai.js (for client tests)
• Server‑side:
• server.js (Express app entry point)
• src/server/views/*.jade templates
• Routing layer (GET “/”, GET “/visualizer”, GET “/audio/*.mp3”)
• Build & Test:
• Grunt “web” task (serves on localhost, livereload)
• specs/client/test.html + testSvg.js + testVisualizer.js (Mocha harness)
• specs/server/test‑server.js (Mocha + Chai CLI)