How perminder-klair/subwave works
Purpose and Entry Points
SUB/WAVE is a self-hosted personal internet-radio platform: one shared Icecast broadcast, automated from a Navidrome music library by an AI DJ. Operators deploy through Docker Compose, use the subwave CLI, or administer via the web UI. Primary entry points are docker-compose.yml, bin/subwave, cli/src/cli.ts, controller/src/server.ts, web/app/page.tsx, and app/src/app/_layout.tsx.
Deployment and Runtime Topology
Production Compose orchestrates Caddy, web, controller, broadcast, Icecast, and the default acoustic analyzer; optional profiles add heavy TTS or GPU analysis. Caddy is the public routing/TLS boundary, while BYO mode exposes web, controller, and Icecast independently. Docker assets and service entrypoints are in docker-compose.yml, docker/Caddyfile, docker/Dockerfile.controller, and docker/broadcast-entrypoint.sh. State is intended to persist outside application containers.
Broadcast Pipeline
Liquidsoap owns real-time audio assembly: it receives controller-directed tracks/speech, applies crossfade and voice ducking, and emits shared mounts through Icecast. The controller’s queue/session/scheduler coordinate what is on air and when; Liquidsoap is deliberately separated as the timing-sensitive mixer. Core paths: liquidsoap/radio.liq, controller/src/broadcast/queue.ts, controller/src/broadcast/session.ts, controller/src/broadcast/liquidsoap-control.ts, and controller/src/broadcast/scheduler.ts.
Controller: Station Domain and API
The Node.js controller is the system of record for configuration, broadcast state, station operations, and HTTP APIs. controller/src/server.ts composes routes, middleware, and startup; route modules separate public listener endpoints from authenticated operator/admin surfaces. Setup and secrets are explicit first-run boundaries. Relevant paths: controller/src/server.ts, controller/src/routes/public.ts, controller/src/routes/settings.ts, controller/src/routes/onboarding.ts, controller/src/setup/firstRun.ts, and controller/src/middleware/auth.ts.
AI DJ and Speech Generation
At track boundaries, the DJ agent combines active show/persona context, station state, requests, and skills to choose music and generate spoken segments. The LLM abstraction supports runtime provider selection, strategies, retries/failover, tool calls, budgets, and telemetry. Generated text is handed to pluggable local, cloud, remote, or heavy-sidecar TTS, with fallback behavior. Paths: controller/src/broadcast/dj-agent.ts, controller/src/llm/agent.ts, controller/src/llm/internal/provider/registry.ts, controller/src/audio/tts.ts, and controller/src/audio/tts-fallback.ts.
Music Library, Curation, and Analysis
Navidrome/Subsonic is the external music-library authority. The controller imports and tags library metadata, optionally delegates acoustic analysis to the Python analyzer service, then uses pools, recency, shows, requests, moods, embeddings, and mix constraints to select tracks. External enrichment/scrobbling integrations include Last.fm, MusicBrainz, ListenBrainz, and optional search providers. Paths: controller/src/music/subsonic.ts, controller/src/music/library.ts, controller/src/music/picker.ts, controller/src/music/analyze-library.ts, docker/analyzer/server.py, and controller/src/broadcast/scrobble.ts.
Client and Operator Surfaces
The Next.js app provides public listening, onboarding, documentation, and authenticated administration; it consumes controller APIs and Icecast stream metadata. The native Expo app is a separate listener client with background playback, casting, and multi-station support. External agents enter through the standalone MCP server, which forwards station-control/request actions to the controller API. Paths: web/app/listen/page.tsx, web/components/admin/AdminShell.tsx, app/src/audio/player.ts, app/src/player/PlayerScreen.tsx, and mcp-subwave/src/index.ts.
Main entry points: server.ts Controller API · docker-compose.yml Docker Compose · Caddyfile Caddy · dj-agent.ts AI DJ
Components 21
Deployment
- Docker Compose · Starts the production services and optional profiles.
docker-compose.yml - Caddy · TLS and public routing boundary.
docker/Caddyfile
Controller
- Controller API · Composes APIs, middleware, and station startup.
controller/src/server.ts - Auth & first run · Protects operator APIs and initializes secrets.
controller/src/setup/firstRun.ts - Station domain · System of record for configuration and broadcast state.
controller/src/routes/settings.ts - AI DJ · Chooses music and writes track-boundary speech.
controller/src/broadcast/dj-agent.ts - LLM runtime · Selects providers and handles tools, budgets, retries, and failover.
controller/src/llm/agent.ts - TTS pipeline · Uses pluggable synthesis with fallback behavior.
controller/src/audio/tts-fallback.ts - Library & curation · Imports metadata and selects tracks using pools and mix constraints.
controller/src/music/picker.ts
Broadcast
- Broadcast scheduler · Coordinates sessions and upcoming playback.
controller/src/broadcast/scheduler.ts - Broadcast queue · Sends selected tracks and speech to the mixer.
controller/src/broadcast/queue.ts - Liquidsoap · Crossfades, ducks voice, and assembles the live program.
liquidsoap/radio.liq - Icecast · Publishes shared listener mounts.
Clients & Operators
- subwave CLI
cli/src/cli.ts - Web app · Public listening, setup, docs, and administration.
web/app/page.tsx - Native listener · Playback, casting, and multi-station listening.
app/src/player/PlayerScreen.tsx - MCP server · Exposes station actions to external agents.
mcp-subwave/src/index.ts
External Services
- Navidrome / Subsonic · External music-library source.
- Acoustic analyzer · Optional service for library acoustic features.
docker/analyzer/server.py - LLM & TTS providers · Local, cloud, remote, or heavy-sidecar inference.
- Persistent state · State persists outside application containers.
Connections 29
- Docker Compose → Caddy: starts
- Docker Compose → Controller API: starts
- Docker Compose → Liquidsoap: starts broadcast
- Docker Compose → Icecast: starts
- Docker Compose → Acoustic analyzer: default analysis
- Caddy → Web app: routes public web
- Caddy → Controller API: routes API
- Caddy → Icecast: routes streams
- subwave CLI → Controller API: administers
- Web app → Controller API: uses APIs
- Web app → Icecast: plays stream
- Native listener → Controller API: reads station APIs
- Native listener → Icecast: plays stream
- MCP server → Controller API: forwards actions
- Controller API → Auth & first run: enforces setup and auth
- Controller API → Station domain: manages
- Controller API → Broadcast scheduler: operates
- Station domain → Persistent state: persists
- Broadcast scheduler → AI DJ: triggers boundaries
- Broadcast scheduler → Broadcast queue: schedules
- AI DJ → LLM runtime: generates with
- AI DJ → Library & curation: requests selections
- AI DJ → TTS pipeline: hands off speech
- LLM runtime → LLM & TTS providers: selects provider
- TTS pipeline → LLM & TTS providers: synthesizes via
- Library & curation → Navidrome / Subsonic: imports and streams music
- Library & curation → Acoustic analyzer: delegates analysis
- Broadcast queue → Liquidsoap: directs media and speech
- Liquidsoap → Icecast: publishes mounts