# tracnitww/libretv architecture

> Architecture diagram of the GitHub repository tracnitww/libretv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tracnitww/libretv
- Repository: https://github.com/tracnitww/libretv

## Overview

##### Project type and purpose
- LibreTV is a lightweight full-stack application combining a static front-end (HTML/CSS/JS) with serverless back-end proxy functions.
- Purpose: provide free, no-login video search and playback by aggregating multiple third-party video sources and proxying HLS streams.

##### File structure
- Front-end:
– `index.html`, `player.html`, `watch.html`, `about.html`, `privacy.html`, `watch.html`
– `css/styles.css`, `js/*.js`, `libs/manifest.json`, `service-worker.js`
- Back-end / proxy:
– `/api/proxy/[...path].mjs` (Edge function for Vercel/Cloudflare)
– `/functions/` & `netlify/functions/proxy.mjs` (Netlify Functions)
– `middleware.js`, `proxy.lua` (for Nginx/OpenResty)
- Deployment/config:
– `Dockerfile`, `docker-compose.yml`, `nginx.conf`, `netlify.toml`, `vercel.json`
– GitHub Actions workflows (`.github/workflows/*.yml`)
– `package.json` (dev server via `npm run dev`)

##### Extract architectural insights from README
- Static assets served over CDN or containerized Nginx in Docker.
- Client uses HLS.js + DPlayer to play streams.
- All API calls (search, detail, HLS) go through serverless functions or proxy middleware to avoid CORS and hide source URLs.
- Optional password protection via `PASSWORD` env var.
- Supported hosts: Cloudflare Pages, Vercel, Netlify, Docker.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Browser
    Browser["Client Browser"]:::front

    %% Static Hosting / CDN
    subgraph "Static Hosting / CDN"
        direction TB
        indexHtml["index.html"]:::front
        watchHtml["watch.html"]:::front
        playerHtml["player.html"]:::front
        aboutHtml["about.html"]:::front
        privacyHtml["privacy.html"]:::front
        robotsTxt["robots.txt"]:::front
        sitemapXml["sitemap.xml"]:::front

        stylesCss["css/styles.css"]:::front
        manifestJson["libs/manifest.json"]:::front
        swJs["service-worker.js"]:::front

        apiJs["js/api.js"]:::front
        appJs["js/app.js"]:::front
        configJs["js/config.js"]:::front
        doubanJs["js/douban.js"]:::front
        passwordJs["js/password.js"]:::front
        sha256Js["js/sha256.js"]:::front
        uiJs["js/ui.js"]:::front
    end

    Browser -->|"Fetch HTML/CSS/JS"| indexHtml
    Browser --> watchHtml
    Browser --> playerHtml
    Browser --> aboutHtml
    Browser --> privacyHtml
    Browser --> robotsTxt
    Browser --> sitemapXml
    Browser --> stylesCss
    Browser --> manifestJson
    Browser --> swJs
    Browser --> apiJs
    Browser --> appJs
    Browser --> configJs
    Browser --> doubanJs
    Browser --> passwordJs
    Browser --> sha256Js
    Browser --> uiJs

    %% Serverless / API Layer
    subgraph "Serverless Functions"  
        direction TB
        vercelApi["api/proxy/[...path].mjs"]:::serverless
        netlifyFunc["netlify/functions/proxy.mjs"]:::serverless
        localMiddleware["functions/_middleware.js"]:::serverless
        localProxy["functions/proxy/[[path]].js"]:::serverless
    end

    Browser -->|"GET /api/proxy/search/detail/hls"| vercelApi
    Browser --> vercelApi
    Browser --> netlifyFunc
    Browser --> localMiddleware
    Browser --> localProxy

    vercelApi -->|"Proxy to third-party APIs & HLS"| ExternalAPIs
    netlifyFunc --> ExternalAPIs
    localMiddleware --> ExternalAPIs
    localProxy --> ExternalAPIs

    %% Optional Docker / Nginx Setup
    subgraph "Docker Container"  
        direction TB
        nginxConf["nginx.conf"]:::docker
        middlewareJs["middleware.js"]:::docker
        proxyLua["proxy.lua"]:::docker
    end

    Browser -->|"Local Nginx Proxy"| nginxConf
    nginxConf --> middlewareJs
    nginxConf --> proxyLua
    middlewareJs --> ExternalAPIs
    proxyLua --> ExternalAPIs

    %% External Video Sources
    subgraph "Third-party Video Sources"
        direction TB
        ExternalAPIs["CMS APIs & HLS Endpoints"]:::external
    end

    %% Click Events
    click indexHtml "https://github.com/tracnitww/libretv/blob/main/index.html"
    click watchHtml "https://github.com/tracnitww/libretv/blob/main/watch.html"
    click playerHtml "https://github.com/tracnitww/libretv/blob/main/player.html"
    click aboutHtml "https://github.com/tracnitww/libretv/blob/main/about.html"
    click privacyHtml "https://github.com/tracnitww/libretv/blob/main/privacy.html"
    click robotsTxt "https://github.com/tracnitww/libretv/blob/main/robots.txt"
    click sitemapXml "https://github.com/tracnitww/libretv/blob/main/sitemap.xml"
    click stylesCss "https://github.com/tracnitww/libretv/blob/main/css/styles.css"
    click manifestJson "https://github.com/tracnitww/libretv/blob/main/libs/manifest.json"
    click swJs "https://github.com/tracnitww/libretv/blob/main/service-worker.js"
    click apiJs "https://github.com/tracnitww/libretv/blob/main/js/api.js"
    click appJs "https://github.com/tracnitww/libretv/blob/main/js/app.js"
    click configJs "https://github.com/tracnitww/libretv/blob/main/js/config.js"
    click doubanJs "https://github.com/tracnitww/libretv/blob/main/js/douban.js"
    click passwordJs "https://github.com/tracnitww/libretv/blob/main/js/password.js"
    click sha256Js "https://github.com/tracnitww/libretv/blob/main/js/sha256.js"
    click uiJs "https://github.com/tracnitww/libretv/blob/main/js/ui.js"
    click vercelApi "https://github.com/tracnitww/libretv/blob/main/api/proxy/[...path].mjs"
    click netlifyFunc "https://github.com/tracnitww/libretv/blob/main/netlify/functions/proxy.mjs"
    click localMiddleware "https://github.com/tracnitww/libretv/blob/main/functions/_middleware.js"
    click localProxy "https://github.com/tracnitww/libretv/blob/main/functions/proxy/[[path]].js"
    click middlewareJs "https://github.com/tracnitww/libretv/blob/main/middleware.js"
    click proxyLua "https://github.com/tracnitww/libretv/blob/main/proxy.lua"
    click nginxConf "https://github.com/tracnitww/libretv/blob/main/nginx.conf"

    %% Styles
    classDef front fill:#e0f7fa,stroke:#006064,color:#006064
    classDef serverless fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20
    classDef docker fill:#eceff1,stroke:#37474f,color:#37474f
    classDef external fill:#fce4ec,stroke:#880e4f,color:#880e4f
```
