# rs-anantmishra/streamsphere architecture

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

- Interactive diagram: https://gitdiagram.com/rs-anantmishra/streamsphere
- Repository: https://github.com/rs-anantmishra/streamsphere

## Overview

##### Main System Components

a) Frontend Layer:
- Angular-based UI application (found in /ui directory)
- Components for videos, playlists, categories, and downloads
- Services for API communication
- WebSocket service for real-time updates

b) Backend Layer:
- Main API Service (in /api directory)
- Content Processor Service (in /processor directory)
- File Management System
- Database Layer (SQLite)

c) External Services:
- yt-dlp integration for video downloading
- Content storage system

##### Component Relationships

**[Frontend Layer]**

- WebSocket Connection

- HTTP/REST APIs

**[Backend Layer]**

- API Service
- Handlers
- Middleware
- Presenters

- Processor Service
- Extractor
- Media Processing
- Request Handler

- Database Layer
- SQLite

- File System
- Content Storage

##### Specific Implementation Details

a) Frontend Architecture:
- Component-based structure (videos, playlists, categories)
- Services layer for API communication
- WebSocket integration for real-time updates
- Theme support (light/dark)

b) Backend Services:
- API handlers for different functionalities
- Content processor for video extraction
- File management system
- Database queries and management

c) Docker Container Structure:
- Main application container
- Content serving container
- Volume management for persistence

##### Data Flow Indicators

- User requests flow
- Video download process
- Content storage operations
- Real-time updates via WebSocket
- Database operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[Angular UI]
        Videos["Videos Component"]:::frontend
        Playlists["Playlists Component"]:::frontend
        Categories["Categories Component"]:::frontend
        Downloads["Downloads Component"]:::frontend
        
        subgraph Services
            WS["WebSocket Service"]:::service
            API_Comm["API Communication"]:::service
            DL_Service["Download Service"]:::service
            Files_Service["Files Service"]:::service
        end
    end

    subgraph Backend
        subgraph API_Service["API Service"]
            Handlers["API Handlers"]:::api
            Middleware["API Middleware"]:::api
            Presenters["API Presenters"]:::api
            Routes["API Routes"]:::api
        end

        subgraph Processor["Content Processor"]
            MainProc["Main Processor"]:::processor
            Extractor["Extractor Service"]:::processor
            MediaProc["Media Processing"]:::processor
            ReqHandler["Request Handler"]:::processor
        end

        subgraph Database
            DB["SQLite Database"]:::db
            DBQueries["Database Queries"]:::db
            Schema["Schema Scripts"]:::db
        end

        subgraph FileSystem
            FileService["File Service"]:::files
            FileRepo["File Repository"]:::files
        end

        subgraph External
            YTDL["yt-dlp Integration"]:::external
            Storage["Content Storage"]:::external
        end
    end

    UI --> Videos & Playlists & Categories & Downloads
    UI --> WS & API_Comm & DL_Service & Files_Service
    
    WS --> Handlers
    API_Comm --> Routes
    DL_Service --> Handlers
    Files_Service --> FileService
    
    Routes --> Middleware --> Handlers --> Presenters
    Handlers --> Processor
    MainProc --> Extractor --> YTDL
    MainProc --> MediaProc
    MainProc --> ReqHandler
    
    Handlers --> DB
    DB --> DBQueries
    DB --> Schema
    
    FileService --> FileRepo
    FileRepo --> Storage

    %% Click Events
    click Videos "https://github.com/rs-anantmishra/streamsphere/tree/master/ui/src/app/components/videos"
    click Playlists "https://github.com/rs-anantmishra/streamsphere/tree/master/ui/src/app/components/playlists"
    click Categories "https://github.com/rs-anantmishra/streamsphere/tree/master/ui/src/app/components/categories"
    click Downloads "https://github.com/rs-anantmishra/streamsphere/tree/master/ui/src/app/components/downloads"
    click WS "https://github.com/rs-anantmishra/streamsphere/blob/master/ui/src/app/services/web-socket.service.ts"
    click API_Comm "https://github.com/rs-anantmishra/streamsphere/blob/master/ui/src/app/services/videos.service.ts"
    click DL_Service "https://github.com/rs-anantmishra/streamsphere/blob/master/ui/src/app/services/download.service.ts"
    click Files_Service "https://github.com/rs-anantmishra/streamsphere/blob/master/ui/src/app/services/files.service.ts"
    click Handlers "https://github.com/rs-anantmishra/streamsphere/tree/master/api/handler"
    click Middleware "https://github.com/rs-anantmishra/streamsphere/tree/master/api/middleware"
    click Presenters "https://github.com/rs-anantmishra/streamsphere/tree/master/api/presenter"
    click Routes "https://github.com/rs-anantmishra/streamsphere/blob/master/api/routes/routes.go"
    click MainProc "https://github.com/rs-anantmishra/streamsphere/blob/master/processor/main.go"
    click Extractor "https://github.com/rs-anantmishra/streamsphere/blob/master/processor/extractor/service.go"
    click MediaProc "https://github.com/rs-anantmishra/streamsphere/blob/master/processor/domain/mediafile.go"
    click ReqHandler "https://github.com/rs-anantmishra/streamsphere/blob/master/processor/requests/repository.go"
    click DB "https://github.com/rs-anantmishra/streamsphere/blob/master/database/database.go"
    click DBQueries "https://github.com/rs-anantmishra/streamsphere/tree/master/database/queries"
    click Schema "https://github.com/rs-anantmishra/streamsphere/blob/master/database/scripts/create.sql"
    click FileService "https://github.com/rs-anantmishra/streamsphere/blob/master/pkg/files/service.go"
    click FileRepo "https://github.com/rs-anantmishra/streamsphere/blob/master/pkg/files/repository.go"
    click YTDL "https://github.com/rs-anantmishra/streamsphere/blob/master/pkg/extractor/service.go"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef service fill:#1976D2,color:white
    classDef api fill:#4CAF50,color:white
    classDef processor fill:#FFC107,color:black
    classDef db fill:#9C27B0,color:white
    classDef files fill:#607D8B,color:white
    classDef external fill:#FF5722,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Service_L["Services"]:::service
        API_L["API"]:::api
        Processor_L["Processor"]:::processor
        DB_L["Database"]:::db
        Files_L["Files"]:::files
        External_L["External"]:::external
    end
```
