Self-Hosted IPTV Web App — Architecture Reference
A quick reference for the architecture behind my self-hosted IPTV streaming platform, built around the iptv-org channel catalog.
Stack
| Layer | Technology |
|---|---|
| Frontend | React 19, Vite, TypeScript, Tailwind CSS, React Router, TanStack Query, Zustand, HLS.js, Shaka Player |
| Backend | FastAPI, Python 3.12, SQLAlchemy, PostgreSQL, Alembic, Pydantic, Redis |
| Infra | Docker Compose, nginx |
Project Layout
frontend/src/
app/ entry, providers, router
features/ channels, player, search, favorites, recent, movies, auth
services/ API clients (Axios)
store/ Zustand global stores
backend/app/
api/ REST routers (channels, movies, search, favorites, proxy, auth)
services/ business logic (proxy signing, tmdb enrichment, channel queries)
parser/ M3U / Kodi playlist parsing
workers/ run_sync, run_extra_sync, run_enrich_movies, scheduler
Clean architecture: API → services → database, dependencies point inward.
Catalog Sync
python -m app.workers.run_syncpulls ~10k channels from iptv-org (~10s), runs on boot + daily schedule.- Local Postgres copy is read for all browsing/search — upstream being slow/down only affects playback of that one channel, not browsing.
Stream Playback: Two Engines
| Stream | Engine |
|---|---|
HLS (.m3u8) | HLS.js |
| DASH, no DRM | Shaka Player |
| DASH + ClearKey | Shaka Player + EME ClearKey |
DASH, header-gated (Referer/UA/Origin) | Routed through backend proxy |
| DASH + Widevine/PlayReady | Not playable in-browser → flagged drmUnsupported |
API response picks the engine:
{
"url": "…",
"kind": "dash",
"clearKeys": { "<kidHex>": "<keyHex>" },
"drmUnsupported": false
}
Signed Stream Proxy (not an open proxy)
- Every upstream URL the proxy will fetch is HMAC-signed (
PROXY_SECRET) by the backend at ingest/response time. - Proxy only fetches URLs it minted itself — rejects non-
http(s)targets, can’t be pointed at arbitrary hosts by a client. - DASH manifests get rewritten (
<BaseURL>+ absolute refs) so segments flow back through/api/v1/proxy/p/{ctx}/{path}with the required headers attached server-side. - Code:
app/services/proxy.py.
Multi-Source Catalog (iptv-org + private playlist)
Rows tagged by source (iptv-org vs extra) so syncing one never deletes rows from the other. Visibility decided at query time, not ingest time:
IPTV_ORG_ENABLED | EXTRA_PLAYLIST_URL | Shows |
|---|---|---|
true | set | iptv-org + extra |
false | set | extra only |
true | empty | iptv-org only |
false | empty | nothing |
Turning a source off hides it from every read endpoint but keeps the rows — flip back on instantly, no re-ingest.
# manual one-off ingest of the extra/private playlist
python -m app.workers.run_extra_sync https://example.com/playlist.m3u
EXTRA_PLAYLIST_REFRESH_HOURS (default 6) — kept short since ClearKey keys rotate frequently.
Movie Metadata (TMDB)
python -m app.workers.run_enrich_movies [LIMIT]
Matches unmatched movie entries against TMDB for posters/descriptions/ratings. Idempotent — only touches movies not yet matched, safe to re-run on a schedule.
Auth — Single User, Deliberately Minimal
No user table, no registration, no password reset. One username/password pair from config:
valid_username = hmac.compare_digest(body.username, settings.auth_username)
valid_password = hmac.compare_digest(body.password, settings.auth_password)
hmac.compare_digest instead of == — avoids leaking timing info on credential comparison even at single-user scale.
Key Env Vars
| Variable | Purpose |
|---|---|
PROXY_SECRET | HMAC secret for proxy tokens — must be set in production |
PUBLIC_BASE_URL | Absolute backend origin, or empty to let reverse proxy resolve |
EXTRA_PLAYLIST_URL | Private/extra DASH-DRM M3U to ingest alongside iptv-org |
EXTRA_PLAYLIST_REFRESH_HOURS | Refresh cadence for the extra playlist (default 6) |
TMDB_API_KEY | Enables movie metadata enrichment |
IPTV_ORG_ENABLED | Toggle the public catalog on/off without losing data |
Deploy
cp backend/.env.example backend/.env
docker compose -f docker/docker-compose.yml up -d --build
Migrations + catalog population run automatically on first boot.
Checklist When Extending
- New stream format/DRM combo? Decide engine (HLS.js vs Shaka) and whether it needs proxying, per the table above.
- New proxy target? Must go through the signing path — never trust a client-supplied URL directly.
- New data source? Tag rows by source, gate visibility at query time, keep ingest and visibility decoupled.
- New auth need beyond single-user? Revisit — current auth intentionally has no user table.