A production-grade backend engine for a hybrid video streaming and social media platform. Built with Node.js, Express, and MongoDB, leveraging advanced aggregation pipelines for handling complex data relationships.
A unified architecture where a single "Likes" collection handles interactions across the entire platform using targetId and targetType (Video, Comment, or Tweet). This approach reduces code duplication and simplifies database management.
- Dynamic Data Injection: Real-time calculation of
likesCount,subscriberCount, andisSubscribedstatus - Complex Joins: Multi-stage
$lookupand$addFieldsoperations for efficient data merging - Performance Optimization: Minimized memory overhead while delivering rich JSON responses
Cascade-style cleanup logic ensures that deleting a video automatically removes all associated comments and likes, maintaining database consistency.
- JWT-based authentication with Access and Refresh Token logic
- Strict ownership verification through middleware and controller-level checks
- Users can only modify their own content (Videos, Playlists, Tweets, Comments)
- Upload and streaming via Cloudinary integration
- Regex-based search with case-insensitive filtering
- Automatic watch history tracking
- Tweet engine for text-based updates with engagement support
- Nested comment system with ownership management and like tracking
- Self-referencing many-to-many relationships for user subscriptions
- Real-time profile analytics for subscriber counts
- Create, update, and delete curated collections
- Atomic updates using
$addToSetand$pullto prevent duplicates
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- ODM: Mongoose
- Media Storage: Cloudinary
- Security: Bcrypt, JWT
- Documentation: Postman
- Node.js v18+
- MongoDB Atlas account
- Cloudinary account
- Clone the repository
git clone https://github.com/somandhir/backend-project.git
cd backend-project- Install dependencies
npm install- Configure environment variables
Create a .env file in the root directory:
PORT=8000
MONGODB_URI=your_mongodb_uri
ACCESS_TOKEN_SECRET=your_access_token_secret
REFRESH_TOKEN_SECRET=your_refresh_token_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_key
CLOUDINARY_API_SECRET=your_cloudinary_secret- Start the server
npm run devComplete API documentation is available via Postman:
backend-project/
├── src/
│ ├── controllers/
│ ├── models/
│ ├── routes/
│ ├── middlewares/
│ └── utils/
├── public/
│ └── temp/
└── package.json
This project is open source and available for educational purposes.