# artoriasphereorg/yasai architecture

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

- Interactive diagram: https://gitdiagram.com/artoriasphereorg/yasai
- Repository: https://github.com/artoriasphereorg/yasai

## Overview

##### Project type and purpose
- This is a front-end JavaScript library (a “drop-in” HLS/HTTP-live-streaming player) that developers embed in their web pages to render live or on-demand video via MediaSource Extensions. It is not a full-stack app, but a single-page integration library.

##### File structure
- Demo.html: example integration, shows how to embed the player in a page.
- YasaiPlayer.js: the core player code (loader, parser, buffer manager, event emitter).
- yasaiDesignV3.css: styling for the player UI.
- README.md: usage instructions, supported settings, event list.
- LICENSE: open-source license.

##### Extract architecture insights from the README
- The library initializes via `new YasaiLivePlayer()`.
- It attaches to a given `<video>` element.
- It fetches an HLS manifest (m3u8) and segment files (.ts or fMP4).
- It uses configurable retry/time-out parameters.
- It emits events at each stage: segment appending, flushing, parsing, errors.

##### Main components
a. Client Page (Demo.html or any host page)
b. YasaiPlayer JS Library
- Loader Module (fetch manifest + segments)
- Parser/Demuxer Module (parse TS/fMP4 into raw samples)
- Buffer Manager (SourceBuffer via MediaSource API)
- Event Emitter (yasaiSegAppending, yasaiEr, etc.)
c. Browser’s MediaSource Extensions (MSE)
d. HTMLVideoElement
e. Streaming Origin / CDN (HTTP server hosting m3u8 + segment files)
f. Configuration (fragLoadingTimeOut, retry settings)
g. CSS/UI Layer (yasaiDesignV3.css)

##### Relationships and data flow
- Manifest request: YasaiPlayer.Loader → Streaming Origin
- Segment requests: Loader → Streaming Origin → (responses) → Parser
- Parsed media → Buffer Manager → MediaSource → Video
- Event callbacks: Internal Modules → Event Emitter → Client Page
- Configuration flows from Client Page to Loader/Parser modules.

##### Architectural patterns & design principles
- Modular pipeline: separate loader, parser, buffer, UI.
- Event-driven: all state transitions and errors are emitted as events.
- Retry/time-out strategy for network resiliency.
- DOM-agnostic core with pluggable UI (CSS).

##### Essential elements
- Component names and responsibilities.
- MediaSource API boundary.
- CSS styling layer around the player UI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Layer
    Demo["Client Page (Host Page)"]:::ui
    click Demo "https://github.com/artoriasphereorg/yasai/blob/main/Demo.html"

    %% UI Layer
    UI["CSS/UI Layer"]:::ui
    click UI "https://github.com/artoriasphereorg/yasai/blob/main/yasaiDesignV3.css"

    %% Library Modules
    subgraph "YasaiPlayer JS Library"
        Lib["YasaiPlayer.js"]:::library
        click Lib "https://github.com/artoriasphereorg/yasai/blob/main/YasaiPlayer.js"
        Loader["Loader Module"]:::library
        Parser["Parser/Demuxer Module"]:::library
        Buffer["Buffer Manager"]:::library
        Emitter["Event Emitter"]:::library
        Config["Configuration"]:::config
    end

    %% External Services
    Origin["Streaming Origin / CDN"]:::external
    MSE["MediaSource Extensions (MSE)"]:::external
    Video["HTMLVideoElement"]:::external

    %% Documentation
    Readme["README.md"]:::docs
    click Readme "https://github.com/artoriasphereorg/yasai/blob/main/README.md"
    License["LICENSE"]:::docs
    click License "https://github.com/artoriasphereorg/yasai/tree/main/LICENSE"

    %% Initialization & Setup
    Demo -->|"initialize: new YasaiLivePlayer()"| Lib
    Demo -->|"include CSS"| UI
    Demo -->|config params| Config
    UI -->|"applied to"| Video

    %% Library Internal Flow
    Lib --> Loader
    Lib --> Parser
    Lib --> Buffer
    Lib --> Emitter
    Config -.->|fragLoadingTimeOut, retry settings| Loader
    Config -.->|parser settings| Parser

    %% Network Requests
    Loader -->|"GET manifest (m3u8)"| Origin
    Loader -->|"GET segments (.ts/.fMP4)"| Origin
    Origin -->|"m3u8 & media segments"| Loader

    %% Parsing & Buffering
    Loader -->|"raw data"| Parser
    Parser -->|"parsed samples"| Buffer
    Buffer -->|"appendBuffer"| MSE
    MSE -->|"decode & render"| Video

    %% Event Emission
    Loader -->|events| Emitter
    Parser -->|events| Emitter
    Buffer -->|events| Emitter
    Emitter -.->|"event callbacks"| Demo

    %% Documentation Links
    Lib -->|docs| Readme
    Lib -->|license| License

    %% Styles
    classDef external fill:#D6EAF8,stroke:#1F618D,color:#154360
    classDef library fill:#D5F5E3,stroke:#27AE60,color:#1E8449
    classDef ui fill:#FAD7A0,stroke:#D68910,color:#7E5109
    classDef config fill:#F5B7B1,stroke:#C0392B,color:#78281F,stroke-dasharray: 5 5
    classDef docs fill:#E8DAEF,stroke:#7D3C98,color:#4A235A,stroke-dasharray: 2 2
```
