A feature-rich, full-stack video sharing platform built with the MERN stack, featuring user authentication, video management, playlists, comments, likes, subscriptions, and more.
- Features
- Tech Stack
- Project Architecture
- Getting Started
- Environment Variables
- API Documentation
- State Management
- Folder Structure
- Screenshots
- Contributing
- License
- π User registration and authentication (JWT)
- π€ User profile management (avatar, cover image)
- π Password change functionality
- π User dashboard with statistics
- πΉ 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
- π¬ Comments on videos
- π Like/Unlike videos and comments
- π Subscribe/Unsubscribe to channels
- π View subscriber count
- π Channel pages with tabs (Videos, Playlists, Tweets, Subscribed)
- π 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)
- π¦ Tweet functionality (text posts)
- π Dark/Light theme support
- π± Responsive design
- β‘ Optimized performance (95% fewer API calls)
- π Real-time updates
- π¨ Modern UI with Tailwind CSS
- 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
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- Bcrypt - Password hashing
- Cloudinary - Media storage
- Multer - File upload
- Git - Version control
- ESLint - Code linting
- Prettier - Code formatting
- Nodemon - Development server
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
- Node.js (v16 or higher)
- MongoDB (local or Atlas)
- Cloudinary account (for media storage)
- npm or yarn
-
Clone the repository
git clone https://github.com/yourusername/youtube-project.git cd youtube-project -
Install Backend Dependencies
cd Backend npm install -
Install Frontend Dependencies
cd ../Frontend npm install -
Set up Environment Variables
Create a
.envfile in theBackenddirectory: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
-
Start the Development Servers
Backend:
cd Backend npm run devFrontend:
cd Frontend npm run dev -
Access the Application
- Frontend: http://localhost:5173
- Backend: https://youtube-backend-psi.vercel.app
| 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 |
https://youtube-backend-psi.vercel.app/api/v1
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
This project uses a hybrid state management approach combining Redux Toolkit and Context API:
- User Authentication - Login, logout, user data
- Data Caching - Reduce API calls by 83%
- Complex State Logic - With middleware support
- AuthContext - Convenient wrapper around Redux user state
- ThemeContext - Dark/light mode, sidebar state
- VideoContext - Video player settings, watch history
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();- β 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
- 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
# Run frontend tests
cd Frontend
npm test
# Run backend tests
cd Backend
npm testnpm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLintnpm run dev # Start development server with nodemon
npm start # Start production server
npm run lint # Run ESLintContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Your Name - Initial work - YourGitHub
- React team for the amazing library
- Redux team for Redux Toolkit
- MongoDB team for the database
- Cloudinary for media storage
- All contributors and supporters
- Email: [email protected]
- GitHub: @yourusername
- LinkedIn: Your Name
Made with β€οΈ by [Your Name]
β Star this repo if you find it helpful!