# divesh1207/videosfilter architecture

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

- Interactive diagram: https://gitdiagram.com/divesh1207/videosfilter
- Repository: https://github.com/divesh1207/videosfilter

## Overview

##### Project type and purpose
- This is a full-stack MERN web application called “Videos Filter.”
- Purpose: Let users log in with Google OAuth, fetch their YouTube “Liked Videos” via the YouTube Data API, store any needed metadata in MongoDB, then display and filter those videos through a React/Tailwind frontend.

##### File structure
- Top-level “client” folder: Vite + React (JSX), Tailwind, Framer Motion, OAuth callback component, public/static assets, and deployment config (vercel.json).
- Top-level “server” folder: Express app (server.js), controllers (authController, videoController), routes (authRoutes, videoRoutes), middlewares (authMiddleware), services (nlpService), configuration (db.js, keys.js), Mongoose models (User, Video).
- Presence of package.json in both indicates independent front-end/back-end projects.
- No Docker/Docker-Compose—likely two distinct deployments (Vercel for client, Heroku/AWS/GCP for server).

##### Extract architecture insights from the README
- Tech stack: React + Tailwind CSS + Framer Motion on front; Node.js + Express on back; MongoDB; Google OAuth 2.0; YouTube Data API; JWT for session management.
- Workflow: OAuth login → obtain access & refresh tokens → fetch liked videos → apply filters → display results.
- CORS settings, token refresh logic, MVC/Layered code structure.

##### Main components
a. Frontend (Client–React App)
b. Backend (Express REST API)
c. Database (MongoDB)
d. External Services:
– Google OAuth 2.0 Authorization Server
– YouTube Data API
e. (Optional) NLP Service layer inside backend for advanced filtering

##### Relationships and data flows
- User (Browser) ←→ React App (Login page, Navbar, OAuthCallback component)
- React invokes `GET /api/auth/google` → Redirect to Google OAuth.
- Google redirects back with auth code → React calls `POST /api/auth/callback`.
- Backend exchanges code for access/refresh tokens → issues JWTs.
- React stores JWT (e.g., in HttpOnly cookie or localStorage).
- React requests liked videos: `GET /api/videos?filter=…` → Express middleware validates JWT → videoController calls nlpService (optional) → videoController fetches from YouTube Data API if not cached, stores or updates Video documents in MongoDB → returns filtered list.
- MongoDB:
- User collection stores user info + refresh token.
- Video collection stores metadata about liked videos (title, desc, date, stats).

##### Architectural patterns & design principles
- Layered (MVC-style):
- Routes → Controllers → Services → Models
- Stateless REST API with JWT for auth
- Single-page application front end (client-side routing via React Router)
- External API integration (YouTube Data API)
- Separation of concerns: UI, API, data persistence, external auth

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend (React App)"
        browser["User Browser"]:::frontend
        main["Main Entry (main.jsx)"]:::frontend
        app["App Component (App.jsx)"]:::frontend
        oauthcb["OAuthCallback Component"]:::frontend
    end

    subgraph "Backend (Express REST API)"
        entry["Server Entry (server.js)"]:::backend
        authR["Authentication Routes"]:::backend
        authC["Authentication Controller"]:::backend
        videoR["Video Routes"]:::backend
        videoC["Video Controller"]:::backend
        authM["JWT Auth Middleware"]:::backend
        nlp["NLP Service"]:::backend
        dbCfg["DB Config (db.js)"]:::backend
        keyCfg["Keys Config (keys.js)"]:::backend
    end

    mongo["MongoDB"]:::database
    google["Google OAuth 2.0"]:::external
    youtube["YouTube Data API"]:::external

    browser --> main
    main --> app
    app --> oauthcb

    oauthcb -->|"GET /api/auth/google"| authR
    authR -->|-.-| google
    google -.->|"redirect with code"| oauthcb
    oauthcb -->|"POST /api/auth/callback"| authR
    authR --> authC
    authC --> keyCfg
    authC --> dbCfg
    authC -->|"calls Token API"| google
    authC --> browser

    browser -->|"GET /api/videos?filter=..."| videoR
    videoR --> authM
    authM --> videoC
    videoC --> nlp
    videoC -->|"fetch if needed"| youtube
    videoC --> mongo
    videoC --> browser

    entry --> authR
    entry --> videoR
    entry --> dbCfg
    entry --> keyCfg

    click main "https://github.com/divesh1207/videosfilter/blob/master/client/src/main.jsx"
    click app "https://github.com/divesh1207/videosfilter/blob/master/client/src/App.jsx"
    click oauthcb "https://github.com/divesh1207/videosfilter/blob/master/client/src/components/OAuthCallback.jsx"
    click entry "https://github.com/divesh1207/videosfilter/blob/master/server/server.js"
    click authR "https://github.com/divesh1207/videosfilter/blob/master/server/routes/authRoutes.js"
    click videoR "https://github.com/divesh1207/videosfilter/blob/master/server/routes/videoRoutes.js"
    click authC "https://github.com/divesh1207/videosfilter/blob/master/server/controllers/authController.js"
    click videoC "https://github.com/divesh1207/videosfilter/blob/master/server/controllers/videoController.js"
    click authM "https://github.com/divesh1207/videosfilter/blob/master/server/middlewares/authMiddleware.js"
    click nlp "https://github.com/divesh1207/videosfilter/blob/master/server/services/nlpService.js"
    click dbCfg "https://github.com/divesh1207/videosfilter/blob/master/server/configure/db.js"
    click keyCfg "https://github.com/divesh1207/videosfilter/blob/master/server/configure/keys.js"

    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef database fill:#E0F7FA,stroke:#0097A7,color:#006064;
    classDef external fill:#F0F0F0,stroke:#6A737D,color:#6A737D;
```
