# equador8078/dangle-video-watching-platform architecture

> Architecture diagram of the GitHub repository equador8078/dangle-video-watching-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/equador8078/dangle-video-watching-platform
- Repository: https://github.com/equador8078/dangle-video-watching-platform

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Dangle”) inspired by YouTube, built on the MERN stack.
- Purpose: allow authenticated users to upload, watch, comment on, and manage videos, backed by AI-powered search and recommendation.

##### File Structure
- Top-level split into two folders:
- yt-backend: Express.js server, controllers, services, models, middleware, routes, and public static handlers.
- yt-frontend: React/Vite client with components, contexts, assets, routing, styling (Tailwind).
- Additional root files: .env sample, package.json scripts to orchestrate both halves.
- Patterns:
- Backend uses MVC‐like structure (models, controllers, routes).
- Frontend uses component-driven UI + Context API for state (AuthContext, PanelContext, SubscriptionContext).

##### README for Insights
- Tech stack enumerated (React, Express, MongoDB, Cloudinary, TensorFlow.js).
- Features highlight authentication (JWT), video storage (Cloudinary + Multer), comments, playlists, history, AI chat search, and recommendation.
- Points to live demo and environment variables.

##### Main Components
a. Frontend (React SPA)
- Entry: main.jsx → App.jsx → React Router
- Key UI modules: VideoSection, VideoCard, Chat/Search widget, Playlist manager, Upload form.
- Context layers: AuthContext, SubscriptionContext, PanelContext.
b. Backend (Express REST API)
- Controllers: user, video, comments, playlist, chat/embedding.
- Services: authentication, Cloudinary integration.
- Middleware: JWT authentication.
- Models: MongoDB schemas via Mongoose.
c. Data Layer
- MongoDB cluster (stores users, videos metadata, comments, playlists, watch history).
- Cloudinary (actual video/image storage).
d. AI & External Services
- TensorFlow.js + Universal Sentence Encoder (runs in browser or server to compute embeddings).
- Cosine similarity module for recommendations.
e. Client-Server Interaction
- Axios calls from frontend to backend API endpoints.
- Static asset upload via Multer → Cloudinary SDK.

##### Relationships and Data Flow
- User → React UI
- Clicks “Upload” → POST /api/video → Multer middleware → Cloudinary → MongoDB save.
- Auth workflow → /api/auth/login or signup → JWT cookie issued.
- React UI → Express API
- GET /api/video/:id → video metadata + secure Cloudinary URL.
- POST /api/comments → create comment in MongoDB.
- GET /api/chat/search → embedding endpoint returns search results.
- Backend → MongoDB & Cloudinary
- Mongoose drives CRUD.
- Cloudinary SDK handles file transfers.
- Recommendation engine
- On video view, compute or retrieve precomputed embeddings → cosine similarity → suggested video list.

