# khaledabdsalame/streamscene architecture

> Architecture diagram of the GitHub repository khaledabdsalame/streamscene, 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/khaledabdsalame/streamscene
- Repository: https://github.com/khaledabdsalame/streamscene

## Overview

##### Project Type & Purpose
- The project is a desktop application built on the .NET framework (using WPF and C#).
- It provides a user-friendly interface for streaming movies using WebTorrent CLI and integrates with external services (like the YTS API) for fetching movie metadata.
- Additional features include built-in subtitle support, privacy (via peer-to-peer streaming and VPN), and optimized buffering.

##### Analyzing the File Structure
- At the top level, you have configuration files (App.config, App.manifest) and the main WPF files (App.xaml, MainWindow.xaml, and several other XAML pages such as Errorpage.xaml, MovieContent.xaml, MoviePlayer.xaml, VideoPlayer.xaml). This indicates a clear separation of the UI views.
- The csproj and solution files indicate a typical Visual Studio project structure.

a. User Interface (UI) Layer:
- Includes all the XAML pages (MainWindow, MovieContent, MoviePlayer, VideoPlayer, Errorpage).
- Represents the view elements that the user interacts with.
- Likely follows the MVVM or similar pattern, where UI is bound to underlying view models—though view models are not explicitly seen, the separation of XAML and code-behind (e.g., MainWindow.xaml.cs) hints at a layered approach.

b. Application/Business Logic Layer:
- Contains code-behind files (e.g., App.xaml.cs, MainWindow.xaml.cs) and manages navigation, user input, and handling errors (via Errorpage.xaml).
- Controls interactions between the UI and external services.
- Coordinates operations like starting a video stream, fetching movie details, or invoking subtitle synchronization.

c. External Service Integration Layer:
- Integration with WebTorrent CLI: The system relies on external torrent streaming capabilities, initiated (likely via command-line calls) from within the application.
- YTS API Integration: The application fetches movie metadata (descriptions, genres, ratings, etc.) using external web services.

d. Supporting Components:
- Media handling: Modules responsible for video playback, buffering, and subtitle synchronization.
- Error Handling & Logging services: Represented with an “Errorpage” component and possibly logging mechanisms configured in App.config.

##### Relationships & Interactions
- The UI Layer triggers user actions (e.g., stream selection, playback commands) that are passed to the Business Logic Layer.
- The Business Logic layer processes these commands and interacts with the External Service Integration Layer. For instance:
– When a user selects a movie, the application calls the YTS API to fetch metadata.
– Upon initiating playback, the application invokes WebTorrent CLI to stream torrent data, passing data back to the UI for playback.
- Error handling flows: If the integration fails or an unexpected event occurs, the flow is rerouted to display the Errorpage.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly split the UI, business logic, and external integrations.
- Layered Architecture: Each layer (presentation, application logic, external services) should be distinct with defined interfaces.
- Modularity: Even though the UI and the logic are spread across various files, the design should treat them as self-contained modules that communicate through well-defined channels.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        MW["MainWindow"]:::ui
        MC["MovieContent"]:::ui
        MP["MoviePlayer"]:::ui
        VP["VideoPlayer"]:::ui
        EP["Errorpage"]:::ui
        subgraph "UI Resources"
            F["Fonts"]:::ui
            I["Images"]:::ui
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        AL["Application Entry & Global Logic"]:::logicLayer
        UC["User Command Processing"]:::logicLayer
    end

    %% External Service Integration
    subgraph "External Service Integration"
        WT["WebTorrent CLI"]:::external
        YTS["YTS API"]:::external
    end

    %% Data Flow Connections
    %% UI actions trigger user commands to be processed
    MW -->|"UserCommand"| UC
    MC -->|"UserCommand"| UC
    MP -->|"UserCommand"| UC
    VP -->|"UserCommand"| UC
    EP -->|"ErrorTriggered"| UC

    %% Business logic initialization
    AL -->|"Dispatch"| UC

    %% Business logic interacts with external services
    UC -->|"InitiateTorrentStream"| WT
    UC -->|"FetchMovieMetadata"| YTS

    %% External services respond back to user commands
    WT -->|"StreamData"| UC
    YTS -->|"MetadataResponse"| UC

    %% Processed data updates UI
    UC -->|"UpdateUI"| MW

    %% Error handling flow
    UC -- "error" --> EP

    %% Styling Classes
    classDef ui fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef logicLayer fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;

    %% Click Events for Component Mapping
    click MW "https://github.com/khaledabdsalame/streamscene/blob/main/MainWindow.xaml"
    click MC "https://github.com/khaledabdsalame/streamscene/blob/main/MovieContent.xaml"
    click MP "https://github.com/khaledabdsalame/streamscene/blob/main/MoviePlayer.xaml"
    click VP "https://github.com/khaledabdsalame/streamscene/blob/main/VideoPlayer.xaml"
    click EP "https://github.com/khaledabdsalame/streamscene/blob/main/Errorpage.xaml"
    click AL "https://github.com/khaledabdsalame/streamscene/blob/main/App.xaml"
    click F "https://github.com/khaledabdsalame/streamscene/tree/main/Fonts"
    click I "https://github.com/khaledabdsalame/streamscene/tree/main/img"
```
