# srgssr/pillarbox-web architecture

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

- Interactive diagram: https://gitdiagram.com/srgssr/pillarbox-web
- Repository: https://github.com/srgssr/pillarbox-web

## Overview

##### Main Components
- Player Component – The heart of the system is the player (src/components/player.js). It extends Video.js to provide custom functionality.
- Data Provider Module – Found in src/dataProvider, this module handles media compositions and data fetching (note the model definitions and services like DataProvider.js).
- Middleware – The middleware (src/middleware) likely intercepts or pre-processes playback and analytics data (e.g., srgssr.js).
- Trackers and Analytics – In src/trackers, components such as PillarboxMonitoring.js and SRGAnalytics.js capture playback metrics and tracking events.
- Utility/Helper Functions – Various utility modules in src/utils (like AkamaiTokenService.js, Drm.js, Image.js, PlayerEvents.js) assist with token management, digital rights handling, image processing, and event management.
- Localization – The language files (src/lang) support internationalization for different locales (e.g., en, de, fr, etc.).
- Styling and Theming – SCSS files and theme-related resources manage the look and feel of the player (located in the scss folder).
- Build Artifacts and Configuration – The build outputs (build.es.js, build.umd.js) and configuration files (Vite, Babel, ESLint, etc.) reflect how the project is bundled and maintained but are not necessarily runtime components.

##### Relationships and Interactions
- The Player Component interacts with the Video.js framework (external dependency) while integrating the custom features from this project.
- It calls the Data Provider service to retrieve media metadata and compositions, which feed playback decisions.
- The Middleware layer can manipulate or validate data between the player and the data provider, ensuring that SRGSSR-specific logic is enforced.
- Tracker components hook into player events (through PlayerEvents utility) to log analytics and monitoring data.
- Utility modules are used by various components (player, data provider, trackers) to perform specialized tasks such as DRM handling or token generation.
- Localization files are utilized by the player and UI components to display content in the appropriate language.
- The SCSS styling is applied directly to the player’s UI elements, affecting layout and appearance.

##### Architectural Patterns and Design Principles
- Modularization – Each domain (player, data provider, trackers, middleware, utils) is segregated into its own set of files and folders.
- Separation of Concerns – Presentation (player and UI components), business logic (data provider and middleware) and utility functions are clearly separated.
- Extensibility – The architecture is designed so that additional features (like new trackers or language support) can be integrated without major restructuring.

##### Relevant Technologies, Frameworks, and Libraries
- Video.js – The core video playback framework which is extended by Pillarbox.
- JavaScript/TypeScript – The project is primarily written in JavaScript with type definitions provided for TypeScript integration.
- Vite – Multiple Vite configuration files are present, pointing to modern bundling and development tooling.
- ESLint/Stylelint & Babel – Tools used for code quality and transformation.
- Testing Framework – Jest is configured for unit and integration tests.
- SCSS – Provides the theming and styling for the player UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        VJS["Video.js"]:::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        P["Player Component"]:::player
        LOC["Localization"]:::localization
    end

    %% Styling & Theming
    subgraph "Styling & Theming"
        PSC["Pillarbox SCSS"]:::styling
        CS["Component Styles"]:::styling
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        subgraph "Data Provider Module"
            DPS["Data Provider Service"]:::data
            DPM["Media Composition Model"]:::data
        end
        MW["Middleware (srgssr)"]:::middleware
        subgraph "Trackers & Analytics"
            PM["Pillarbox Monitoring"]:::tracker
            SA["SRG Analytics"]:::tracker
        end
    end

    %% Support Utilities
    subgraph "Support Utilities"
        AT["AkamaiTokenService"]:::utils
        DRM["Drm"]:::utils
        IMG["Image"]:::utils
        PE["PlayerEvents"]:::utils
    end

    %% Relationships
    VJS --> P
    P -->|"fetches"| DPS
    P -->|"processes"| MW
    MW -->|"validates"| DPS
    DPS -->|"uses"| DPM
    P -->|"triggers"| PM
    P -->|"triggers"| SA
    P -->|"uses"| AT
    P -->|"uses"| DRM
    P -->|"uses"| IMG
    P -->|"uses"| PE
    PE -->|"notifies"| PM
    PE -->|"notifies"| SA
    P -->|"localizes"| LOC
    P -->|"styledBy"| PSC

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef player fill:#ccf,stroke:#333,stroke-width:2px;
    classDef localization fill:#cff,stroke:#333,stroke-width:2px;
    classDef styling fill:#cfc,stroke:#333,stroke-width:2px;
    classDef data fill:#fcf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ff9,stroke:#333,stroke-width:2px;
    classDef tracker fill:#9ff,stroke:#333,stroke-width:2px;
    classDef utils fill:#ffc,stroke:#333,stroke-width:2px;

    %% Click Events
    click P "https://github.com/srgssr/pillarbox-web/blob/main/src/components/player.js"
    click DPS "https://github.com/srgssr/pillarbox-web/blob/main/src/dataProvider/services/DataProvider.js"
    click DPM "https://github.com/srgssr/pillarbox-web/blob/main/src/dataProvider/model/MediaComposition.js"
    click MW "https://github.com/srgssr/pillarbox-web/blob/main/src/middleware/srgssr.js"
    click PM "https://github.com/srgssr/pillarbox-web/blob/main/src/trackers/PillarboxMonitoring.js"
    click SA "https://github.com/srgssr/pillarbox-web/blob/main/src/trackers/SRGAnalytics.js"
    click AT "https://github.com/srgssr/pillarbox-web/blob/main/src/utils/AkamaiTokenService.js"
    click DRM "https://github.com/srgssr/pillarbox-web/blob/main/src/utils/Drm.js"
    click IMG "https://github.com/srgssr/pillarbox-web/blob/main/src/utils/Image.js"
    click PE "https://github.com/srgssr/pillarbox-web/blob/main/src/utils/PlayerEvents.js"
    click LOC "https://github.com/srgssr/pillarbox-web/tree/main/src/lang"
    click PSC "https://github.com/srgssr/pillarbox-web/blob/main/scss/pillarbox.scss"
    click CS "https://github.com/srgssr/pillarbox-web/tree/main/scss/components"
```
