# iitzbambusel/chromaflow architecture

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

- Interactive diagram: https://gitdiagram.com/iitzbambusel/chromaflow
- Repository: https://github.com/iitzbambusel/chromaflow

## Overview

Chromaflow is a Chromium audio-analysis extension backed by a local FastAPI service. The main workflow captures a playing tab, streams audio for live BPM/key analysis, and can identify the track; the popup presents results and requests harmonic recommendations. Recognition, cover proxying, catalog matching, and platform links are distinct product stages. Edges use README-described workflows or source-index references; several extension runtime handoffs are documented but not shown in source excerpts, so those links are dashed.

Main entry points: [`backend/main.py`](https://github.com/iitzbambusel/chromaflow/blob/main/backend/main.py) (FastAPI Endpoints), [`extension/offscreen.js`](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen.js) (Offscreen Runtime), [`backend/metadata/service.py`](https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/service.py) (Recognition State Machine), [`backend/matching/engine.py`](https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/engine.py) (Match Scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Browser Extension"]
  node_background["Capture Coordinator<br/>[background.js]"]
  node_offscreen["Offscreen Runtime<br/>[offscreen.js]"]
  node_audio_graph["Audio Graph<br/>[audio_graph.js]"]
  node_worklet["PCM Worklet<br/>[pcm_worklet.js]"]
  node_pcm_buffer["PCM Ring Buffer<br/>[pcm_buffer.js]"]
  node_dispatcher["Analysis Dispatcher"]
  node_recognizer_client["Track Recognizer Client"]
  node_popup["Studio Popup<br/>[popup.js]"]
  node_vu_meter["VU Meter<br/>[vu_meter.js]"]
  node_match_client["Match Client<br/>[match_client.js]"]
end

subgraph group_analysis["Audio Analysis"]
  node_api["FastAPI Endpoints<br/>[main.py]"]
  node_session_buffer["Session Ring Buffer<br/>[buffer.py]"]
  node_audio_decode["Audio Decode<br/>[audio.py]"]
  node_dsp_facade["Analysis Facade<br/>[analyzer.py]"]
  node_key_detector["Key Detection<br/>[key_detector.py]"]
  node_tempo_detector["Tempo Detection<br/>[tempo_detector.py]"]
  node_smoother["Stream Smoothing<br/>[smoother.py]"]
end

subgraph group_recognition["Recognition"]
  node_metadata_service["Recognition State Machine<br/>[service.py]"]
  node_providers["Fingerprint and Catalog Providers<br/>[providers.py]"]
  node_title_parser["Tab Title Parser<br/>[title_parser.py]"]
  node_cover_proxy["Cover Proxy<br/>[cover_proxy.py]"]
end

subgraph group_matching["Harmonic Matching"]
  node_match_engine["Match Scoring<br/>[engine.py]"]
  node_catalog[("Track Catalog<br/>[catalog.py]")]
  node_camelot["Camelot Mapping<br/>[camelot.py]"]
  node_platform_links["Platform Links<br/>[links.py]"]
end

node_listener(("Listener"))
node_tab(("Playing Tab"))
node_backend(("Local Backend"))
node_shazam(("Shazam Service"))
node_itunes(("iTunes Catalog"))

node_listener -->|"operates"| node_popup
node_tab -.->|"initiates capture"| node_background
node_background -.->|"dispatches capture"| node_offscreen
node_offscreen -.->|"configures audio"| node_audio_graph
node_audio_graph -.->|"processes audio"| node_worklet
node_worklet -.->|"writes PCM"| node_pcm_buffer
node_offscreen -.->|"reads audio"| node_pcm_buffer
node_offscreen -->|"starts dispatch"| node_dispatcher
node_dispatcher -->|"sends audio chunks"| node_backend
node_backend -->|"serves requests"| node_api
node_api -->|"manages sessions"| node_session_buffer
node_api -->|"decodes uploads"| node_audio_decode
node_api -->|"runs analysis"| node_dsp_facade
node_dsp_facade -->|"detects key"| node_key_detector
node_dsp_facade -->|"detects tempo"| node_tempo_detector
node_api -.->|"smooths stream results"| node_smoother
node_offscreen -.->|"requests recognition"| node_recognizer_client
node_recognizer_client -->|"sends session request"| node_backend
node_api -->|"handles identification"| node_metadata_service
node_metadata_service -->|"queries providers"| node_providers
node_providers -->|"fingerprints audio"| node_shazam
node_providers -->|"enriches matches"| node_itunes
node_metadata_service -->|"parses tab title"| node_title_parser
node_metadata_service -->|"registers artwork"| node_cover_proxy
node_popup -->|"requests recommendations"| node_match_client
node_match_client -->|"posts match query"| node_backend
node_api -->|"scores recommendations"| node_match_engine
node_match_engine -->|"queries candidates"| node_catalog
node_match_engine -->|"scores key relations"| node_camelot
node_match_engine -->|"builds platform links"| node_platform_links
node_popup -->|"renders audio level"| node_vu_meter

click node_background "https://github.com/iitzbambusel/chromaflow/blob/main/extension/background.js"
click node_offscreen "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen.js"
click node_audio_graph "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/audio_graph.js"
click node_worklet "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/pcm_worklet.js"
click node_pcm_buffer "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/pcm_buffer.js"
click node_dispatcher "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/analysis_dispatcher.js"
click node_recognizer_client "https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/track_recognizer.js"
click node_popup "https://github.com/iitzbambusel/chromaflow/blob/main/extension/popup.js"
click node_vu_meter "https://github.com/iitzbambusel/chromaflow/blob/main/extension/shared/vu_meter.js"
click node_api "https://github.com/iitzbambusel/chromaflow/blob/main/backend/main.py"
click node_session_buffer "https://github.com/iitzbambusel/chromaflow/blob/main/backend/buffer.py"
click node_audio_decode "https://github.com/iitzbambusel/chromaflow/blob/main/backend/audio.py"
click node_dsp_facade "https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/analyzer.py"
click node_key_detector "https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/key_detector.py"
click node_tempo_detector "https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/tempo_detector.py"
click node_smoother "https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/smoother.py"
click node_metadata_service "https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/service.py"
click node_providers "https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/providers.py"
click node_title_parser "https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/title_parser.py"
click node_cover_proxy "https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/cover_proxy.py"
click node_match_engine "https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/engine.py"
click node_catalog "https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/catalog.py"
click node_camelot "https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/camelot.py"
click node_platform_links "https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/links.py"
click node_match_client "https://github.com/iitzbambusel/chromaflow/blob/main/extension/shared/match_client.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_background,node_offscreen,node_audio_graph,node_worklet,node_pcm_buffer,node_dispatcher,node_recognizer_client,node_popup,node_vu_meter,node_match_client toneBlue
class node_api,node_session_buffer,node_audio_decode,node_dsp_facade,node_key_detector,node_tempo_detector,node_smoother toneAmber
class node_metadata_service,node_providers,node_title_parser,node_cover_proxy toneMint
class node_match_engine,node_catalog,node_camelot,node_platform_links toneRose
class node_listener,node_tab,node_backend,node_shazam,node_itunes toneIndigo
```

## Components

### Browser Extension

- [Capture Coordinator](https://github.com/iitzbambusel/chromaflow/blob/main/extension/background.js): `extension/background.js`
- [Offscreen Runtime](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen.js): `extension/offscreen.js`
- [Audio Graph](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/audio_graph.js): `extension/offscreen/audio_graph.js`
- [PCM Worklet](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/pcm_worklet.js): `extension/offscreen/pcm_worklet.js`
- [PCM Ring Buffer](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/pcm_buffer.js): `extension/offscreen/pcm_buffer.js`
- [Analysis Dispatcher](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/analysis_dispatcher.js): `extension/offscreen/analysis_dispatcher.js`
- [Track Recognizer Client](https://github.com/iitzbambusel/chromaflow/blob/main/extension/offscreen/track_recognizer.js): `extension/offscreen/track_recognizer.js`
- [Studio Popup](https://github.com/iitzbambusel/chromaflow/blob/main/extension/popup.js): `extension/popup.js`
- [VU Meter](https://github.com/iitzbambusel/chromaflow/blob/main/extension/shared/vu_meter.js): `extension/shared/vu_meter.js`
- [Match Client](https://github.com/iitzbambusel/chromaflow/blob/main/extension/shared/match_client.js): `extension/shared/match_client.js`

### Audio Analysis

- [FastAPI Endpoints](https://github.com/iitzbambusel/chromaflow/blob/main/backend/main.py): `backend/main.py`
- [Session Ring Buffer](https://github.com/iitzbambusel/chromaflow/blob/main/backend/buffer.py): `backend/buffer.py`
- [Audio Decode](https://github.com/iitzbambusel/chromaflow/blob/main/backend/audio.py): `backend/audio.py`
- [Analysis Facade](https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/analyzer.py): `backend/dsp/analyzer.py`
- [Key Detection](https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/key_detector.py): `backend/dsp/key_detector.py`
- [Tempo Detection](https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/tempo_detector.py): `backend/dsp/tempo_detector.py`
- [Stream Smoothing](https://github.com/iitzbambusel/chromaflow/blob/main/backend/dsp/smoother.py): `backend/dsp/smoother.py`

### Recognition

- [Recognition State Machine](https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/service.py): `backend/metadata/service.py`
- [Fingerprint and Catalog Providers](https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/providers.py): `backend/metadata/providers.py`
- [Tab Title Parser](https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/title_parser.py): `backend/metadata/title_parser.py`
- [Cover Proxy](https://github.com/iitzbambusel/chromaflow/blob/main/backend/metadata/cover_proxy.py): `backend/metadata/cover_proxy.py`

### Harmonic Matching

- [Match Scoring](https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/engine.py): `backend/matching/engine.py`
- [Track Catalog](https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/catalog.py): `backend/matching/catalog.py`
- [Camelot Mapping](https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/camelot.py): `backend/matching/camelot.py`
- [Platform Links](https://github.com/iitzbambusel/chromaflow/blob/main/backend/matching/links.py): `backend/matching/links.py`

### Other components

- **Listener**
- **Playing Tab**
- **Local Backend**
- **Shazam Service**
- **iTunes Catalog**

## Connections

- Listener → Studio Popup: operates (evidence: `README.md`)
- Playing Tab → Capture Coordinator: initiates capture
- Capture Coordinator → Offscreen Runtime: dispatches capture
- Offscreen Runtime → Audio Graph: configures audio (evidence: `extension/offscreen.js`)
- Audio Graph → PCM Worklet: processes audio
- PCM Worklet → PCM Ring Buffer: writes PCM
- Offscreen Runtime → PCM Ring Buffer: reads audio (evidence: `extension/offscreen.js`)
- Offscreen Runtime → Analysis Dispatcher: starts dispatch (evidence: `extension/offscreen.js`)
- Analysis Dispatcher → Local Backend: sends audio chunks (evidence: `README.md`)
- Local Backend → FastAPI Endpoints: serves requests (evidence: `README.md`)
- FastAPI Endpoints → Session Ring Buffer: manages sessions (evidence: `backend/main.py`)
- FastAPI Endpoints → Audio Decode: decodes uploads (evidence: `backend/main.py`)
- FastAPI Endpoints → Analysis Facade: runs analysis (evidence: `backend/main.py`)
- Analysis Facade → Key Detection: detects key (evidence: `backend/dsp/analyzer.py`)
- Analysis Facade → Tempo Detection: detects tempo (evidence: `backend/dsp/analyzer.py`)
- FastAPI Endpoints → Stream Smoothing: smooths stream results
- Offscreen Runtime → Track Recognizer Client: requests recognition (evidence: `extension/offscreen.js`)
- Track Recognizer Client → Local Backend: sends session request (evidence: `README.md`)
- FastAPI Endpoints → Recognition State Machine: handles identification (evidence: `backend/main.py`)
- Recognition State Machine → Fingerprint and Catalog Providers: queries providers (evidence: `backend/metadata/service.py`)
- Fingerprint and Catalog Providers → Shazam Service: fingerprints audio (evidence: `README.md`)
- Fingerprint and Catalog Providers → iTunes Catalog: enriches matches (evidence: `README.md`)
- Recognition State Machine → Tab Title Parser: parses tab title
- Recognition State Machine → Cover Proxy: registers artwork (evidence: `backend/metadata/service.py`)
- Studio Popup → Match Client: requests recommendations (evidence: `extension/popup.js`)
- Match Client → Local Backend: posts match query (evidence: `extension/shared/match_client.js`)
- FastAPI Endpoints → Match Scoring: scores recommendations (evidence: `backend/main.py`)
- Match Scoring → Track Catalog: queries candidates (evidence: `backend/matching/engine.py`)
- Match Scoring → Camelot Mapping: scores key relations (evidence: `backend/matching/engine.py`)
- Match Scoring → Platform Links: builds platform links (evidence: `backend/matching/engine.py`)
- Studio Popup → VU Meter: renders audio level (evidence: `extension/popup.js`)
