# washington-kibichii/youtube-clone-mern architecture

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

- Interactive diagram: https://gitdiagram.com/washington-kibichii/youtube-clone-mern
- Repository: https://github.com/washington-kibichii/youtube-clone-mern

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) YouTube clone.
- Purpose: allow users to register/login (JWT), upload/view videos (stored in Firebase Storage), interact via likes/comments, manage channels/playlists, and use a “Studio” interface for content management.

##### File structure
- Top-level:
- docker-compose.yml – orchestrates services in Docker
- frontend/ – React single-page app
- backend/ – Node/Express API server with Handlebars views for password/reset flows
- backend/ breakdown:
- Database/ (database.js) – MongoDB connection setup
- Models/ – Mongoose schemas (user, videos, trending)
- Router/ – Express route modules (auth, videos, comments, likes, channel, studio)
- public/ & views/ – static assets & HBS templates for emails/reset pages
- server.js, Dockerfile, vercel.json – entrypoint, deployment config
- frontend/ breakdown:
- src/ – React code (App.jsx, Components/, Firebase.js, main.jsx, CSS, assets)
- public/, index.html, netlify.toml, Dockerfile, vite.config.js – bundling, hosting, deployment

##### README insights
- Deployment: Frontend on Netlify (netlify.toml), backend on Vercel (vercel.json) or via Docker Compose
- Features: auth flows, video CRUD, playlists, studio, responsive UI

a. Main components
- React Frontend (SPA hosted on Netlify or Docker)
- Node/Express Backend API (with Handlebars views for email flows)
- MongoDB (Atlas or local via Docker)
- Firebase Storage (video/file storage)
- External Email Service (via Nodemailer using GMail SMTP)
- Docker Compose (local orchestration) or cloud hosts (Netlify, Vercel)
b. Relationships & interactions
1. User’s browser ⇄ React Frontend (HTTP/WS)
2. Frontend → Backend API (REST calls with Bearer JWT)
3. Backend → MongoDB (Mongoose queries)
4. Backend → Firebase Storage (upload/download via SDK)
5. Backend → Email Service (password reset emails)
6. Docker Compose connects Frontend, Backend, MongoDB in local dev
c. Architectural patterns & principles
- Client-Server separation (React SPA vs. REST API)
- MVC on backend: Router (controllers) → Models → Database
- Stateless JWT authentication
- Externalize large-object storage (Firebase) rather than DB blobs
- Deploy via containers or serverless platforms
d. Key technologies/frameworks
- React + Vite (frontend bundler)
- Express.js + Node.js (backend)
- Mongoose + MongoDB Atlas or local Docker container
- Firebase Storage SDK
- JSON Web Tokens for auth
- Docker & docker-compose for local orchestration
- Netlify (frontend), Vercel (backend) as deployment targets

##### Detail
- Mongoose Models interacting in the backend layer
- That JWT tokens travel in HTTP headers between FE and BE

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["User’s Browser"]:::presentation

    subgraph "Presentation Layer"
        ReactSPA["React SPA"]:::frontend
    end

    subgraph "Application Layer"
        ExpressAPI["Express API"]:::backend
        subgraph "Routers"
            auth["auth.js"]:::backend
            vids["videos.js"]:::backend
            comm["comments.js"]:::backend
            likes["likes.js"]:::backend
            chan["channel.js"]:::backend
            studio["studio.js"]:::backend
        end
        subgraph "Database Config"
            dbjs["database.js"]:::data
        end
    end

    subgraph "Infrastructure & Services"
        MongoDB["MongoDB"]:::data
        FirebaseStorage["Firebase Storage"]:::data
        EmailService["Email SMTP"]:::data
    end

    subgraph "Local Dev Orchestration"
        DockerCompose["docker-compose.yml"]:::infra
    end

    Browser -->|"HTTP/HTTPS"| ReactSPA
    ReactSPA -->|"REST API calls (Bearer JWT)"| ExpressAPI
    ExpressAPI --> dbjs
    dbjs --> MongoDB
    ExpressAPI -->|"Mongoose Queries"| MongoDB
    ExpressAPI -->|"SDK Upload/Download"| FirebaseStorage
    ExpressAPI -->|"Send emails"| EmailService
    DockerCompose --> ReactSPA
    DockerCompose --> ExpressAPI
    DockerCompose --> MongoDB

    %% Click Events
    click ReactSPA "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/frontend/src/"
    click main.jsx "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/main.jsx"
    click App.jsx "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/App.jsx"
    click FirebaseJS "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Firebase.js"
    click ComponentsDir "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/frontend/src/Components/"
    click CssDir "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/frontend/src/Css/"
    click ExpressAPI "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/server.js"
    click VercelConf "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/vercel.json"
    click BackendDocker "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/backend/Dockerfile"
    click dbjs "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Database/database.js"
    click auth "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/auth.js"
    click vids "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/videos.js"
    click comm "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/comments.js"
    click likes "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/likes.js"
    click chan "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/channel.js"
    click studio "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/Router/studio.js"
    click Signin "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Signin.jsx"
    click Signup "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Signup.jsx"
    click Reset "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Reset.jsx"
    click VideoSection "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/VideoSection.jsx"
    click WatchLater "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/WatchLater.jsx"
    click StudioComments "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Studio/Comments.jsx"
    click LikeVideos "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/LikeVideos.jsx"
    click ChannelDir "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/frontend/src/Components/Channel/"
    click StudioDir "https://github.com/washington-kibichii/youtube-clone-mern/tree/main/frontend/src/Components/Studio/"
    click Trending "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Trending.jsx"
    click Playlists "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Playlists.jsx"
    click ChannelPlaylists "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Channel/ChannelPlaylists.jsx"
    click Library "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/src/Components/Library.jsx"
    click resetCss "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/public/css/reset.css"
    click resetHbs "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/views/reset-password.hbs"
    click doneHbs "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/backend/views/done.hbs"
    click DockerCompose "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/docker-compose.yml"
    click NetlifyConf "https://github.com/washington-kibichii/youtube-clone-mern/blob/main/frontend/netlify.toml"

    classDef frontend fill:#9f6,stroke:#333,stroke-width:1px
    classDef backend fill:#6cf,stroke:#333,stroke-width:1px
    classDef data fill:#ccc,stroke:#333,stroke-width:1px
    classDef infra fill:#aaa,stroke:#333,stroke-width:1px
    classDef presentation fill:#afa,stroke:#333,stroke-width:1px
```
