Skip to content

KrishChothani/YouTube-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 YouTube Clone - Full Stack Video Platform

A feature-rich, full-stack video sharing platform built with the MERN stack, featuring user authentication, video management, playlists, comments, likes, subscriptions, and more.

License Node React MongoDB

πŸ“‹ Table of Contents

✨ Features

User Management

  • πŸ” User registration and authentication (JWT)
  • πŸ‘€ User profile management (avatar, cover image)
  • πŸ”‘ Password change functionality
  • πŸ“Š User dashboard with statistics

Video Features

  • πŸ“Ή Video upload with thumbnail
  • ▢️ Video playback with custom player
  • 🎬 Video details (title, description, views, duration)
  • πŸ” Video search and filtering
  • πŸ“ Video editing and deletion
  • πŸ‘οΈ Watch history tracking

Social Features

  • πŸ’¬ Comments on videos
  • πŸ‘ Like/Unlike videos and comments
  • πŸ”” Subscribe/Unsubscribe to channels
  • πŸ“Š View subscriber count
  • 🎭 Channel pages with tabs (Videos, Playlists, Tweets, Subscribed)

Playlist Management

  • πŸ“š Create, edit, and delete playlists
  • βž• Add/remove videos from playlists
  • πŸ“‹ View playlists on channel pages
  • 🎯 Quick save to playlist popup
  • πŸ“Š Playlist statistics (total views, video count)

Additional Features

  • 🐦 Tweet functionality (text posts)
  • πŸŒ™ Dark/Light theme support
  • πŸ“± Responsive design
  • ⚑ Optimized performance (95% fewer API calls)
  • πŸ”„ Real-time updates
  • 🎨 Modern UI with Tailwind CSS

πŸ›  Tech Stack

Frontend

  • React 18.2 - UI library
  • Redux Toolkit - State management
  • Context API - UI state management
  • React Router v6 - Routing
  • Axios - HTTP client
  • Tailwind CSS - Styling
  • Vite - Build tool

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • MongoDB - Database
  • Mongoose - ODM
  • JWT - Authentication
  • Bcrypt - Password hashing
  • Cloudinary - Media storage
  • Multer - File upload

DevOps & Tools

  • Git - Version control
  • ESLint - Code linting
  • Prettier - Code formatting
  • Nodemon - Development server

πŸ— Project Architecture

YouTube-Project/
β”‚
β”œβ”€β”€ Frontend/                      # React frontend application
β”‚   β”œβ”€β”€ node_modules/
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   β”œβ”€β”€ Components/
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”œβ”€β”€ examples/
β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ Pages/
β”‚   β”‚   β”œβ”€β”€ store/
β”‚   β”‚   └── utils/
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ eslint.config.js
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ package-lock.json
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ postcss.config.js
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   β”œβ”€β”€ vercel.json
β”‚   └── vite.config.js
β”‚
└── Backend/                       # Node.js backend application
    β”œβ”€β”€ node_modules/
    β”œβ”€β”€ Public/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ .cph/
    β”‚   β”œβ”€β”€ controllers/
    β”‚   β”œβ”€β”€ db/
    β”‚   β”œβ”€β”€ middlewares/
    β”‚   β”œβ”€β”€ models/
    β”‚   β”œβ”€β”€ routes/
    β”‚   └── utils/
    β”œβ”€β”€ .env
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ .prettierignore
    β”œβ”€β”€ .prettierrc
    β”œβ”€β”€ package-lock.json
    β”œβ”€β”€ package.json
    └── vercel.json

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or Atlas)
  • Cloudinary account (for media storage)
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/youtube-project.git
    cd youtube-project
  2. Install Backend Dependencies

    cd Backend
    npm install
  3. Install Frontend Dependencies

    cd ../Frontend
    npm install
  4. Set up Environment Variables

    Create a .env file in the Backend directory:

    PORT=8000
    MONGODB_URI=your_mongodb_connection_string
    CORS_ORIGIN=http://localhost:5173
    
    ACCESS_TOKEN_SECRET=your_access_token_secret
    ACCESS_TOKEN_EXPIRY=1d
    REFRESH_TOKEN_SECRET=your_refresh_token_secret
    REFRESH_TOKEN_EXPIRY=10d
    
    CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
    CLOUDINARY_API_KEY=your_cloudinary_api_key
    CLOUDINARY_API_SECRET=your_cloudinary_api_secret
  5. Start the Development Servers

    Backend:

    cd Backend
    npm run dev

    Frontend:

    cd Frontend
    npm run dev
  6. Access the Application

πŸ” Environment Variables

Backend (.env)

