# punkmohamed/youtube-clone architecture

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

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

## Overview

##### Project type and purpose
- This is a front-end Single Page Application (SPA) built with React, TypeScript, Vite, and Tailwind CSS.
- Its purpose is to provide a YouTube-style UI: home page with trending videos, categories (music, gaming, movies), shorts, detail pages, and a user profile page.

##### File structure
- Top-level config:
- vite.config.ts (bundler/dev server)
- tsconfig.json / tsconfig.app.json / tsconfig.node.json (TypeScript settings)
- eslint.config.js (lint rules)
- tailwind.config.js / postcss.config.js (CSS tooling)
- package.json / package-lock.json (dependencies + scripts)
- vercel.json (deployment settings)
- “public” folder: static assets and index.html entry point
- “src” folder:
- main.tsx + index.css: application bootstrap & global styles
- App.tsx: root React component
- layouts/: top-level UI wrappers (PageHeader, SideBar, Layouts)
- pages/: route-level views (Home, Detail, Shorts, Trending, YoutubeProfile)
- components/: reusable UI components (VideoGrid, TrendingNow, RelatedVideos, Buttons, etc.)
- context/: React Context providers (API_KEYS, videoContext, SideBarContext)
- data/: static mock data (home.ts, sidebar.ts)
- utils/: pure helper functions (formatDuration, formatTimeAgo, etc.)

##### README
- Confirms React + TypeScript + Vite setup with optional ESLint/TypeScript linting strategies.
- Mentions official Vite plugins for React Fast Refresh (Babel or SWC).

a. Developer environment & CI/CD
- Git repository → (push) → Vercel CI/CD pipeline
- Vercel build uses Vite to compile TS/JS and process Tailwind CSS
- Result: static assets deployed to CDN
b. Client-side layers
- Browser loads index.html + CSS + JS bundle
- Vite-generated JS bundle containing:
- App.tsx (root)
- Layout components (layouts/)
- Page components (pages/)
- Reusable UI components (components/)
- Context providers (context/)
- Utility modules (utils/)
- Static data (data/)
c. External services
- YouTube Data API (REST endpoints)
- Potential environment variables (API_KEYS)

##### Relationships & interactions
- User → Browser → loads React SPA → App.tsx
- App.tsx wraps children in Context providers (SideBarContext, videoContext)
- Pages invoke context hooks or direct API calls:
- videoContext fetches video lists (trending, search, profile playlists) from YouTube Data API
- API_KEYS context provides credentials
- Components consume context state + props to render UI
- Utils format data for display
- Static data (data/home.ts, data/sidebar.ts) seed initial UI (e.g., sidebar links)
- Tailwind CSS: styling injected at build time

##### Architectural patterns & design principles
- Component-based UI (React)
- Single Responsibility: each component, page, utility file has one purpose
- Context API for global state (sidebar open/closed, current video lists, API keys)
- Separation of concerns: layouts vs. pages vs. components vs. utils vs. static data

