# shaka-project/shaka-player architecture

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

- Interactive diagram: https://gitdiagram.com/shaka-project/shaka-player
- Repository: https://github.com/shaka-project/shaka-player

## Overview

##### High-level system components
- Core Player Engine: Represent the central “Player API” that exposes the public interface and manages the playback lifecycle.
- UI Components: Represent the UI layer (in the “ui” directory) that provides controls, display elements (play/pause, fullscreen, volume, etc.), caption handling, language selection, and VR support.
- Build and Testing Infrastructure: Show the build pipeline (found in “build” and CI workflows under “.github/workflows”) which compiles, runs tests, and produces versioned builds (with and without UI components).
- Demo and Integration Layers: Include the “demo” and “app-engine” directories that host demonstration webpages and integration examples for showcasing how users can embed and interact with the player.

##### Depicting the relationships and interactions
- Manifest parsing modules (from “lib/dash”, “lib/hls”, “lib/mss”) that convert manifests into actionable segment information.
- ABR logic (from “lib/abr”) that controls stream switching by monitoring bandwidth.
- DRM integration (from “lib/drm”) which negotiates keys and protection schemes.
- Transmuxers (from “lib/transmuxer”) to convert media containers and support different stream formats.
- Text and subtitle processing (from “lib/text”) for closed captions and subtitles.
- That the UI layer (from “ui/”) consumes API events from the core to update interactive controls and display captions, statistics, etc.
- Integration of offline storage (using IndexedDB logic from “lib/offline”) that connects to the core engine for caching and playback of stored media.

##### Architectural patterns and design principles
- Modular Design: Emphasize that each major functionality (ABR, DRM, transmuxing, etc.) is developed as a discrete module and is loosely coupled with the core engine.
- Plugin/Extensibility: Note the extensible pattern that allows manifest parser plugins or text display plugins for custom behavior.
- Layered Architecture: Differentiate between low-level (networking, data parsing, transport layer via “lib/net”) and higher-level (streaming engine, UI integration) components.
- Testing & CI: Include side blocks that capture robust testing (unit tests in “test/”) and the build system (scripts and containers from “build/” and GitHub workflows) ensuring continuous integration and quality assurance.

##### Specific technologies and frameworks
- That the player relies on Web APIs such as MediaSource Extensions, Encrypted Media Extensions, and IndexedDB.
- Mention that the build system uses tools like Docker (build/docker/Dockerfile), custom Python/JS build scripts (in “build/”), and GitHub Actions workflows.
- That the UI is built using plain JavaScript (and LESS for styles) and is sometimes integrated into frameworks via separate demo/integration repositories.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Browser APIs
    subgraph "Browser APIs"
        MSE("MediaSource Extensions"):::external
        EME("Encrypted Media Extensions"):::external
    end

    %% Core Playback
    subgraph "Core Playback"
        Core("Core Player Engine"):::core
    end

    %% Media Modules
    subgraph "Media Modules"
        ABR("ABR Management Module"):::module
        subgraph "Manifest Parsers"
            DASH("DASH Parser"):::module
            HLS("HLS Parser"):::module
            MSS("MSS Parser"):::module
        end
        DRM("DRM Support Module"):::module
        Transmux("Transmuxer Module"):::module
        Text("Text/ Captions Processing"):::module
        Offline("Offline Storage Module"):::module
    end

    %% UI & Integration
    subgraph "UI & Integration"
        UI("UI Components"):::ui
        DemoApps("Demo Applications"):::ui
        Integration("Integration Examples"):::ui
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Build("Build & Test Infrastructure"):::infra
        Docs("Documentation & Community"):::infra
    end

    %% Connections from Core to Browser APIs
    Core -->|"MSE"| MSE
    Core -->|"EME"| EME

    %% Connections from Core to Media Modules
    Core -->|"calls"| ABR
    Core --> DASH
    Core --> HLS
    Core --> MSS
    Core --> DRM
    Core --> Transmux
    Core --> Text
    Core --> Offline

    %% Connections from Core to UI and Integration
    Core -->|"API_events"| UI
    Core -->|"embed_usage"| DemoApps
    Core -->|"integrated_usage"| Integration

    %% Infrastructure support
    Build -->|"builds"| Core
    Docs -->|"guides"| Core

    %% Styling Classes
    classDef core fill:#f4cccc,stroke:#c00,stroke-width:2px;
    classDef module fill:#c9daf8,stroke:#034f84,stroke-width:2px;
    classDef ui fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef infra fill:#fff2cc,stroke:#b45f06,stroke-width:2px;
    classDef external fill:#d9d2e9,stroke:#6d4e7c,stroke-width:2px;

    %% Click Events
    click Core "https://github.com/shaka-project/shaka-player/blob/main/lib/player.js"
    click ABR "https://github.com/shaka-project/shaka-player/tree/main/lib/abr/"
    click DASH "https://github.com/shaka-project/shaka-player/blob/main/lib/dash/dash_parser.js"
    click HLS "https://github.com/shaka-project/shaka-player/blob/main/lib/hls/hls_parser.js"
    click MSS "https://github.com/shaka-project/shaka-player/blob/main/lib/mss/mss_parser.js"
    click DRM "https://github.com/shaka-project/shaka-player/tree/main/lib/drm/"
    click Transmux "https://github.com/shaka-project/shaka-player/tree/main/lib/transmuxer/"
    click Text "https://github.com/shaka-project/shaka-player/tree/main/lib/text/"
    click Offline "https://github.com/shaka-project/shaka-player/tree/main/lib/offline/"
    click UI "https://github.com/shaka-project/shaka-player/tree/main/ui/"
    click Build "https://github.com/shaka-project/shaka-player/tree/main/build/"
    click DemoApps "https://github.com/shaka-project/shaka-player/tree/main/demo/"
    click Integration "https://github.com/shaka-project/shaka-player/tree/main/app-engine/"
    click Docs "https://github.com/shaka-project/shaka-player/tree/main/docs/"
```
