# ykh815/youtubeclone architecture

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

- Interactive diagram: https://gitdiagram.com/ykh815/youtubeclone
- Repository: https://github.com/ykh815/youtubeclone

## Overview

##### Main Components

A. Frontend Layer:
- Client-side JavaScript components (from src/assets/js)
- Video Player
- Video Recorder
- Comment System
- Main Application Logic
- SCSS/CSS Styling System (from src/assets/scss)
- View Templates (Pug templates from src/views)

B. Backend Layer:
- Express.js Server (app.js and init.js)
- Authentication System (passport.js)
- Routes Layer (all files in src/routers)
- Controllers Layer (userController.js and videoController.js)
- Models Layer (User.js, Video.js, Comment.js)
- Database Layer (db.js)

**[Client Layer]**
- ↕
**[Web Server Layer]**
- ↕
**[Application Layer]**
- ↕
**[Data Layer]**

##### Specific Component Relationships

- Client requests flow through routes → controllers → models
- Authentication flows through passport.js middleware
- Asset compilation process (webpack) for JavaScript and SCSS
- Template rendering flow from controllers to views
- API endpoints for video and user operations

##### Key Interactions to Highlight

a. User Flow:
- Authentication paths (login, join, social login)
- Video upload and management
- Comment system interaction
- User profile management

b. Data Flow:
- Video storage and retrieval
- User data management
- Comment creation and association

##### Detailed Component Breakdown

Frontend:
**[Views Layer (Pug Templates)]**
- ↓
**[Asset Pipeline]**
- JavaScript Modules
- SCSS Stylesheets
- ↓
**[Browser-side Features]**
- Video Player
- Video Recorder
- Comment System

Backend:
**[Express Server]**
- ↓
**[Routers]**
- Global Router
- User Router
- Video Router
- API Router
- ↓
**[Controllers]**
- User Controller
- Video Controller
- ↓
**[Models]**
- User Model
- Video Model
- Comment Model
- ↓
**[Database]**

##### Additional Elements

- Middleware layer showing request processing
- Authentication flow with Passport.js
- Static asset handling
- Template rendering pipeline
- API endpoints for AJAX operations

##### Important Notes

- Clear separation between server-side and client-side code
- Where webpack fits in the asset compilation process
- MVC pattern implementation
- How social login integrates with the main authentication system
- Demonstrate the relationship between models and their corresponding controllers

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Browser Interface"]
        VP["Video Player"]:::frontend
        VR["Video Recorder"]:::frontend
        CS["Comment System"]:::frontend
        ML["Main Frontend Logic"]:::frontend
        Styles["Styling System"]:::frontend
        Templates["View Templates"]:::frontend
    end

    subgraph Server
        Express["Express Server"]:::backend
        Auth["Authentication System"]:::auth
        MW["Middleware Layer"]:::middleware

        subgraph "Routes Layer"
            GR["Global Router"]:::route
            UR["User Router"]:::route
            VDR["Video Router"]:::route
            AR["API Router"]:::route
        end

        subgraph "Controllers Layer"
            UC["User Controller"]:::controller
            VC["Video Controller"]:::controller
        end

        subgraph "Models Layer"
            UM["User Model"]:::model
            VM["Video Model"]:::model
            CM["Comment Model"]:::model
        end

        DB["Database"]:::database
    end

    Browser --> Express
    Express --> MW
    MW --> Auth
    MW --> |Route Handling| GR
    MW --> |Route Handling| UR
    MW --> |Route Handling| VDR
    MW --> |Route Handling| AR

    GR --> UC
    GR --> VC
    UR --> UC
    VDR --> VC
    AR --> UC
    AR --> VC

    UC --> UM
    VC --> VM
    VC --> CM

    UM --> DB
    VM --> DB
    CM --> DB

    %% Click Events
    click Express "https://github.com/ykh815/youtubeclone/blob/master/src/app.js"
    click VP "https://github.com/ykh815/youtubeclone/blob/master/src/assets/js/videoPlayer.js"
    click VR "https://github.com/ykh815/youtubeclone/blob/master/src/assets/js/videoRecorder.js"
    click CS "https://github.com/ykh815/youtubeclone/blob/master/src/assets/js/addComment.js"
    click ML "https://github.com/ykh815/youtubeclone/blob/master/src/assets/js/main.js"
    click Styles "https://github.com/ykh815/youtubeclone/blob/master/src/assets/scss/main.scss"
    click Templates "https://github.com/ykh815/youtubeclone/tree/master/src/views"
    click GR "https://github.com/ykh815/youtubeclone/blob/master/src/routers/globalRouter.js"
    click UR "https://github.com/ykh815/youtubeclone/blob/master/src/routers/userRouter.js"
    click VDR "https://github.com/ykh815/youtubeclone/blob/master/src/routers/videoRouter.js"
    click AR "https://github.com/ykh815/youtubeclone/blob/master/src/routers/apiRouter.js"
    click UC "https://github.com/ykh815/youtubeclone/blob/master/src/controllers/userController.js"
    click VC "https://github.com/ykh815/youtubeclone/blob/master/src/controllers/videoController.js"
    click UM "https://github.com/ykh815/youtubeclone/blob/master/src/models/User.js"
    click VM "https://github.com/ykh815/youtubeclone/blob/master/src/models/Video.js"
    click CM "https://github.com/ykh815/youtubeclone/blob/master/src/models/Comment.js"
    click DB "https://github.com/ykh815/youtubeclone/blob/master/src/db.js"
    click Auth "https://github.com/ykh815/youtubeclone/blob/master/src/passport.js"
    click MW "https://github.com/ykh815/youtubeclone/blob/master/src/middlewares.js"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef route fill:#e74c3c,stroke:#c0392b,color:white
    classDef controller fill:#f1c40f,stroke:#f39c12,color:black
    classDef model fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#34495e,stroke:#2c3e50,color:white
    classDef auth fill:#e67e22,stroke:#d35400,color:white
    classDef middleware fill:#95a5a6,stroke:#7f8c8d,color:white
```
