# bitmovin/pwx-package-template architecture

> Architecture diagram of the GitHub repository bitmovin/pwx-package-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bitmovin/pwx-package-template
- Repository: https://github.com/bitmovin/pwx-package-template

## Overview

##### Core Framework Layer (Bottom Layer)
a. Structured Concurrency Implementation (left)
b. Effect System (center)
c. Package System (right)
- Context object as a connecting element between these components

##### Player Building Blocks Layer (Middle Layer)
- Two main effects above the core framework:
a. State Management Effect
b. Network Effect

##### Player Packages Layer (Top Layer)
- Following packages in a logical group:
- Core Package
- Data Package
- HLS Package
- Network Package
- Presentation Package
- Source Package
- Sources API Package

##### State Management (Side Panel)
- Atoms:
- SourceStateAtom
- StreamAtom
- Their relationships to the packages

##### Execution Flow

Special Elements to Include:

##### Task Execution
- Fork points where tasks can spawn child tasks

##### Effect System Integration
- How effects connect to external systems
- Browser API integration points

##### Package Dependencies
- Use a different line style for package dependencies
- How packages can be composed

- Core Framework: Blue
- Effects: Green
- Packages: Orange
- State Management: Purple
- External Systems: Gray

- Double lines: Package boundaries

##### How error handling and cancelation propagate through the system

Level of Detail:
- Keep the core framework layer detailed but abstract
- Package interactions at a high level
- Specific implementation details only for critical components
- Reactive nature of the system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Core Framework Layer"
        SC["Structured Concurrency"]
        ES["Effect System"]
        PS["Package System"]:::package
        CO["Context Object"]
        
        SC <--> ES
        ES <--> PS
        CO --- SC
        CO --- ES
        CO --- PS
    end

    subgraph "Player Building Blocks"
        SME["State Management Effect"]
        NE["Network Effect"]:::network
        
        SME -.-> ES
        NE -.-> ES
    end

    subgraph "Player Packages"
        CP["Core Package"]
        DP["Data Package"]
        HP["HLS Package"]
        NP["Network Package"]:::network
        PP["Presentation Package"]
        SP["Source Package"]
        SAP["Sources API Package"]
        
        CP --> DP
        DP --> HP
        HP --> NP
        NP --> PP
        SP --> SAP
    end

    subgraph "State Management"
        SSA["Source State Atom"]:::state
        SA["Stream Atom"]:::state
        PBA["Playback State Atom"]:::state
        RTA["Resize Tracker Atom"]:::state
        EDA["Encryption Data Atom"]:::state
        
        SSA --> SA
        SA --> PBA
        PBA --> RTA
        RTA --> EDA
    end

    subgraph "Task Execution"
        BRT["Backend Request Task"]:::task
        WNT["Wrapped Network Task"]:::task
        
        BRT -.-> WNT
    end

    %% Connections between sections
    SME --> SSA
    NE --> WNT
    PS --> CP

    %% Click events for component mapping
    click PS "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/hello-world/HelloWorld.package.ts"
    click PBA "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/playback-state/PlaybackStateAtom.ts"
    click EDA "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/segment-decryption/EncryptionDataAtom.ts"
    click RTA "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/resize-tracker/ResizeTrackerStateAtom.ts"
    click NE "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/segment-download-statistics/NetworkInspector.package.ts"
    click WNT "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/segment-download-statistics/WrappedNetworkTask.ts"
    click BRT "https://github.com/bitmovin/pwx-package-template/blob/main//src/examples/segment-decryption/BackendRequestTask.ts"

    %% Styling
    classDef package fill:#f96,stroke:#333
    classDef network fill:#9cf,stroke:#333
    classDef state fill:#c9f,stroke:#333
    classDef task fill:#fc9,stroke:#333

    %% Legend
    subgraph Legend
        L1["Package"]:::package
        L2["Network Component"]:::network
        L3["State Component"]:::state
        L4["Task Component"]:::task
    end
```