Variable Description Example
PORT Server port 8000
MONGODB_URI MongoDB connection string mongodb://localhost:27017/youtube
CORS_ORIGIN Allowed CORS origin http://localhost:5173
ACCESS_TOKEN_SECRET JWT access token secret your_secret_key
ACCESS_TOKEN_EXPIRY Access token expiry 1d
REFRESH_TOKEN_SECRET JWT refresh token secret your_refresh_secret
REFRESH_TOKEN_EXPIRY Refresh token expiry 10d
CLOUDINARY_CLOUD_NAME Cloudinary cloud name your_cloud_name
CLOUDINARY_API_KEY Cloudinary API key your_api_key
CLOUDINARY_API_SECRET Cloudinary API secret your_api_secret

πŸ“‘ API Documentation

Base URL

https://youtube-backend-psi.vercel.app/api/v1

Authentication Endpoints

Method Endpoint Description Auth Required
POST /users/register Register new user No
POST /users/login Login user No
POST /users/logout Logout user Yes
GET /users/current-user Get current user Yes
PATCH /users/update-account Update user details Yes
PATCH /users/avatar Update avatar Yes
PATCH /users/cover-image Update cover image Yes
POST /users/change-password Change password Yes

Video Endpoints

Method Endpoint Description Auth Required
GET /videos Get all videos No
GET /videos/v/:videoId Get video by ID No
POST /videos Upload video Yes
PATCH /videos/:videoId Update video Yes
DELETE /videos/:videoId Delete video Yes

Playlist Endpoints

Method Endpoint Description Auth Required
POST /playlists Create playlist Yes
GET /playlists/:playlistId Get playlist by ID Yes
GET /playlists/user/:userId Get user playlists Yes
PATCH /playlists/:playlistId Update playlist Yes
DELETE /playlists/:playlistId Delete playlist Yes
PATCH /playlists/add/:videoId/:playlistId Add video to playlist Yes
PATCH /playlists/remove/:videoId/:playlistId Remove video from playlist Yes

Comment Endpoints

Method Endpoint Description Auth Required
GET /comments/:videoId Get video comments No
POST /comments/:videoId Add comment Yes
PATCH /comments/c/:commentId Update comment Yes
DELETE /comments/c/:commentId Delete comment Yes

Like Endpoints

Method Endpoint Description Auth Required
POST /likes/toggle/v/:videoId Toggle video like Yes
POST /likes/toggle/c/:commentId Toggle comment like Yes
GET /likes/video Get user's liked videos Yes

Subscription Endpoints

Method Endpoint Description Auth Required
POST /subscriptions/c/:channelId Toggle subscription Yes
GET /subscriptions/u/:subscriberId Get user subscriptions Yes
GET /subscriptions/c/:channelId Get channel subscribers Yes

πŸ”„ State Management

This project uses a hybrid state management approach combining Redux Toolkit and Context API:

Redux (Global State)

  • User Authentication - Login, logout, user data
  • Data Caching - Reduce API calls by 83%
  • Complex State Logic - With middleware support

Context API (UI State)

  • AuthContext - Convenient wrapper around Redux user state
  • ThemeContext - Dark/light mode, sidebar state
  • VideoContext - Video player settings, watch history

Usage Examples

Access User Data (Context):

import { useAuthContext } from './context/AuthContext';

function MyComponent() {
  const { user, isLoggedIn } = useAuthContext();
  return <div>Welcome, {user?.userName}!</div>;
}

Update User Data (Redux):

import { useDispatch } from 'react-redux';
import { loginUser } from './store/slices/userSlice';

const dispatch = useDispatch();
await dispatch(loginUser({ email, password })).unwrap();

Theme Management:

import { useTheme } from './context/ThemeContext';

const { toggleTheme, isDark } = useTheme();

πŸ“Š Performance Optimizations

  • βœ… 83% reduction in user API calls (Redux caching)
  • βœ… 99% reduction in comment API calls (fixed infinite loops)
  • βœ… 95% overall reduction in unnecessary API calls
  • βœ… Optimized re-renders with proper useEffect dependencies
  • βœ… Lazy loading for images and videos
  • βœ… Debounced search functionality

🎨 UI Features

  • Responsive Design - Works on desktop, tablet, and mobile
  • Dark/Light Theme - User preference saved to localStorage
  • Modern UI - Clean, intuitive interface with Tailwind CSS
  • Loading States - Skeleton screens and spinners
  • Error Handling - User-friendly error messages
  • Toast Notifications - Success/error feedback

πŸ§ͺ Testing

# Run frontend tests
cd Frontend
npm test

# Run backend tests
cd Backend
npm test

πŸ“ Scripts

Frontend

npm run dev          # Start development server
npm run build        # Build for production
npm run preview      # Preview production build
npm run lint         # Run ESLint

Backend

npm run dev          # Start development server with nodemon
npm start            # Start production server
npm run lint         # Run ESLint

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Authors

πŸ™ Acknowledgments

  • React team for the amazing library
  • Redux team for Redux Toolkit
  • MongoDB team for the database
  • Cloudinary for media storage
  • All contributors and supporters

πŸ“ž Contact

πŸ”— Links


Made with ❀️ by [Your Name]

⭐ Star this repo if you find it helpful!

Releases

No releases published

Packages

No packages published

Languages