# phuongnam195/youtube-clone architecture

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

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

## Overview

##### Main Components

A. Application Layer
- Main App Entry Point
- Main Screen (Tab-based Navigation)

B. Feature Modules
- Home Feature
- Shorts Feature
- Watching Feature

C. Core Layer
- Components
- Repositories
- Entity Models
- Network Services
- Dependency Injection

**┌─────────────────────────────────────────────┐**
- UI Layer                     │
- ┬──────────────┬───────────────┤
- Home       │   Shorts     │   Watching    │
- Feature    │   Feature    │   Feature     │
- ┴──────────────┴───────────────┤
- Core Layer                     │
- ┤
- Dependency Injection Layer          │
- ┤
- Network Layer                    │
- ┘

##### Detailed Component Breakdown

- Blue rectangles for UI components
- Green rectangles for business logic/repositories
- Yellow diamonds for services
- Purple rectangles for models/entities

B. Show specific relationships:
- ServiceLocator → Repositories
- Repositories → Network Services
- ViewModels → Repositories
- Views → ViewModels

##### Key Architectural Patterns to Highlight

A. MVVM Architecture:
- Views (Screens and Components)
- ViewModels (PlayingViewModel, WatchingViewModel)
- Models (Video, Channel, VideoCategory)

B. Repository Pattern:
- VideoRepository
- ChannelRepository
- VideoCategoryRepository
- PexelsRepository

C. Dependency Injection:
- ServiceLocator
- ServiceRegistry

##### Important Details

A. Data Flow:
- API calls flow (ApiConstants → Repositories → ViewModels → Views)
- Video playback flow (WatchingScreen → PlayingViewModel → VideoPlayingView)
- Content loading flow (Home → Repository → Network → Models)

B. Component Communication:
- How features interact with core components
- Demonstrate dependency injection flow
- Data passing between screens

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        AppEntry["Main App Entry"]
        MainNav["Main Navigation"]
    end

    subgraph "Feature Modules"
        subgraph "Home Feature"
            HomeScreen["Home Screen"]
        end
        
        subgraph "Shorts Feature"
            ShortsScreen["Shorts Screen"]
        end
        
        subgraph "Watching Feature"
            WatchingScreen["Watching Screen"]
            PlayingVM["Playing ViewModel"]
            WatchingVM["Watching ViewModel"]
        end
    end

    subgraph "Core Layer"
        subgraph "Components"
            UIComp["UI Components"]
        end
        
        subgraph "Services"
            ApiConst["API Constants"]
            NetworkService["Network Service"]
        end
        
        subgraph "Models"
            EntityModels["Entity Models"]
            ResponseModels["Response Models"]
        end
        
        subgraph "Repositories"
            VideoRepo["Video Repository"]
            ChannelRepo["Channel Repository"]
            VideoCatRepo["Video Category Repository"]
            PexelsRepo["Pexels Repository"]
        end
        
        subgraph "Dependency Injection"
            ServiceLoc["Service Locator"]
            ServiceReg["Service Registry"]
        end
    end

    %% Relationships
    AppEntry --> MainNav
    MainNav --> HomeScreen
    MainNav --> ShortsScreen
    MainNav --> WatchingScreen
    
    WatchingScreen --> PlayingVM
    WatchingScreen --> WatchingVM
    
    ServiceLoc --> ServiceReg
    ServiceReg --> VideoRepo
    ServiceReg --> ChannelRepo
    ServiceReg --> VideoCatRepo
    ServiceReg --> PexelsRepo
    
    VideoRepo --> NetworkService
    ChannelRepo --> NetworkService
    VideoCatRepo --> NetworkService
    PexelsRepo --> NetworkService
    
    NetworkService --> ApiConst
    NetworkService --> ResponseModels
    ResponseModels --> EntityModels

    %% Click Events
    click AppEntry "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Main.swift"
    click MainNav "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/MainScreen.swift"
    click HomeScreen "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Features/Home/Screen/HomeScreen.swift"
    click ShortsScreen "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Features/Shorts/View/ShortsScreen.swift"
    click WatchingScreen "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Features/Watching/Screen/WatchingScreen.swift"
    click PlayingVM "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Features/Watching/ViewModel/PlayingViewModel.swift"
    click WatchingVM "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Features/Watching/ViewModel/WatchingViewModel.swift"
    click UIComp "https://github.com/phuongnam195/youtube-clone/tree/main/Youtube Clone/Core/Component/"
    click ApiConst "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/Constant/ApiConstants.swift"
    click EntityModels "https://github.com/phuongnam195/youtube-clone/tree/main/Youtube Clone/Core/Entity/"
    click ResponseModels "https://github.com/phuongnam195/youtube-clone/tree/main/Youtube Clone/Core/Model/"
    click ServiceLoc "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/DI/ServiceLocator.swift"
    click ServiceReg "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/DI/ServiceRegistry.swift"
    click VideoRepo "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/Repository/VideoRepository.swift"
    click ChannelRepo "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/Repository/ChannelRepository.swift"
    click VideoCatRepo "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/Repository/VideoCategoryRepository.swift"
    click PexelsRepo "https://github.com/phuongnam195/youtube-clone/blob/main/Youtube Clone/Core/Repository/PexelsRepository.swift"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef feature fill:#d4e6f1,stroke:#2874a6
    classDef service fill:#f9e79f,stroke:#d4ac0d
    classDef repository fill:#d5f5e3,stroke:#1e8449
    classDef model fill:#e8daef,stroke:#8e44ad
    classDef di fill:#fadbd8,stroke:#c0392b
    
    class HomeScreen,ShortsScreen,WatchingScreen,PlayingVM,WatchingVM feature
    class ApiConst,NetworkService service
    class VideoRepo,ChannelRepo,VideoCatRepo,PexelsRepo repository
    class EntityModels,ResponseModels model
    class ServiceLoc,ServiceReg di
```
