# fadhoil/karaoke_tv architecture

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

- Interactive diagram: https://gitdiagram.com/fadhoil/karaoke_tv
- Repository: https://github.com/fadhoil/karaoke_tv

## Overview

Karaoke TV separates the TV host from phone-based operators: a host creates a room, operators join by QR or code, add and manage songs, and shared room state drives TV playback. The main runtime layers are the room UI, queue/playback store, selectable persistence backends, and YouTube/QR/audio features. README documents Supabase realtime/presence and local demo synchronization; unsampled implementations are represented only at the directory or module level, and their links rely on that documentation.

Main entry points: [`components/ControllerRoom.tsx`](https://github.com/fadhoil/karaoke_tv/blob/main/components/ControllerRoom.tsx) (Phone controls), [`lib/store/index.ts`](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/index.ts) (Store selector), [`app/page.tsx`](https://github.com/fadhoil/karaoke_tv/blob/main/app/page.tsx) (Home and join), [`components/HostRoom.tsx`](https://github.com/fadhoil/karaoke_tv/blob/main/components/HostRoom.tsx) (TV host controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rooms["Room Experience"]
  node_home["Home and join<br/>[page.tsx]"]
  node_host_entry["Create room route<br/>[page.tsx]"]
  node_host_page["Host room route<br/>[page.tsx]"]
  node_host_ui["TV host controls<br/>[HostRoom.tsx]"]
  node_controller_page["Operator room route<br/>[page.tsx]"]
  node_controller_ui["Phone controls<br/>[ControllerRoom.tsx]"]
  node_qr_scan["QR scanner<br/>[QrScanner.tsx]"]
end

subgraph group_media["Song and Playback"]
  node_queue["Queue operations<br/>[core.ts]"]
  node_playback["Position calculations<br/>[playback.ts]"]
  node_youtube_player["YouTube TV player<br/>[HostRoom.tsx]"]
end

subgraph group_state["Room State"]
  node_store_select["Store selector<br/>[index.ts]"]
  node_backend_contract["Backend contract<br/>[backend.ts]"]
  node_demo_store["Local demo backend<br/>[demo.ts]"]
  node_supabase_store["Supabase backend<br/>[supabase.ts]"]
  node_supabase_db[("Supabase database<br/>[schema.sql]")]
  node_presence["Member presence<br/>[supabase.ts]"]
end

subgraph group_services["Integrations"]
  node_qr_api["QR generator<br/>[route.ts]"]
  node_search_api["Karaoke search<br/>[route.ts]"]
  node_video_api["YouTube link details<br/>[route.ts]"]
  node_audio_layer["Global sound layer<br/>[SoundLayer.tsx]"]
  node_audio_engine["Audio engine<br/>[audio.ts]"]
  node_status_api["Environment status<br/>[route.ts]"]
end

node_visitor(("TV or phone user"))
node_youtube["YouTube Data API"]
node_browser_storage[("Browser local storage")]

node_visitor -->|"opens"| node_home
node_home -->|"opens scanner"| node_qr_scan
node_home -->|"creates room"| node_host_entry
node_home -->|"joins by code"| node_controller_page
node_qr_scan -->|"routes scanned code"| node_controller_page
node_host_entry -->|"creates room through"| node_store_select
node_host_entry -->|"redirects to"| node_host_page
node_host_page -->|"renders"| node_host_ui
node_controller_page -->|"renders"| node_controller_ui
node_host_ui -->|"reads and updates"| node_store_select
node_controller_ui -->|"reads and updates"| node_store_select
node_controller_ui -->|"searches songs"| node_search_api
node_controller_ui -->|"adds YouTube links"| node_video_api
node_controller_ui -->|"requests room QR"| node_qr_api
node_host_ui -->|"controls playback"| node_youtube_player
node_host_ui -->|"calculates position"| node_playback
node_controller_ui -->|"calculates position"| node_playback
node_store_select -->|"creates store"| node_queue
node_queue -->|"uses backend"| node_backend_contract
node_store_select -->|"selects without credentials"| node_demo_store
node_store_select -->|"selects with credentials"| node_supabase_store
node_demo_store -->|"persists and broadcasts"| node_browser_storage
node_supabase_store -.->|"reads and writes"| node_supabase_db
node_supabase_store -.->|"tracks members"| node_presence
node_search_api -->|"searches and fetches details"| node_youtube
node_video_api -.->|"reads video details"| node_youtube
node_qr_api -.->|"provides scannable QR"| node_visitor
node_audio_layer -->|"plays effects and jingle"| node_audio_engine
node_visitor -.->|"interacts with"| node_audio_layer
node_visitor -.->|"checks configuration"| node_status_api

click node_home "https://github.com/fadhoil/karaoke_tv/blob/main/app/page.tsx"
click node_host_entry "https://github.com/fadhoil/karaoke_tv/blob/main/app/host/page.tsx"
click node_host_page "https://github.com/fadhoil/karaoke_tv/blob/main/app/host/%5Bcode%5D/page.tsx"
click node_host_ui "https://github.com/fadhoil/karaoke_tv/blob/main/components/HostRoom.tsx"
click node_controller_page "https://github.com/fadhoil/karaoke_tv/blob/main/app/r/%5Bcode%5D/page.tsx"
click node_controller_ui "https://github.com/fadhoil/karaoke_tv/blob/main/components/ControllerRoom.tsx"
click node_qr_scan "https://github.com/fadhoil/karaoke_tv/blob/main/components/QrScanner.tsx"
click node_qr_api "https://github.com/fadhoil/karaoke_tv/blob/main/app/api/qr/route.ts"
click node_queue "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/core.ts"
click node_playback "https://github.com/fadhoil/karaoke_tv/blob/main/lib/playback.ts"
click node_youtube_player "https://github.com/fadhoil/karaoke_tv/blob/main/components/HostRoom.tsx"
click node_search_api "https://github.com/fadhoil/karaoke_tv/blob/main/app/api/youtube/search/route.ts"
click node_video_api "https://github.com/fadhoil/karaoke_tv/blob/main/app/api/youtube/video/route.ts"
click node_store_select "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/index.ts"
click node_backend_contract "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/backend.ts"
click node_demo_store "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/demo.ts"
click node_supabase_store "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/supabase.ts"
click node_supabase_db "https://github.com/fadhoil/karaoke_tv/blob/main/supabase/schema.sql"
click node_presence "https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/supabase.ts"
click node_audio_layer "https://github.com/fadhoil/karaoke_tv/blob/main/components/SoundLayer.tsx"
click node_audio_engine "https://github.com/fadhoil/karaoke_tv/blob/main/lib/audio.ts"
click node_status_api "https://github.com/fadhoil/karaoke_tv/blob/main/app/api/status/route.ts"

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_home,node_host_entry,node_host_page,node_host_ui,node_controller_page,node_controller_ui,node_qr_scan,node_visitor toneBlue
class node_queue,node_playback,node_youtube_player,node_browser_storage toneAmber
class node_store_select,node_backend_contract,node_demo_store,node_supabase_store,node_supabase_db,node_presence,node_youtube toneMint
class node_qr_api,node_search_api,node_video_api,node_audio_layer,node_audio_engine,node_status_api toneRose
```

## Components

### Room Experience

- [Home and join](https://github.com/fadhoil/karaoke_tv/blob/main/app/page.tsx): `app/page.tsx`
- [Create room route](https://github.com/fadhoil/karaoke_tv/blob/main/app/host/page.tsx): `app/host/page.tsx`
- [Host room route](https://github.com/fadhoil/karaoke_tv/blob/main/app/host/%5Bcode%5D/page.tsx): `app/host/[code]/page.tsx`
- [TV host controls](https://github.com/fadhoil/karaoke_tv/blob/main/components/HostRoom.tsx): `components/HostRoom.tsx`
- [Operator room route](https://github.com/fadhoil/karaoke_tv/blob/main/app/r/%5Bcode%5D/page.tsx): `app/r/[code]/page.tsx`
- [Phone controls](https://github.com/fadhoil/karaoke_tv/blob/main/components/ControllerRoom.tsx): `components/ControllerRoom.tsx`
- [QR scanner](https://github.com/fadhoil/karaoke_tv/blob/main/components/QrScanner.tsx): `components/QrScanner.tsx`

### Song and Playback

- [Queue operations](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/core.ts): `lib/store/core.ts`
- [Position calculations](https://github.com/fadhoil/karaoke_tv/blob/main/lib/playback.ts): `lib/playback.ts`
- [YouTube TV player](https://github.com/fadhoil/karaoke_tv/blob/main/components/HostRoom.tsx): `components/HostRoom.tsx`

### Room State

- [Store selector](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/index.ts): `lib/store/index.ts`
- [Backend contract](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/backend.ts): `lib/store/backend.ts`
- [Local demo backend](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/demo.ts): `lib/store/demo.ts`
- [Supabase backend](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/supabase.ts): `lib/store/supabase.ts`
- [Supabase database](https://github.com/fadhoil/karaoke_tv/blob/main/supabase/schema.sql): `supabase/schema.sql`
- [Member presence](https://github.com/fadhoil/karaoke_tv/blob/main/lib/store/supabase.ts): `lib/store/supabase.ts`

### Integrations

- [QR generator](https://github.com/fadhoil/karaoke_tv/blob/main/app/api/qr/route.ts): `app/api/qr/route.ts`
- [Karaoke search](https://github.com/fadhoil/karaoke_tv/blob/main/app/api/youtube/search/route.ts): `app/api/youtube/search/route.ts`
- [YouTube link details](https://github.com/fadhoil/karaoke_tv/blob/main/app/api/youtube/video/route.ts): `app/api/youtube/video/route.ts`
- [Global sound layer](https://github.com/fadhoil/karaoke_tv/blob/main/components/SoundLayer.tsx): `components/SoundLayer.tsx`
- [Audio engine](https://github.com/fadhoil/karaoke_tv/blob/main/lib/audio.ts): `lib/audio.ts`
- [Environment status](https://github.com/fadhoil/karaoke_tv/blob/main/app/api/status/route.ts): `app/api/status/route.ts`

### Other components

- **TV or phone user**
- **YouTube Data API**
- **Browser local storage**

## Connections

- TV or phone user → Home and join: opens (evidence: `README.md`)
- Home and join → QR scanner: opens scanner (evidence: `app/page.tsx`)
- Home and join → Create room route: creates room (evidence: `app/page.tsx`)
- Home and join → Operator room route: joins by code (evidence: `app/page.tsx`)
- QR scanner → Operator room route: routes scanned code
- Create room route → Store selector: creates room through (evidence: `app/host/page.tsx`)
- Create room route → Host room route: redirects to (evidence: `README.md`)
- Host room route → TV host controls: renders (evidence: `app/host/[code]/page.tsx`)
- Operator room route → Phone controls: renders (evidence: `app/r/[code]/page.tsx`)
- TV host controls → Store selector: reads and updates (evidence: `components/HostRoom.tsx`)
- Phone controls → Store selector: reads and updates (evidence: `components/ControllerRoom.tsx`)
- Phone controls → Karaoke search: searches songs (evidence: `README.md`)
- Phone controls → YouTube link details: adds YouTube links (evidence: `README.md`)
- Phone controls → QR generator: requests room QR (evidence: `README.md`)
- TV host controls → YouTube TV player: controls playback (evidence: `components/HostRoom.tsx`)
- TV host controls → Position calculations: calculates position (evidence: `components/HostRoom.tsx`)
- Phone controls → Position calculations: calculates position (evidence: `components/ControllerRoom.tsx`)
- Store selector → Queue operations: creates store (evidence: `lib/store/index.ts`)
- Queue operations → Backend contract: uses backend (evidence: `lib/store/core.ts`)
- Store selector → Local demo backend: selects without credentials (evidence: `lib/store/index.ts`)
- Store selector → Supabase backend: selects with credentials (evidence: `lib/store/index.ts`)
- Local demo backend → Browser local storage: persists and broadcasts (evidence: `README.md`)
- Supabase backend → Supabase database: reads and writes (evidence: `README.md`)
- Supabase backend → Member presence: tracks members (evidence: `README.md`)
- Karaoke search → YouTube Data API: searches and fetches details (evidence: `app/api/youtube/search/route.ts`)
- YouTube link details → YouTube Data API: reads video details
- QR generator → TV or phone user: provides scannable QR
- Global sound layer → Audio engine: plays effects and jingle (evidence: `components/SoundLayer.tsx`)
- TV or phone user → Global sound layer: interacts with (evidence: `README.md`)
- TV or phone user → Environment status: checks configuration (evidence: `README.md`)