##### Architectural Patterns and Principles
- Separation of concerns:
- Frontend UI vs. Backend API vs. Data store vs. Media store.
- Layered architecture: Controllers → Services → Models in backend.
- Stateless JWT authentication.
- Component-based UI with Context for state.
- API-first design exposing RESTful endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser / React SPA"
        direction TB
        Main["main.jsx"]:::frontend
        App["App.jsx"]:::frontend
        AuthCtx["AuthContext"]:::frontend
        PanelCtx["PanelContext"]:::frontend
        SubCtx["SubscriptionContext"]:::frontend
        VideoSection["VideoSection"]:::frontend
        VideoCard["VideoCard"]:::frontend
        ChatWidget["Chat/Search Widget"]:::frontend
        UploadForm["Upload Form"]:::frontend
        subgraph "Playlist Module"
            direction TB
            PlContainer["playList.jsx"]:::frontend
            PlCard["playlistCard.jsx"]:::frontend
            PlPop["playlistPop.jsx"]:::frontend
            PlVideo["playlistVideo.jsx"]:::frontend
        end
        TensorFlow["TensorFlow.js (Embeddings)"]:::external
    end

    subgraph "API Server (Express)"
        direction TB
        Server["index.js"]:::api
        subgraph Controllers
            direction TB
            UserCtrl["UserController"]:::api
            VideoCtrl["VideoController"]:::api
            CommentsCtrl["CommentsController"]:::api
            PlaylistCtrl["PlaylistController"]:::api
            ChatCtrl["ChatController"]:::api
            EmbeddingCtrl["EmbeddingController"]:::api
        end
        subgraph Services
            direction TB
            AuthService["Authentication Service"]:::api
            CloudinarySetup["Cloudinary Integration"]:::api
        end
        JWTMiddleware["JWT Authentication Middleware"]:::api
        subgraph Models
            direction TB
            UserModel["User Model"]:::api
            VideoModel["Video Model"]:::api
            CommentsModel["Comments Model"]:::api
            PlaylistModel["Playlist Model"]:::api
        end
        subgraph Routes
            direction TB
            UserRoutes["User Routes"]:::api
            VideoRoutes["Video Routes"]:::api
            CommentsRoutes["Comments Routes"]:::api
            ChatRoutes["Chat Routes"]:::api
        end
        StaticUploadHandler["Static Upload Handler"]:::api
    end

    MongoDB["MongoDB Cluster"]:::data
    Cloudinary["Cloudinary"]:::external

    %% Client Flow
    Main --> App
    App --> AuthCtx
    App --> PanelCtx
    App --> SubCtx
    App --> VideoSection
    VideoSection --> VideoCard
    App --> ChatWidget
    App --> UploadForm
    App --> PlContainer
    PlContainer --> PlCard
    PlContainer --> PlPop
    PlContainer --> PlVideo
    VideoSection --> TensorFlow

    App -->|Axios HTTP| Server
    ChatWidget -->|GET /api/chat/search| Server
    UploadForm -->|POST /api/video| Server

    %% Server Flow
    Server --> Controllers
    Controllers --> Services
    Controllers --> Models
    Server --> JWTMiddleware
    Server --> Routes
    Server --> StaticUploadHandler
    Server -->|CRUD| MongoDB
    Server -->|Upload/Download| Cloudinary

    classDef frontend fill:#e0f7fa,stroke:#333,stroke-width:1px
    classDef api fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef data fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef external fill:#e1bee7,stroke:#333,stroke-width:1px

    %% Click Events
    click Main "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/main.jsx"
    click App "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/App.jsx"
    click AuthCtx "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/context/AuthContext.jsx"
    click PanelCtx "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/context/PanelContext.jsx"
    click SubCtx "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/context/SubscriptionContext.jsx"
    click VideoSection "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/VideoSection.jsx"
    click VideoCard "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/VideoCard.jsx"
    click ChatWidget "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/home.jsx"
    click UploadForm "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/uploadVideo.jsx"
    click PlContainer "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/playlist/playList.jsx"
    click PlCard "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/playlist/playlistCard.jsx"
    click PlPop "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/playlist/playlistPop.jsx"
    click PlVideo "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-frontend/src/components/playlist/playlistVideo.jsx"
    click UserCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/user.js"
    click VideoCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/video.js"
    click CommentsCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/comments.js"
    click PlaylistCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/playlist.js"
    click ChatCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/chat.js"
    click EmbeddingCtrl "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/controllers/embedding.js"
    click AuthService "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/services/authentication.js"
    click CloudinarySetup "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/cloudinary.js"
    click JWTMiddleware "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/middleware/authentication.js"
    click UserModel "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/models/user.js"
    click VideoModel "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/models/video.js"
    click CommentsModel "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/models/comments.js"
    click PlaylistModel "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/models/playlist.js"
    click VideoRoutes "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/routes/video.js"
    click UserRoutes "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/routes/user.js"
    click CommentsRoutes "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/routes/comments.js"
    click ChatRoutes "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/routes/chat.js"
    click Server "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/index.js"
    click StaticUploadHandler "https://github.com/equador8078/dangle-video-watching-platform/blob/main/yt-backend/public/uploads.js"
```
