# wwbn/avideo architecture

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

- Interactive diagram: https://gitdiagram.com/wwbn/avideo
- Repository: https://github.com/wwbn/avideo

## Overview

##### Project type and purpose
- This is a full‐stack, modular video streaming platform (AVideo) written in PHP.
- Purpose: allow users to upload, encode, play (on‐demand & live), monetize, and manage video content via a core “Streamer” web app, an “Encoder” service, and a “Live Server.”
- Key domains: user management, video processing, playback, live streaming, plugins/extensions, and background jobs.

##### File structure
- Top‐level folders:
- admin, feed, objects, plugin, install, updatedb – core web app (MVC‐like PHP + JSON APIs)
- CreatePlugin – CLI/GUI scaffolding for plugin creation
- Dockerfile(s) & docker‐compose – containerized deployment
- deploy – webserver (Apache & Nginx) configs
- node_modules / package.json – client‐side assets & build
- storage – video & auxiliary file storage
- vendor & composer.json – PHP dependencies
- Plugin folder: dozens of self‐contained modules (standalone PHP classes, SQL installers, view templates)
- Background scripts: install/, updatedb/, plugin cron tasks in plugin subfolders
- Live & WebSocket servers: plugin/YPTSocket, plugin/WebRTC, plugin/Live (Nginx RTMP and HLS configs).

##### README
- Confirms three logical subsystems: Streamer (web UI + API), Encoder (FFmpeg service), Live Server (RTMP/HLS).
- Highlights extensibility via plugins and API, and recommends Docker/Ubuntu for deployment.

##### Elements
- User‐facing (blue)
- Core services (green)
- Data stores (orange)
- External services (gray)
- Annotations for plugins, cron jobs, and container boundaries.

##### Detail is key
- Essential services (Encoder, Live, WebSockets).
- How storage (local vs. CDN) and database interact.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser)" 
        FB1["sw.js"]:::frontend
        FB2["OneSignalSDKWorker.js"]:::frontend
        FB3["package.json"]:::frontend
        FB4["node_modules/"]:::frontend
    end

    %% Core Streamer Service
    subgraph "Streamer Web Server (PHP App)" 
        SE1["index.php"]:::core
        SE2["admin/"]:::core
        SE3["objects/"]:::core
        SE4["plugin/"]:::core
    end

    %% Database
    DB["MySQL/MariaDB\n(install/database.sql)"]:::datastore

    %% Storage Layer
    ST["Storage (local FS)\nstorage/data/"]:::datastore

    %% Encoder Service
    subgraph "Encoder Service (FFmpeg)" 
        EN1["aVideoEncoder.json.php"]:::core
        EN2["aVideoEncoderChunk.json.php"]:::core
        EN3["aVideoEncoderNotifyIsDone.json.php"]:::core
        EN4["aVideoQueueEncoder.json.php"]:::core
    end

    %% Live Server
    subgraph "Live Server (Nginx RTMP/HLS)" 
        LS1["docker-entrypoint-live"]:::core
        LS2["plugin/Live/install/nginx.conf"]:::core
    end

    %% WebSocket Server
    subgraph "WebSocket Server (YPTSocket)" 
        WS1["server.php"]:::core
        WS2["server.node.php"]:::core
        WS3["worker.php"]:::core
        WS4["crontab.php"]:::core
    end

    %% External Services
    subgraph "External Services" 
        EX1["Payment Plugins\n(PayPal, Stripe, RazorPay, BTCPay)"]:::external
        EX2["Ad Servers\n(VAST/VMAP)"]:::external
        EX3["OneSignal Push"]:::external
        EX4["OAuth2 Providers"]:::external
    end

    %% Relationships
    FB1 & FB2 & FB3 & FB4 -->|"HTTP/S UI & AJAX"| SE1
    SE1 -->|"SQL CRUD"| DB
    SE1 -->|"File Upload/Retrieval"| ST
    SE1 -->|"Spawn FFmpeg Jobs"| EN1
    EN1 & EN2 & EN3 & EN4 -->|"Write Encoded Files"| ST
    ST -->|"Notify State"| SE1
    FB1 & FB2 & FB3 & FB4 -->|"HLS Playback / RTMP Publish"| LS1
    LS1 -->|"on_publish hooks"| SE1
    FB1 & FB2 & FB3 & FB4 <-->|"WebSocket"| WS1
    SE1 -->|"Payment Webhooks"| EX1
    SE1 -->|"Ad Tagging"| EX2
    SE1 -->|"Push Notifications"| EX3
    SE1 -->|"OAuth Flows"| EX4

    %% Click Events
    click FB1 "https://github.com/wwbn/avideo/blob/master/sw.js"
    click FB2 "https://github.com/wwbn/avideo/blob/master/OneSignalSDKWorker.js"
    click FB3 "https://github.com/wwbn/avideo/blob/master/package.json"
    click FB4 "https://github.com/wwbn/avideo/tree/master/node_modules/"
    click SE1 "https://github.com/wwbn/avideo/blob/master/index.php"
    click SE2 "https://github.com/wwbn/avideo/tree/master/admin/"
    click SE3 "https://github.com/wwbn/avideo/tree/master/objects/"
    click SE4 "https://github.com/wwbn/avideo/tree/master/plugin/"
    click DB "https://github.com/wwbn/avideo/blob/master/install/database.sql"
    click ST "https://github.com/wwbn/avideo/tree/master/storage/data/"
    click EN1 "https://github.com/wwbn/avideo/blob/master/objects/aVideoEncoder.json.php"
    click EN2 "https://github.com/wwbn/avideo/blob/master/objects/aVideoEncoderChunk.json.php"
    click EN3 "https://github.com/wwbn/avideo/blob/master/objects/aVideoEncoderNotifyIsDone.json.php"
    click EN4 "https://github.com/wwbn/avideo/blob/master/objects/aVideoQueueEncoder.json.php"
    click LS1 "https://github.com/wwbn/avideo/tree/master/deploy/nginx/docker-entrypoint-live"
    click LS2 "https://github.com/wwbn/avideo/blob/master/plugin/Live/install/nginx.conf"
    click WS1 "https://github.com/wwbn/avideo/blob/master/plugin/YPTSocket/server.php"
    click WS2 "https://github.com/wwbn/avideo/blob/master/plugin/YPTSocket/server.node.php"
    click WS3 "https://github.com/wwbn/avideo/blob/master/plugin/YPTSocket/worker.php"
    click WS4 "https://github.com/wwbn/avideo/blob/master/plugin/YPTSocket/crontab.php"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0047AB,color:#0047AB,stroke-width:1px;
    classDef core fill:#DFF5D8,stroke:#2E7D32,color:#2E7D32,stroke-width:1px;
    classDef datastore fill:#FFE8A1,stroke:#B8860B,color:#B8860B,stroke-width:1px;
    classDef external fill:#F0F0F0,stroke:#555,color:#555,stroke-width:1px;
```
