A RESTful backend API for a video-sharing platform inspired by YouTube. The project provides APIs for user authentication, video management, comments, likes, playlists, subscriptions, tweets, and media uploads.
- Node.js
- Express.js
- MongoDB
- Mongoose
- JSON Web Tokens (JWT)
- bcrypt
- Multer
- Cloudinary
- mongoose-aggregate-paginate-v2
- User registration and login
- JWT-based authentication using access and refresh tokens
- Password hashing with bcrypt
- Cookie-based authentication
- Protected routes
- Authorization and ownership checks
- User logout
- Publish videos with thumbnails
- Retrieve all videos
- Retrieve individual videos
- Update video details
- Delete videos
- Toggle video publish status
- Pagination and sorting
- Keyword-based video search
- Add comments to videos
- Retrieve comments for a video
- Update comments
- Delete comments
- Paginated comment retrieval
- Like or unlike videos
- Like or unlike tweets
- Like or unlike comments
- Retrieve videos liked by a user
- Create playlists
- Update playlists
- Delete playlists
- Retrieve playlists by ID
- Add videos to playlists
- Remove videos from playlists
- Retrieve a user's playlists
- Subscribe and unsubscribe from channels
- Retrieve channels a user is subscribed to
- Retrieve subscribers of a channel
- Create tweets
- Retrieve a user's tweets
- Update tweets
- Delete tweets
- Health-check endpoint for verifying API availability
The application uses MongoDB with Mongoose for data modeling and relationships between users, videos, comments, likes, playlists, subscriptions, and tweets.
MongoDB aggregation pipelines are used for queries that require data from multiple collections.
The application uses aggregation stages such as:
$match$lookup$addFields$project$sort
Aggregation-based pagination is also used for endpoints that return collections of related data.
Multer is used to handle multipart form-data before media files are uploaded to Cloudinary.
The upload flow supports:
- Video uploads
- User avatars
- Cover images
- Video thumbnails
- Multiple file fields
- Temporary local file cleanup
The backend follows a modular structure separating routes, controllers, models, middleware, database configuration, and utility functions.
src/
├── controllers/
├── db/
├── middlewares/
├── models/
├── routes/
├── utils/
├── app.js
└── index.js
A complete Postman collection containing the API requests is included in the docs directory.
POST /user/register
Register a new user.
POST /user/login
Authenticate a user.
POST /user/logout
Log out the current user.
POST /videos
Publish a video.
GET /videos
Retrieve videos.
GET /videos/:videoId
Retrieve a video by ID.
PATCH /videos/:videoId
Update video details.
DELETE /videos/:videoId
Delete a video.
PATCH /videos/toggle/publish/:videoId
Toggle video publish status.
GET /comments/:videoId
Retrieve comments for a video.
POST /comments/:videoId
Add a comment.
PATCH /comments/c/:commentId
Update a comment.
DELETE /comments/c/:commentId
Delete a comment.
POST /likes/toggle/v/:videoId
Like or unlike a video.
POST /likes/toggle/t/:tweetId
Like or unlike a tweet.
POST /likes/toggle/c/:commentId
Like or unlike a comment.
GET /likes/liked-videos
Retrieve liked videos.
POST /playlists
Create a playlist.
PATCH /playlists/:playlistId
Update a playlist.
GET /playlists/:playlistId
Retrieve a playlist.
DELETE /playlists/:playlistId
Delete a playlist.
PATCH /playlists/:playlistId/:videoId
Add a video to a playlist.
DELETE /playlists/:playlistId/:videoId
Remove a video from a playlist.
GET /playlists/user/:userId
Retrieve a user's playlists.
GET /subscriptions/u/:subscriberId
Retrieve channels subscribed to by a user.
GET /subscriptions/c/:userId
Retrieve subscribers of a channel.
PATCH /subscriptions/c/:userId
Toggle a channel subscription.
POST /tweets
Create a tweet.
GET /tweets/:userId
Retrieve a user's tweets.
PATCH /tweets/:tweetId
Update a tweet.
DELETE /tweets/:tweetId
Delete a tweet.
GET /healthcheck
Check API availability.
Make sure you have:
- Node.js
- npm
- MongoDB
- A Cloudinary account
Clone the repository:
git clone https://github.com/your-username/videotube-backend.git
cd videotube-backendInstall dependencies:
npm installCreate a .env file in the project root.
PORT=8000
MONGODB_URI=your_mongodb_connection_string
CORS_ORIGIN=your_frontend_origin
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_secretStart the development server:
npm run devFor production:
npm startA Postman collection containing the API requests is included in the repository.
docs/
└── videotube.postman_collection.json
The collection is organized into the following sections:
- Users
- Videos
- Comments
- Likes
- Playlists
- Subscriptions
- Tweets
- Health Check
Import the collection into Postman and configure the required environment variables before testing the API.
Implemented JWT-based authentication with access and refresh tokens, password hashing using bcrypt, protected routes, and authorization checks for user-owned resources.
Used MongoDB aggregation pipelines for queries involving multiple collections and related data.
Aggregation stages such as $match, $lookup, $addFields, $project, and $sort are used to retrieve and shape API responses.
Implemented pagination, sorting, and keyword-based querying for API endpoints that return collections of data.
Built a media upload pipeline using Multer and Cloudinary for handling user images, video thumbnails, and video files.
Separated application logic into controllers, routes, models, middleware, database configuration, and utility modules to keep the backend organized and maintainable.
- Automated API testing
- Rate limiting
- Redis caching
- Improved search
- Performance monitoring
- Docker containerization
- CI/CD pipeline
- Frontend client
- OpenAPI/Swagger API documentation
A RESTful backend API for a video-sharing platform inspired by YouTube. The project provides APIs for user authentication, video management, comments, likes, playlists, subscriptions, tweets, and media uploads.
- Node.js
- Express.js
- MongoDB
- Mongoose
- JSON Web Tokens (JWT)
- bcrypt
- Multer
- Cloudinary
- mongoose-aggregate-paginate-v2
- User registration and login
- JWT-based authentication using access and refresh tokens
- Password hashing with bcrypt
- Cookie-based authentication
- Protected routes
- Authorization and ownership checks
- User logout
- Publish videos with thumbnails
- Retrieve all videos
- Retrieve individual videos
- Update video details
- Delete videos
- Toggle video publish status
- Pagination and sorting
- Keyword-based video search
- Add comments to videos
- Retrieve comments for a video
- Update comments
- Delete comments
- Paginated comment retrieval
- Like or unlike videos
- Like or unlike tweets
- Like or unlike comments
- Retrieve videos liked by a user
- Create playlists
- Update playlists
- Delete playlists
- Retrieve playlists by ID
- Add videos to playlists
- Remove videos from playlists
- Retrieve a user's playlists
- Subscribe and unsubscribe from channels
- Retrieve channels a user is subscribed to
- Retrieve subscribers of a channel
- Create tweets
- Retrieve a user's tweets
- Update tweets
- Delete tweets
- Health-check endpoint for verifying API availability
The application uses MongoDB with Mongoose for data modeling and relationships between users, videos, comments, likes, playlists, subscriptions, and tweets.
MongoDB aggregation pipelines are used for queries that require data from multiple collections.
The application uses aggregation stages such as:
$match$lookup$addFields$project$sort
Aggregation-based pagination is also used for endpoints that return collections of related data.
Multer is used to handle multipart form-data before media files are uploaded to Cloudinary.
The upload flow supports:
- Video uploads
- User avatars
- Cover images
- Video thumbnails
- Multiple file fields
- Temporary local file cleanup
The backend follows a modular structure separating routes, controllers, models, middleware, database configuration, and utility functions.
src/
├── controllers/
├── db/
├── middlewares/
├── models/
├── routes/
├── utils/
├── app.js
└── index.js
A complete Postman collection containing the API requests is included in the docs directory.
POST /user/register
Register a new user.
POST /user/login
Authenticate a user.
POST /user/logout
Log out the current user.
POST /videos
Publish a video.
GET /videos
Retrieve videos.
GET /videos/:videoId
Retrieve a video by ID.
PATCH /videos/:videoId
Update video details.
DELETE /videos/:videoId
Delete a video.
PATCH /videos/toggle/publish/:videoId
Toggle video publish status.
GET /comments/:videoId
Retrieve comments for a video.
POST /comments/:videoId
Add a comment.
PATCH /comments/c/:commentId
Update a comment.
DELETE /comments/c/:commentId
Delete a comment.
POST /likes/toggle/v/:videoId
Like or unlike a video.
POST /likes/toggle/t/:tweetId
Like or unlike a tweet.
POST /likes/toggle/c/:commentId
Like or unlike a comment.
GET /likes/liked-videos
Retrieve liked videos.
POST /playlists
Create a playlist.
PATCH /playlists/:playlistId
Update a playlist.
GET /playlists/:playlistId
Retrieve a playlist.
DELETE /playlists/:playlistId
Delete a playlist.
PATCH /playlists/:playlistId/:videoId
Add a video to a playlist.
DELETE /playlists/:playlistId/:videoId
Remove a video from a playlist.
GET /playlists/user/:userId
Retrieve a user's playlists.
GET /subscriptions/u/:subscriberId
Retrieve channels subscribed to by a user.
GET /subscriptions/c/:userId
Retrieve subscribers of a channel.
PATCH /subscriptions/c/:userId
Toggle a channel subscription.
POST /tweets
Create a tweet.
GET /tweets/:userId
Retrieve a user's tweets.
PATCH /tweets/:tweetId
Update a tweet.
DELETE /tweets/:tweetId
Delete a tweet.
GET /healthcheck
Check API availability.
Make sure you have:
- Node.js
- npm
- MongoDB
- A Cloudinary account
Clone the repository:
git clone https://github.com/your-username/videotube-backend.git
cd videotube-backendInstall dependencies:
npm installCreate a .env file in the project root.
PORT=8000
MONGODB_URI=your_mongodb_connection_string
CORS_ORIGIN=your_frontend_origin
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_secretFor other developers, you can provide a .env.example file containing only placeholder values.
Start the development server:
npm run devFor production:
npm startA Postman collection containing the API requests is included in the repository.
docs/
└── videotube.postman_collection.json
The collection is organized into the following sections:
- Users
- Videos
- Comments
- Likes
- Playlists
- Subscriptions
- Tweets
- Health Check
Import the collection into Postman and configure the required environment variables before testing the API.
Implemented JWT-based authentication with access and refresh tokens, password hashing using bcrypt, protected routes, and authorization checks for user-owned resources.
Used MongoDB aggregation pipelines for queries involving multiple collections and related data.
Aggregation stages such as $match, $lookup, $addFields, $project, and $sort are used to retrieve and shape API responses.
Implemented pagination, sorting, and keyword-based querying for API endpoints that return collections of data.
Built a media upload pipeline using Multer and Cloudinary for handling user images, video thumbnails, and video files.
Separated application logic into controllers, routes, models, middleware, database configuration, and utility modules to keep the backend organized and maintainable.
- Automated API testing
- Rate limiting
- Redis caching
- Improved search
- Performance monitoring
- Docker containerization
- CI/CD pipeline
- Frontend client
- OpenAPI/Swagger API documentation
This project is intended for learning and portfolio purposes.
c304de9 (Add frontend service layer)