# borisnliscool/yar architecture

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

- Interactive diagram: https://gitdiagram.com/borisnliscool/yar
- Repository: https://github.com/borisnliscool/yar

## Overview

##### Main System Components

a. Frontend Layer (Web Application)
- Built with SvelteKit (evident from the /apps/web structure)
- Components for:
- Authentication flows (/routes/(auth))
- Protected routes (/routes/(protected))
- Video management interfaces
- User settings
- Upload functionality

b. Backend Layer (Node.js Application)
- Main service groups:
- Core Services (authentication, database, JWT)
- Media Services (video download, FFmpeg processing)
- File Management
- API Routes

c. External Services & Dependencies
- yt-dlp integration
- FFmpeg for video processing
- Database (Prisma ORM)
- File storage system

##### Component Relationships

- Client-Server Communication:
- HTTP/REST APIs between frontend and backend
- WebSocket connections (if applicable)
- Authentication flows
- Media upload/download paths

- Backend Processing Pipeline:
- Video download flow through yt-dlp
- Video processing flow through FFmpeg
- Storage management flow
- Database interactions

##### Specific Implementation Details

Key architectural elements:
**[Frontend (SvelteKit)] → [API Layer] → [Backend Services]**
- ↓
**[yt-dlp Integration] ← [Media Service] → [FFmpeg Processing]**
- ↓
**[File Service] ↔ [Storage System] ← → [Database (Prisma)]**

##### Important Architectural Patterns to Highlight

- Service-based architecture (evident from /services directory)
- Route-based modularization
- Middleware pipeline
- Converter pattern for data transformation
- Authentication and authorization flow

##### Technical Stack Indicators

- Frontend: SvelteKit, TailwindCSS
- Backend: Node.js, Express
- Database: Prisma ORM
- Media Processing: FFmpeg, yt-dlp
- Authentication: JWT

##### Development Environment

A separate section showing:
- Docker containers (reference docker-compose files)
- Development tools
- Build pipeline

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        WebApp["Web Application (SvelteKit)"]
        Auth["Authentication Routes"]:::frontend
        Protected["Protected Routes"]:::frontend
        VideoMgmt["Video Management"]:::frontend
        Upload["Upload Interface"]:::frontend
        Settings["User Settings"]:::frontend
        Components["UI Components"]:::frontend
        Stores["State Stores"]:::frontend
        APIInterface["API Interface"]:::frontend
    end

    subgraph Backend
        API["API Layer"]:::backend
        
        subgraph Services
            AuthService["Authentication Service"]:::backend
            MediaService["Media Service"]:::backend
            FileService["File Management"]:::backend
            JWTService["JWT Service"]:::backend
            SettingsService["Settings Service"]:::backend
            VideoDownload["Video Download Service"]:::backend
            FFmpegService["FFmpeg Service"]:::backend
        end
        
        subgraph Data
            Converters["Data Converters"]:::backend
            Database[(Database)]:::database
            Storage[("File Storage")]:::database
        end
    end

    subgraph External
        YTDLP["yt-dlp"]:::external
        FFmpeg["FFmpeg"]:::external
    end

    %% Frontend Relationships
    WebApp --> Auth
    WebApp --> Protected
    Protected --> VideoMgmt
    Protected --> Upload
    Protected --> Settings
    WebApp --> Components
    WebApp --> Stores
    WebApp --> APIInterface
    APIInterface --> API

    %% Backend Relationships
    API --> AuthService
    API --> MediaService
    API --> FileService
    API --> SettingsService
    
    AuthService --> JWTService
    MediaService --> VideoDownload
    MediaService --> FFmpegService
    VideoDownload --> YTDLP
    FFmpegService --> FFmpeg
    
    FileService --> Storage
    Services --> Converters
    Services --> Database

    %% Styling
    classDef frontend fill:#3b82f6,color:#fff
    classDef backend fill:#22c55e,color:#fff
    classDef external fill:#eab308,color:#000
    classDef database fill:#a855f7,color:#fff

    %% Click Events
    click Auth "https://github.com/borisnliscool/yar/tree/main/apps/web/src/routes/(auth)"
    click Protected "https://github.com/borisnliscool/yar/tree/main/apps/web/src/routes/(protected)"
    click VideoMgmt "https://github.com/borisnliscool/yar/tree/main/apps/web/src/routes/(protected)/watch"
    click Upload "https://github.com/borisnliscool/yar/tree/main/apps/web/src/routes/(protected)/upload"
    click Settings "https://github.com/borisnliscool/yar/tree/main/apps/web/src/routes/(protected)/settings"
    click AuthService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/authenticationService.ts"
    click MediaService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/mediaService.ts"
    click FileService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/fileService.ts"
    click FFmpegService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/ffmpegService.ts"
    click VideoDownload "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/videoDownloadService.ts"
    click API "https://github.com/borisnliscool/yar/tree/main/apps/backend/src/routes"
    click Database "https://github.com/borisnliscool/yar/tree/main/apps/backend/prisma"
    click JWTService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/jwtService.ts"
    click SettingsService "https://github.com/borisnliscool/yar/blob/main/apps/backend/src/services/settingsService.ts"
    click Converters "https://github.com/borisnliscool/yar/tree/main/apps/backend/src/converters"
    click APIInterface "https://github.com/borisnliscool/yar/blob/main/apps/web/src/lib/api.ts"
    click Components "https://github.com/borisnliscool/yar/tree/main/apps/web/src/lib/components"
    click Stores "https://github.com/borisnliscool/yar/tree/main/apps/web/src/lib/stores"
```
