# Architecture Documentation for Linear Void > The architecture documentation for the Linear Void project is structured according to the [arc42 template](https://arc42.org/). This template provides a comprehensive framework for documenting software architecture, ensuring that all relevant aspects of the system are covered. ## Table of Contents - [Architecture Documentation for Linear Void](#architecture-documentation-for-linear-void) - [Table of Contents](#table-of-contents) - [Companion Documentation](#companion-documentation) - [Introduction and Goals](#introduction-and-goals) - [Requirements Overview](#requirements-overview) - [Quality Goals](#quality-goals) - [Stakeholders](#stakeholders) - [Architecture Constraints](#architecture-constraints) - [Context and Scope](#context-and-scope) - [Business Context](#business-context) - [High-Level Context Diagram (Mermaid)](#high-level-context-diagram-mermaid) - [Technical Context](#technical-context) - [Solution Strategy](#solution-strategy) - [Building Block View](#building-block-view) - [Whitebox Overall System](#whitebox-overall-system) - [Level 2](#level-2) - [Level 3](#level-3) - [Runtime View](#runtime-view) - [Playout \& Delivery Scenario](#playout--delivery-scenario) - [Deployment View](#deployment-view) - [CI/CD Pipeline Architecture](#cicd-pipeline-architecture) - [Infrastructure Level 1](#infrastructure-level-1) - [Infrastructure Level 2](#infrastructure-level-2) - [Cross-cutting Concepts](#cross-cutting-concepts) - [Caching \& Cost Optimization](#caching--cost-optimization) - [Video Normalization \& Playout](#video-normalization--playout) - [Required Source Profile (Linear Void v1)](#required-source-profile-linear-void-v1) - [Reference Normalization Command](#reference-normalization-command) - [Verification Gate (ffprobe)](#verification-gate-ffprobe) - [Monitoring \& Resilience](#monitoring--resilience) - [Prometheus Baseline](#prometheus-baseline) - [Grafana Dashboards](#grafana-dashboards) - [Alerting Rules (Prometheus Rule Groups)](#alerting-rules-prometheus-rule-groups) - [API Documentation Reference](#api-documentation-reference) - [Chat WebSocket API](#chat-websocket-api) - [Playout and Delivery REST API](#playout-and-delivery-rest-api) - [Admin REST API](#admin-rest-api) - [Cloudflare Configuration Reference](#cloudflare-configuration-reference) - [DNS and Zone Routing](#dns-and-zone-routing) - [Cache Rules Baseline](#cache-rules-baseline) - [Edge Security and Controls](#edge-security-and-controls) - [Worker and Header Policy](#worker-and-header-policy) - [Operations and Validation](#operations-and-validation) - [Security \& Moderation](#security--moderation) - [Transport and Edge Protection](#transport-and-edge-protection) - [Reverse Proxy Enforcement (nginx)](#reverse-proxy-enforcement-nginx) - [Admin Authentication and Session Security](#admin-authentication-and-session-security) - [Rate Limiting and Abuse Controls](#rate-limiting-and-abuse-controls) - [CORS and Cross-Origin Behavior](#cors-and-cross-origin-behavior) - [Moderation and Privacy](#moderation-and-privacy) - [Chat](#chat) - [Architecture Decisions](#architecture-decisions) - [Quality Requirements](#quality-requirements) - [Performance Benchmarks and Capacity Planning](#performance-benchmarks-and-capacity-planning) - [Baseline SLO Targets (v1)](#baseline-slo-targets-v1) - [Workload Assumptions](#workload-assumptions) - [Initial Capacity Model](#initial-capacity-model) - [Benchmark Plan](#benchmark-plan) - [Capacity Triggers and Actions](#capacity-triggers-and-actions) - [Scaling Strategy](#scaling-strategy) - [Phase 1: Vertical + Cache-First (Current Baseline)](#phase-1-vertical--cache-first-current-baseline) - [Phase 2: Service Separation](#phase-2-service-separation) - [Phase 3: Multi-Origin Resilience](#phase-3-multi-origin-resilience) - [Phase 4: Regional and Throughput Expansion](#phase-4-regional-and-throughput-expansion) - [Scaling Triggers](#scaling-triggers) - [Disaster Recovery and Backup Procedures](#disaster-recovery-and-backup-procedures) - [Recovery Targets](#recovery-targets) - [Backup Scope](#backup-scope) - [Backup Cadence](#backup-cadence) - [Recovery Runbook (Minimum)](#recovery-runbook-minimum) - [Failure Modes and Strategy](#failure-modes-and-strategy) - [Risks and Technical Debts](#risks-and-technical-debts) - [Glossary](#glossary) ## Companion Documentation - [API.md](../../API.md) - Implemented WebSocket and REST API reference. - [DEPLOYMENT.md](../../DEPLOYMENT.md) - Production deployment and operational runbook. - [MONITORING.md](../../MONITORING.md) - Metrics, dashboards, and monitoring troubleshooting. - [SECURITY.md](../../SECURITY.md) - Security model, controls, and hardening baseline. ## Introduction and Goals ### Requirements Overview Linear Void is an independent **24/7 linear video channel** broadcasting a playlist of self-owned pre-recorded videos. Viewers access it via a custom lightweight HTML/CSS/JavaScript SPA with synchronized HLS playback, schedule metadata, public chat rooms, and private 1:1 messaging. Complete independence from third-party video platforms (YouTube, Twitch, etc.). **Core Requirements** (merged from all ADRs): - Continuous synchronized playback from playlist (live-style HLS, not VOD). - Self-hosted source media, frontend, schedule, and chat data. - Primary US audience/origin (East Coast preferred for low latency/peering). - Extreme cost efficiency (bandwidth dominant; target near-zero egress via Cloudflare R2 + edge caching). - Custom chat with rooms, DMs, presence, moderation, persistence. - Storage planning for 48h of 720p30/1080p30 content. - Browser-compatible playback (`hls.js` + native HLS). - Operational simplicity and scalability. Full decision rationale, alternatives, and consequences in [`adr/ADR-001.md`](adr/ADR-001.md). ### Quality Goals | Priority | Quality Attribute | Goal | Scenario | | -------- | ------------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------- | | 1 | **Cost Efficiency** | <$25/month for moderate scale (100s concurrent) | R2 $0 egress + immutable `.ts` edge caching eliminates per-viewer bandwidth cost | | 2 | **Performance / Latency** | Low US latency; acceptable HLS delay | Hetzner Ashburn origin + Cloudflare US POPs (15–35s end-to-end) | | 3 | **Availability** | 24/7 with minimal downtime | FFmpeg/MediaMTX auto-restart loop, fallback slate, monitoring | | 4 | **Scalability** | Grow from 10s to 1000s viewers without proportional cost | Edge caching + R2; only request volume limits | | 5 | **Maintainability** | Lightweight, clear configs, low ops overhead | Static SPA, Go/Node chat, SQLite/PostgreSQL+Redis | | 6 | **Security / Usability** | Secure transport, moderation tools, good UX | HTTPS/WSS, Cloudflare WAF, rate limits, intuitive chat/player | ### Stakeholders | Role/Name | Contact | Expectations | | ------------------- | ------- | -------------------------------------------------------------------------------- | | Product Owner | - | Cost-effective independent 24/7 channel with synchronized viewing and rich chat | | Engineering Team | - | Simple, evolvable stack (FFmpeg, HLS, Cloudflare R2, lightweight WebSocket chat) | | US Viewers | - | Reliable low-latency playback, responsive synchronized chat experience | | Moderators / Admins | - | Easy playlist management, moderation dashboard, monitoring/alerting | | Operations | - | Low TCO, clear cost model, automated failover, backups | (See `adr/ADR-001.md` for detailed forces, decision drivers, and rationale.) ## Architecture Constraints - Independence from video hosting platforms (no YouTube, Twitch, paid Cloudflare Stream). - US-centric (origin + audience). - Cost must remain low even at scale (bandwidth dominant). - Standard browser playback only (no plugins). - Cloudflare ToS compliance for video delivery (use R2 as origin for large immutable files). - HLS as primary protocol (standard, not LL-HLS initially). - Self-hosted playlist normalization and continuous playout required. (See `adr/ADR-001.md` for full forces and trade-offs.) ## Context and Scope ### Business Context Linear Void provides a continuously running scheduled video program (playlist-driven) to a primarily US audience. The custom viewer site replaces traditional platforms, giving full control over content, schedule, UI, and real-time chat (public rooms + private DMs). ### High-Level Context Diagram (Mermaid) ```mermaid flowchart TD subgraph "External Users" Viewers[US Viewers
Browser SPA + hls.js + Chat UI] Admins[Admins / Moderators
Playlist & Schedule UI] end subgraph "Cloudflare Global Edge" CDN[Cloudflare CDN
Cache Rules + WAF + TLS] Pages[Cloudflare Pages
Static SPA Hosting] R2[Cloudflare R2
HLS Segments + Source MP4s
enam location hint] end subgraph "US-East Origin (Hetzner Ashburn VPS)" VPS[VPS CX22
Nginx Proxy + Monitoring] Playout[Playout Service
FFmpeg + MediaMTX/SRS
Continuous HLS from Playlist] Chat[Chat Backend
WebSockets + Redis + DB
Public rooms + Private DMs] end Admins -->|HTTPS - Schedule/Playlist| Playout Playout -->|S3-compatible Upload| R2 R2 -->|Cached HLS| CDN Viewers -->|HTTPS| Pages Viewers -->|HLS Requests| CDN Viewers -->|WSS Chat| Chat Chat --> VPS VPS -->|Proxy / Static| Pages CDN -->|Origin Pull on Miss| R2 ``` **External Interfaces**: - **Cloudflare**: CDN (cache rules for `.ts` vs `.m3u8`), R2 (object storage, $0 egress), Pages (static hosting), WAF/TLS. - **Hetzner VPS**: Compute for playout and chat (low-cost US-East with good peering). - **Browsers**: Native HLS (`