# skilledgamer101/youtube-clone architecture

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

- Interactive diagram: https://gitdiagram.com/skilledgamer101/youtube-clone
- Repository: https://github.com/skilledgamer101/youtube-clone

## Overview

##### Main Components

a. Client Layer:
- Next.js Web Client (yt-web-client)
- User interface components (upload, sign-in, video watching)
- Integration with Firebase Authentication

b. API Layer:
- Firebase Functions (yt-api-service)
- API endpoints for video metadata operations

c. Processing Layer:
- Video Processing Service
- FFmpeg integration for video transcoding

d. Storage Layer:
- Google Cloud Storage (for raw and processed videos)
- Cloud Firestore (for video metadata)

e. Message Queue:
- Cloud Pub/Sub for async communication

**[User/Browser Layer]**
- ↓
**[Web Client Layer (Next.js)]**
- ↓
**[API Layer (Firebase Functions)]**
- ↓
**[Processing Layer]    [Storage Layer]**
- ↓                    ↓
**[Message Queue]    [Databases/Storage]**

##### Key Flows to Highlight

a. Video Upload Flow:
**User → Web Client → Cloud Storage → Pub/Sub →**
**Video Processing Service → Cloud Storage (processed) →**
**Firestore (metadata)**

b. Video Viewing Flow:
**User → Web Client → Firebase Functions →**
**Firestore (metadata) → Cloud Storage (video content)**

##### Important Details

- Security perimeters (public vs. private services)
- Load balancers and scaling components
- Environment separation (development/production)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "User Layer"
        User(("User"))
    end

    subgraph "Web Client Layer"
        WebClient["Next.js Web Client"]:::frontend
        Upload["Upload Component"]:::frontend
        SignIn["Sign-in Component"]:::frontend
        Watch["Video Watch Component"]:::frontend
        NavBar["Navigation Component"]:::frontend
        FirebaseAuth["Firebase Authentication"]:::auth
        FunctionsIntegration["Firebase Functions Integration"]:::frontend
    end

    subgraph "API Layer"
        APIService["Firebase Functions API"]:::api
    end

    subgraph "Processing Layer"
        VideoProcessing["Video Processing Service"]:::processing
    end

    subgraph "Storage Layer"
        CloudStorage[(Google Cloud Storage)]:::storage
        Firestore[(Cloud Firestore)]:::storage
    end

    subgraph "Message Queue Layer"
        PubSub{{"Cloud Pub/Sub"}}:::queue
    end

    %% Connections
    User --> WebClient
    User --> Upload
    User --> SignIn
    User --> Watch
    User --> NavBar

    WebClient --> FirebaseAuth
    WebClient --> FunctionsIntegration
    FunctionsIntegration --> APIService
    
    Upload --> CloudStorage
    CloudStorage --> PubSub
    PubSub --> VideoProcessing
    VideoProcessing --> CloudStorage
    VideoProcessing --> Firestore

    Watch --> APIService
    APIService --> Firestore
    APIService --> CloudStorage

    %% Click Events
    click WebClient "https://github.com/Skilledgamer101/youtube-clone/tree/main/yt-web-client"
    click Upload "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/navbar/upload.tsx"
    click SignIn "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/navbar/sign-in.tsx"
    click Watch "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/watch/page.tsx"
    click NavBar "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/navbar/navbar.tsx"
    click FirebaseAuth "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/firebase/firebase.ts"
    click FunctionsIntegration "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-web-client/app/firebase/functions.ts"
    click APIService "https://github.com/Skilledgamer101/youtube-clone/blob/main/yt-api-service/functions/src/index.ts"
    click VideoProcessing "https://github.com/Skilledgamer101/youtube-clone/tree/main/video-processing-service"
    click CloudStorage "https://github.com/Skilledgamer101/youtube-clone/blob/main/utils/gcs-cors.json"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef processing fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef queue fill:#f1c40f,stroke:#f39c12,color:black
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Service"]:::api
        Processing["Processing Service"]:::processing
        Storage["Storage Service"]:::storage
        Queue["Message Queue"]:::queue
        Auth["Authentication"]:::auth
    end
```