##### Detailed breakdown
- CI/CD & Deployment layer: GitHub/VCS → Vercel CI → Vite build → CDN
- Static assets layer: public/index.html + assets → served by CDN
- Bundling layer: Vite (plugins: plugin-react or plugin-react-swc), PostCSS, Tailwind
- Client runtime:
[App.tsx]
├─ [SideBarContext]
├─ [videoContext]
├─ [Pages (Home, Detail, Shorts, Trending, YoutubeProfile)]
│       └─ use Context or API calls
├─ [Layouts (SideBar, PageHeader, Layouts)]
├─ [Components (VideoGrid, TrendingNow, RelatedVideos, etc.)]
├─ [Utils (formatDuration, formatTimeAgo, …)]
└─ [Data (home.ts, sidebar.ts)]
- External API: YouTube Data API (key managed by API_KEYS context)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD & Deployment
    GitRepo["Git Repository"]:::external
    VercelCI["Vercel CI/CD Pipeline"]:::cdn
    ViteBuild["Vite Build\n(compile TS/JS, Tailwind CSS)"]:::build
    CDN["CDN (Static Assets)"]:::cdn

    GitRepo -->|git push| VercelCI
    VercelCI -->|build| ViteBuild
    ViteBuild -->|deploy| CDN

    %% Configurations & Public
    subgraph "Config & Entry"
        ViteConfig["vite.config.ts"]:::build
        TailwindConfig["tailwind.config.js"]:::build
        PostCSSConfig["postcss.config.js"]:::build
        TSConfigs["tsconfig.json\n tsconfig.app.json\n tsconfig.node.json"]:::build
        ESLintConfig["eslint.config.js"]:::build
        VercelConfig["vercel.json"]:::cdn
        PublicDir["public/"]:::external
        IndexHTML["index.html"]:::external
    end

    ViteBuild --> ViteConfig
    ViteBuild --> TailwindConfig
    ViteBuild --> PostCSSConfig
    ViteBuild --> TSConfigs
    ViteBuild --> ESLintConfig
    VercelCI --> VercelConfig
    CDN --> PublicDir
    PublicDir --> IndexHTML

    %% Bundling outputs to Browser
    CDN -->|serve index.html + assets| Browser["Browser"]:::external

    %% Application Bootstrap
    subgraph "Application Bootstrap" 
        MainTSX["src/main.tsx"]:::frontend
        IndexCSS["src/index.css"]:::frontend
    end
    Browser --> MainTSX
    Browser --> IndexCSS

    %% Client Runtime
    subgraph "Client Runtime" 
        App["App.tsx"]:::frontend
        subgraph "Layouts"
            LayoutsComp["Layouts.tsx"]:::frontend
            PageHeader["PageHeader.tsx"]:::frontend
            SideBarLayout["SideBar.tsx"]:::frontend
        end
        subgraph "Pages"
            HomePage["Home.tsx"]:::frontend
            DetailPage["Detail.tsx"]:::frontend
            ShortsPage["Shorts.tsx"]:::frontend
            TrendingPage["Trending.tsx"]:::frontend
            ProfilePage["YoutubeProfile.tsx"]:::frontend
        end
        subgraph "Components"
            VideoGrid["VideoGrid.tsx"]:::frontend
            TrendingNow["TrendingNow.tsx"]:::frontend
            TrendingMusic["TrendingMusic.tsx"]:::frontend
            TrendingGaming["TrendingGaming.tsx"]:::frontend
            TrendingMovies["TrendingMovies.tsx"]:::frontend
            RelatedVideos["RelatedVideos.tsx"]:::frontend
            ShortsComp["youtubeShorts.tsx"]:::frontend
            ButtonComp["Button.tsx"]:::frontend
            Categories["CategoriesPills.tsx"]:::frontend
            AboutModel["AboutModel.tsx"]:::frontend
            ProfileHome["ProfileHomeSection.tsx"]:::frontend
            ProfilePlaylists["ProfilePlaylists.tsx"]:::frontend
            ProfileShorts["ProfileShortsSection.tsx"]:::frontend
            ProfileVideos["ProfileVideosSection.tsx"]:::frontend
        end
        subgraph "Context Providers"
            APIKEYs["API_KEYS.tsx"]:::frontend
            SideBarCtx["SideBarContext.tsx"]:::frontend
            VideoCtx["videoContext.tsx"]:::frontend
        end
        subgraph "Data & Utils"
            DataHome["home.ts"]:::frontend
            DataSidebar["sidebar.ts"]:::frontend
            UtilsDuration["formatDuration.ts"]:::frontend
            UtilsTimeAgo["formatTimeAgo.ts"]:::frontend
            UtilsVidDur["formatVideoDuration.ts"]:::frontend
        end
    end

    MainTSX --> App
    App --> APIKEYs
    App --> SideBarCtx
    App --> VideoCtx
    App --> LayoutsComp
    App --> PageHeader
    App --> SideBarLayout
    App --> HomePage
    App --> DetailPage
    App --> ShortsPage
    App --> TrendingPage
    App --> ProfilePage

    HomePage --> VideoGrid
    HomePage --> TrendingNow
    HomePage --> DataHome
    HomePage --> DataSidebar

    DetailPage --> RelatedVideos
    ShortsPage --> ShortsComp
    TrendingPage --> TrendingMusic
    TrendingPage --> TrendingGaming
    TrendingPage --> TrendingMovies

    ProfilePage --> ProfileHome
    ProfilePage --> ProfilePlaylists
    ProfilePage --> ProfileShorts
    ProfilePage --> ProfileVideos

    AllComps-->UtilsDuration
    AllComps-->UtilsTimeAgo
    AllComps-->UtilsVidDur

    %% External API
    YouTubeAPI["YouTube Data API"]:::external
    VideoCtx -->|fetch video lists| YouTubeAPI
    APIKEYs --> YouTubeAPI

    %% Click Events
    click ViteConfig "https://github.com/punkmohamed/youtube-clone/blob/main/vite.config.ts"
    click TailwindConfig "https://github.com/punkmohamed/youtube-clone/blob/main/tailwind.config.js"
    click PostCSSConfig "https://github.com/punkmohamed/youtube-clone/blob/main/postcss.config.js"
    click TSConfigs "https://github.com/punkmohamed/youtube-clone/blob/main/tsconfig.json"
    click TSConfigs "https://github.com/punkmohamed/youtube-clone/blob/main/tsconfig.app.json"
    click TSConfigs "https://github.com/punkmohamed/youtube-clone/blob/main/tsconfig.node.json"
    click ESLintConfig "https://github.com/punkmohamed/youtube-clone/blob/main/eslint.config.js"
    click VercelConfig "https://github.com/punkmohamed/youtube-clone/blob/main/vercel.json"
    click PublicDir "https://github.com/punkmohamed/youtube-clone/tree/main/public/"
    click IndexHTML "https://github.com/punkmohamed/youtube-clone/blob/main/index.html"
    click MainTSX "https://github.com/punkmohamed/youtube-clone/blob/main/src/main.tsx"
    click IndexCSS "https://github.com/punkmohamed/youtube-clone/blob/main/src/index.css"
    click App "https://github.com/punkmohamed/youtube-clone/blob/main/src/App.tsx"
    click LayoutsComp "https://github.com/punkmohamed/youtube-clone/blob/main/src/layouts/Layouts.tsx"
    click PageHeader "https://github.com/punkmohamed/youtube-clone/blob/main/src/layouts/PageHeader.tsx"
    click SideBarLayout "https://github.com/punkmohamed/youtube-clone/blob/main/src/layouts/SideBar.tsx"
    click HomePage "https://github.com/punkmohamed/youtube-clone/blob/main/src/pages/Home.tsx"
    click DetailPage "https://github.com/punkmohamed/youtube-clone/blob/main/src/pages/Detail.tsx"
    click ShortsPage "https://github.com/punkmohamed/youtube-clone/blob/main/src/pages/Shorts.tsx"
    click TrendingPage "https://github.com/punkmohamed/youtube-clone/blob/main/src/pages/Trending.tsx"
    click ProfilePage "https://github.com/punkmohamed/youtube-clone/blob/main/src/pages/YoutubeProfile.tsx"
    click VideoGrid "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/VideoGrid.tsx"
    click TrendingNow "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/TrendingNow.tsx"
    click TrendingMusic "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/TrendingMusic.tsx"
    click TrendingGaming "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/TrendingGaming.tsx"
    click TrendingMovies "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/TrendingMovies.tsx"
    click RelatedVideos "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/RelatedVideos.tsx"
    click ShortsComp "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/youtubeShorts.tsx"
    click ButtonComp "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/Button.tsx"
    click Categories "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/CategoriesPills.tsx"
    click AboutModel "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/AboutModel.tsx"
    click ProfileHome "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/ProfileHomeSection.tsx"
    click ProfilePlaylists "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/ProfilePlaylists.tsx"
    click ProfileShorts "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/ProfileShortsSection.tsx"
    click ProfileVideos "https://github.com/punkmohamed/youtube-clone/blob/main/src/components/ProfileVideosSection.tsx"
    click APIKEYs "https://github.com/punkmohamed/youtube-clone/blob/main/src/context/API_KEYS.tsx"
    click SideBarCtx "https://github.com/punkmohamed/youtube-clone/blob/main/src/context/SideBarContext.tsx"
    click VideoCtx "https://github.com/punkmohamed/youtube-clone/blob/main/src/context/videoContext.tsx"
    click DataHome "https://github.com/punkmohamed/youtube-clone/blob/main/src/data/home.ts"
    click DataSidebar "https://github.com/punkmohamed/youtube-clone/blob/main/src/data/sidebar.ts"
    click UtilsDuration "https://github.com/punkmohamed/youtube-clone/blob/main/src/utils/formatDuration.ts"
    click UtilsTimeAgo "https://github.com/punkmohamed/youtube-clone/blob/main/src/utils/formatTimeAgo.ts"
    click UtilsVidDur "https://github.com/punkmohamed/youtube-clone/blob/main/src/utils/formatVideoDuration.ts"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef build fill:#ffe0b2,stroke:#fb8c00,stroke-width:1px
    classDef external fill:#c8e6c9,stroke:#43a047,stroke-width:1px
    classDef cdn fill:#d1c4e9,stroke:#7e57c2,stroke-width:1px
```
