A robust, production-ready backend for a video hosting platform similar to YouTube. Built with modern web technologies and following industry best practices for authentication, file handling, and API design.
- User Authentication: JWT-based authentication with access/refresh tokens
- Video Management: Upload, stream, update, and delete videos with Cloudinary integration
- Social Features: Comments, likes, subscriptions, and playlists
- Tweet System: Twitter-like functionality for user engagement
- Dashboard Analytics: Channel statistics and video management
- File Upload: Secure file handling with Multer middleware
- Security: Password hashing with bcrypt, CORS protection
- Database: MongoDB with Mongoose ODM and aggregation pipelines
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose
- Authentication: JWT (JSON Web Tokens)
- File Storage: Cloudinary
- Security: bcrypt for password hashing
- File Upload: Multer
- Development: Nodemon for hot reloading
src/
├── controllers/ # Route handlers and business logic
├── models/ # MongoDB schemas and models
├── routes/ # API route definitions
├── middleware/ # Authentication and file upload middleware
├── utils/ # Helper functions and utilities
└── db/ # Database connection configuration
| Endpoint | Method | Description |
|---|---|---|
/register |
POST |
Registers a new user. |
/login |
POST |
Logs in a user. |
/logout |
POST |
Logs out a user. |
/change-password |
POST |
Changes the password for the user. |
/refresh-token |
POST |
Generates a new refresh token for the user. |
/current-user |
GET |
Gets the current user. |
/watch-history |
GET |
Gets the watch history of the current user. |
/channel/:username |
GET |
Returns the user's channel profile. |
/avatar |
PATCH |
Updates the avatar of the user. |
/cover-image |
PATCH |
Updates the cover image of the user. |
/update-account-details |
PATCH |
Updates the account details of the user. |
| Endpoint | Method | Description |
|---|---|---|
/publish-video |
POST |
Uploads a new video. |
/update-video/:videoId |
POST |
Updates video details (title, description, and thumbnail) for the specified video ID. |
/toggle-publish-status/:videoId |
POST |
Toggles the publish status of a video. |
/get-all-videos |
GET |
Fetches all videos of the user. |
/:videoId |
GET |
Fetches the video by video ID. |
/delete-video/:videoId |
DELETE |
Deletes the video specified by the video ID. |
| Endpoint | Method | Description |
|---|---|---|
/ |
POST |
Creates a new tweet. |
/user/:userId |
GET |
Retrieves tweets for a specific user. |
/:tweetId |
GET |
Retrieves the tweet by tweet ID. |
/:tweetId |
DELETE |
Deletes the tweet specified by the tweet ID. |
| Endpoint | Method | Description |
|---|---|---|
/:playlistId |
GET |
Fetches the playlist by playlist ID. |
/:playlistId |
PATCH |
Updates the playlist specified by the playlist ID. |
/:playlistId |
DELETE |
Deletes the playlist specified by the playlist ID. |
/add/:videoId/:playlistId |
PATCH |
Adds a video to the playlist specified by video ID and playlist ID. |
/remove/:videoId/:playlistId |
PATCH |
Removes a video from the playlist specified by video ID and playlist ID. |
/user/:userId |
GET |
Retrieves playlists for a specific user. |
| Endpoint | Method | Description |
|---|---|---|
/:videoId |
GET |
Retrieves comments for a specific video. |
/:videoId |
POST |
Comments on a specific video. |
/c/:commentId |
PATCH |
Updates a comment specified by the comment ID. |
/c/:commentId |
DELETE |
Deletes a comment specified by the comment ID. |
| Endpoint | Method | Description |
|---|---|---|
/toggle/v/:videoId |
POST |
Toggles the like status for a specific video. |
/toggle/c/:commentId |
POST |
Toggles the like status for a specific comment. |
/toggle/t/:tweetId |
POST |
Toggles the like status for a specific tweet. |
/videos |
GET |
Retrieves the liked videos of the logged-in user. |
| Endpoint | Method | Description |
|---|---|---|
/c/:channelId |
GET |
Retrieves subscribers for a specific channel. |
/c/:channelId |
POST |
Toggles subscription status for a specific channel. |
/u/:subscriberId |
GET |
Retrieves subscribed channels for a specific user. |
| Endpoint | Method | Description |
|---|---|---|
/stats |
GET |
Retrieves channel statistics (logged in). |
/videos |
GET |
Retrieves channel videos (logged in). |
- Node.js (v16 or higher)
- MongoDB (local or Atlas)
- Cloudinary account for file storage
-
Clone the repository
git clone https://github.com/AdityaKrSingh26/Flixify-Backend.git cd Flixify-Backend -
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in the root directory:PORT=8000 MONGODB_URI=your_mongodb_connection_string CORS_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_secret
-
Start the development server
npm run server:dev
-
For production
npm start
The server will start on http://localhost:8000
We welcome contributions! Please follow these guidelines:
- Fork & Clone: Fork the repo and clone your fork
- Branch: Create a feature branch (
git checkout -b feature/amazing-feature) - Install: Run
npm installand set up your.envfile - Code: Make your changes following our standards
- Use ES6+ syntax and modules
- Follow existing naming conventions (camelCase for variables/functions)
- Add JSDoc comments for functions
- Handle errors properly with try-catch blocks
- Use async/await over promises
- Test: Ensure your changes work locally
- Commit: Use descriptive commit messages
- Push: Push to your fork (
git push origin feature/amazing-feature) - PR: Open a Pull Request with a clear description and Raise your PR on DEV branch.
- Keep PRs focused and small
- Update documentation if needed
- Follow the existing code style
- Test your changes thoroughly