Skip to content

Latest commit

Β 

History

69 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 VividStream

A full-stack, production-grade video streaming and creator platform built with the MERN stack (MongoDB, Express, React 19, Node.js) with Cloudinary media storage, JWT-based secure authentication, and MongoDB aggregation pipelines.


πŸ“‘ Table of Contents


🌟 Overview

VividStream is a modern video sharing platform inspired by YouTube, designed with a backend-first architecture. It supports media uploads (video & images) via Cloudinary, real-time community engagement (likes, comments, tweets, subscriptions), playlist management, watch history tracking, and an analytics dashboard for creators.


πŸ›  Tech Stack

Frontend

Backend

  • Runtime & Framework: Node.js (ES Modules), Express 5
  • Database & ODM: MongoDB, Mongoose 8
  • Pagination & Queries: mongoose-aggregate-paginate-v2 & custom MongoDB aggregation pipelines
  • Authentication: JSON Web Tokens (JWT Access & Refresh tokens), bcryptjs, cookie-parser
  • File Handling & Storage: Multer (local temporary buffer) & Cloudinary (cloud media storage)
  • CORS: cors configured with credentials for cookie exchange

πŸš€ Key Features

πŸ” Authentication & User Management

  • Secure user registration with avatar and cover image uploads.
  • Access & Refresh token rotation with HttpOnly secure cookies and Authorization header fallback.
  • Profile management (update account details, update avatar/cover image, change password).
  • Channel profile page displaying subscriber counts, subscribed channels, and channel videos.

πŸŽ₯ Video Management & Playback

  • Video upload with custom thumbnails, title, and description.
  • Video playback player with real-time view count tracking.
  • Video updating (title, description, thumbnail) and deletion.
  • Toggle publish / unpublish status.
  • Video list with pagination, search queries, and sorting (by views, creation date).

πŸ’¬ Social & Community Engagement

  • Likes: Like and unlike videos, comments, and community tweets.
  • Comments: Full CRUD on video comments (add, edit, delete, list with author details).
  • Subscriptions: One-click channel subscribe/unsubscribe toggle and subscriber counts.
  • Community Tweets: Creator microblogging / tweet feed with like counters and timeline.

πŸ“ Playlists & Collections

  • Create custom playlists with title and description.
  • Add and remove videos from playlists.
  • Fetch user playlists and dedicated playlist detail views.

πŸ•’ Watch History & Liked Videos

  • Automated watch history tracking (most recent first).
  • Dedicated Liked Videos feed for authenticated users.

πŸ“Š Creator Dashboard

  • Channel stats analytics (total video views, subscriber count, total likes).
  • Video management table with status toggles and direct actions.

πŸ— Project Architecture

graph TD
    Client["React 19 Frontend (Vite)"] <-->|"REST API / Cookies (Credentials)"| Express["Express Backend (/api/v1)"]
    Express <-->|"Mongoose & Aggregations"| Mongo[("MongoDB Database")]
    Express <-->|"Multer Temp File"| LocalFS["Local Disk (public/temp)"]
    LocalFS -->|"Media Upload"| Cloudinary[("Cloudinary Media CDN")]
Loading

πŸ“‚ Folder Structure

vivid-stream/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ public/temp/         # Multer temporary buffer directory
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/     # Request handlers (user, video, comment, etc.)
β”‚   β”‚   β”œβ”€β”€ db/              # MongoDB connection setup
β”‚   β”‚   β”œβ”€β”€ middlewares/     # Auth (verifyJWT) & upload (multer) middlewares
β”‚   β”‚   β”œβ”€β”€ models/          # Mongoose schema definitions
β”‚   β”‚   β”œβ”€β”€ routes/          # Express route definitions
β”‚   β”‚   β”œβ”€β”€ utils/           # ApiError, ApiResponse, asyncHandler, cloudinary
β”‚   β”‚   β”œβ”€β”€ app.js           # Express app configuration & middleware pipeline
β”‚   β”‚   β”œβ”€β”€ constants.js     # DB name & application constants
β”‚   β”‚   └── index.js         # Backend server entry point
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.sample
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/              # Static frontend assets
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/             # Axios API client functions
β”‚   β”‚   β”œβ”€β”€ components/      # Reusable UI components & layouts
β”‚   β”‚   β”‚   β”œβ”€β”€ layout/      # AppLayout, Navbar, Sidebar
β”‚   β”‚   β”‚   └── video/       # VideoCard, VideoPlayer, etc.
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ pages/           # Application views (Home, Watch, Channel, etc.)
β”‚   β”‚   β”œβ”€β”€ routes/          # ProtectedRoute and navigation guards
β”‚   β”‚   β”œβ”€β”€ stores/          # Zustand state stores (auth.store.js)
β”‚   β”‚   β”œβ”€β”€ styles/          # Modular SCSS stylesheets
β”‚   β”‚   β”œβ”€β”€ utils/           # Frontend utility functions
β”‚   β”‚   β”œβ”€β”€ App.jsx          # Route declarations & auth initialization
β”‚   β”‚   └── main.jsx         # React DOM mount point
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
β”œβ”€β”€ PROJECT_CONTEXT.md
└── Readme.md

⚑ Getting Started

Prerequisites


