This project is a complete backend solution replicating the core features of YouTube. It provides APIs for managing users, videos, comments, subscriptions, playlists, and more.
- Overview
- Features
- Tech Stack
- Installation
- Environment Variables
- API Endpoints
- Error Handling
- Security
- Testing
- Contributing
- License
This backend application is designed to handle various functionalities of YouTube, including user authentication, video uploads, comments, likes, and subscriptions. Built with modern technologies, it ensures scalability and performance for handling media content and social interactions.
- User authentication (registration, login, logout)
- Video uploads and management
- Commenting on videos
- Subscription management
- Playlist creation and management
- Like and dislike functionalities for videos, comments, and tweets
- Dashboard statistics
- Backend: Node.js, Express
- Database: MongoDB, Mongoose
- File Storage: AWS S3 for video and image storage
- Authentication: JWT for secure access
- Others: Multer for file uploads, Aggregation pipelines for analytics
- Node.js (v14 or higher)
- MongoDB (local or cloud)
- AWS account for S3 storage
-
Clone the repository:
git clone https://github.com/your-repo/youtube-backend-clone.git
-
Navigate to the project directory:
cd youtube-backend-clone
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and populate it as follows:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret AWS_ACCESS_KEY_ID=your_aws_access_key AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key AWS_BUCKET_NAME=your_s3_bucket_name
-
Start the development server:
npm run dev
Variable | Description |
---|---|
PORT |
Port number for the server |
MONGO_URI |
MongoDB connection string |
JWT_SECRET |
Secret key for JWT |
AWS_ACCESS_KEY_ID |
AWS access key for S3 storage |
AWS_SECRET_ACCESS_KEY |
AWS secret access key |
AWS_BUCKET_NAME |
Name of the S3 bucket for videos |
- POST /api/v1/users/register: Register a new user.
- POST /api/v1/users/login: Log in an existing user.
- POST /api/v1/users/logout: Log out the current user.
- POST /api/v1/users/refresh-token: Refresh access token.
- PATCH /api/v1/users/account: Update user account details.
- POST /api/v1/video/video-upload: Upload a video.
- GET /api/v1/video/all-videos: Retrieve all videos.
- GET /api/v1/video/:videoId: Get details of a specific video.
- PATCH /api/v1/video/update-details/:videoId: Update video details.
- GET /api/v1/video/delete-video/:videoId: Delete a video.
- POST /api/v1/video/comment/:videoId: Add a comment to a video.
- PATCH /api/v1/video/comment/:commentId/update: Update a specific comment.
- GET /api/v1/video/comment/:commentId: Get a specific comment.
- POST /api/v1/channel/subscribe/:channelId: Subscribe to a channel.
- POST /api/v1/channel/:subscriberId/subscribed-to: Get subscribed channels.
- POST /api/v1/playlist/create-playlist: Create a new playlist.
- GET /api/v1/playlist/:userId/playlists: Get user playlists.
- GET /api/v1/playlist/:playlistId: Get details of a specific playlist.
- GET /api/v1/playlist/:playlistId/add-video/:videoId: Add a video to a playlist.
- GET /api/v1/playlist/:playlistId/remove-video/:videoId: Remove a video from a playlist.
- POST /api/v1/video/:videoId/like: Like or dislike a video.
- POST /api/v1/comment/:commentId/like: Like or dislike a comment.
- POST /api/v1/dashboard/stats: Get channel statistics.
- POST /api/v1/dashboard/channel/all-videos: Get all videos uploaded by the channel.
Custom error handling middleware returns meaningful error messages with appropriate status codes for various scenarios (e.g., 400, 404, 500).
- JWT Authentication: Protects routes to ensure only authenticated users can access certain resources.
- Password Hashing: bcrypt is used for secure password storage.
- AWS S3: Securely stores video files.
Testing for API endpoints is implemented using Jest and Supertest to ensure expected functionality.
npm test
- Fork the project.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.
This project is licensed under the MIT License.