Backend Setup

  1. Navigate to the backend directory:

    cd backend
  2. Install dependencies:

    npm install
  3. Configure Environment Variables: Create a .env file in backend/:

    PORT=8000
    CORS_ORIGIN=http://localhost:5173
    MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net
    ACCESS_TOKEN_SECRET=your_access_token_secret_key
    ACCESS_TOKEN_EXPIRES_IN=1d
    REFRESH_TOKEN_SECRET=your_refresh_token_secret_key
    REFRESH_TOKEN_EXPIRES_IN=10d
    CLOUDINARY_CLOUD_NAME=your_cloud_name
    CLOUDINARY_API_KEY=your_api_key
    CLOUDINARY_API_SECRET=your_api_secret
  4. Start the backend development server:

    npm run dev

    Server will run on http://localhost:8000.


Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Configure Environment Variables (Optional): Create a .env file in frontend/ if needed:

    VITE_API_BASE_URL=http://localhost:8000/api/v1
  4. Start the frontend development server:

    npm run dev

    Vite will serve the app on http://localhost:5173.


πŸ”‘ Environment Variables

Backend (backend/.env)

Variable Description Example
PORT Port number for Express server 8000
CORS_ORIGIN Allowed client origin for CORS http://localhost:5173
MONGODB_URI MongoDB connection URI mongodb+srv://...
ACCESS_TOKEN_SECRET Secret key for signing JWT access tokens your_access_token_secret
ACCESS_TOKEN_EXPIRES_IN Expiry duration for access token 1d
REFRESH_TOKEN_SECRET Secret key for signing JWT refresh tokens your_refresh_token_secret
REFRESH_TOKEN_EXPIRES_IN Expiry duration for refresh token 10d
CLOUDINARY_CLOUD_NAME Cloudinary account cloud name your_cloud_name
CLOUDINARY_API_KEY Cloudinary API Key 1234567890
CLOUDINARY_API_SECRET Cloudinary API Secret your_api_secret

πŸ“‘ API Reference

Base URL: /api/v1

πŸ‘€ Users (/api/v1/users)

Method Endpoint Description Auth
POST /register Register new user (avatar & cover upload) ❌
POST /login Authenticate user & set JWT cookies ❌
POST /logout Invalidate refresh token & clear cookies βœ…
POST /refresh-token Regenerate access & refresh tokens ❌
POST /change-password Update current user's password βœ…
GET /current-user Fetch currently authenticated user βœ…
PATCH /update-account Update full name and email βœ…
PATCH /avatar Update user avatar image βœ…
PATCH /cover-image Update user channel cover image βœ…
GET /c/:username Fetch channel profile details & subscription status βœ…
GET /history Fetch authenticated user's watch history βœ…

πŸ“Ή Videos (/api/v1/videos)

Method Endpoint Description Auth
GET / Get published videos (search, paginate, sort) βœ…
POST / Upload video & thumbnail to Cloudinary βœ…
GET /:videoId Get video details, owner, like & subscriber stats βœ…
PATCH /:videoId Update video title, description, or thumbnail βœ…
DELETE /:videoId Delete video from database βœ…
PATCH /toggle/publish/:videoId Toggle publish / unpublish status βœ…

πŸ’¬ Comments (/api/v1/comments)

Method Endpoint Description Auth
GET /:videoId Get comments for a video (paginated) βœ…
POST /:videoId Add a comment to a video βœ…
PATCH /c/:commentId Update comment content βœ…
DELETE /c/:commentId Delete a comment βœ…

❀️ Likes (/api/v1/likes)

Method Endpoint Description Auth
POST /toggle/v/:videoId Toggle like status on a video βœ…
POST /toggle/c/:commentId Toggle like status on a comment βœ…
POST /toggle/t/:tweetId Toggle like status on a tweet βœ…
GET /videos Get list of videos liked by the current user βœ…

πŸ”” Subscriptions (/api/v1/subscriptions)

Method Endpoint Description Auth
POST /c/:channelId Toggle subscribe / unsubscribe to a channel βœ…
GET /c/:channelId Get list of subscribers for a channel βœ…
GET /u/:subscriberId Get channels subscribed to by a user βœ…

πŸ“ Playlists (/api/v1/playlist)

Method Endpoint Description Auth
POST / Create a new playlist βœ…
GET /:playlistId Get playlist details and video list βœ…
PATCH /:playlistId Update playlist name and description βœ…
DELETE /:playlistId Delete a playlist βœ…
PATCH /add/:videoId/:playlistId Add a video to a playlist βœ…
PATCH /remove/:videoId/:playlistId Remove a video from a playlist βœ…
GET /user/:userId Get all playlists created by a user βœ…

🐦 Tweets (/api/v1/tweets)

Method Endpoint Description Auth
POST / Post a community tweet βœ…
GET / Fetch all community tweets (feed) βœ…
GET /user/:userId Fetch tweets authored by a specific user βœ…
PATCH /:tweetId Update tweet content βœ…
DELETE /:tweetId Delete a tweet βœ…

πŸ“Š Dashboard & Healthcheck

Method Endpoint Description Auth
GET /api/v1/dashboard/stats Channel stats (views, subscribers, likes) βœ…
GET /api/v1/dashboard/videos Get all videos uploaded by the channel βœ…
GET /api/v1/healthcheck Service health status ❌

πŸ’‘ Design Decisions & Architecture

  1. Backend as Source of Truth: Counts (subscribers, likes, views) and relational statuses are calculated dynamically via optimized MongoDB aggregation pipelines rather than being hardcoded or guessed on the frontend.
  2. Robust Error Handling: Standardized ApiError class and ApiResponse envelope ensure consistent status codes, error messaging, and data payloads across all endpoints.
  3. Safe Media Lifecycle: Multipart uploads are buffered locally to public/temp by Multer before being streamed to Cloudinary, with automatic filesystem cleanup on success or error.
  4. Zustand State Persistence: Lightweight client-side session management that automatically revalidates authentication on startup through /api/v1/users/current-user.

πŸ“œ License

This project is licensed under the ISC License.

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages