A high-performance, scalable backend architecture for video sharing, built with Node.js, Express, and MongoDB Aggregation Pipelines.
This project implements a production-grade backend with a focus on scalability and data consistency.
- Complex Aggregations: Uses MongoDB Aggregation Pipelines (
$lookup,$unwind,$addFields) for high-performance data joining (e.g., fetching videos with owner details and subscription status in a single query). - JWT Security: Implements a dual-token architecture (Access Token + Refresh Token) for secure, stateless authentication.
- Cloud-Native Storage: Integrates Cloudinary for scalable video/image storage and optimization.
- Optimized Queries: Uses
mongoose-aggregate-paginate-v2for efficient pagination on heavy datasets.
- Runtime: Node.js (v20+)
- Framework: Express.js
- Database: MongoDB (Mongoose ODM)
- Storage: Cloudinary API
- Auth: JSON Web Tokens (JWT), Bcrypt
- Validation: Mongoose Schema Validation
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/api/v1/users/register |
Register a new user with avatar | Public |
POST |
/api/v1/users/login |
Login and receive Access/Refresh tokens | Public |
POST |
/api/v1/videos/publish |
Upload video & thumbnail (Multipart) | Auth |
GET |
/api/v1/videos |
Get all videos with pagination & filters | Public |
GET |
/api/v1/users/c/:username |
Get channel profile & stats | Auth |
- Clone the repository
git clone [https://github.com/ImAryanPandey/video-sharing-platform.git](https://github.com/ImAryanPandey/video-sharing-platform.git)
cd video-sharing-platform/backend- Install Dependencies
npm install
- Environment Variables
Create a
.envfile in the root:
PORT=8000
MONGODB_URI=mongodb+srv://<your-mongo-url>
CORS_ORIGIN=*
ACCESS_TOKEN_SECRET=your-secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your-secret
REFRESH_TOKEN_EXPIRY=10d
CLOUDINARY_CLOUD_NAME=...
CLOUDINARY_API_KEY=...
CLOUDINARY_API_SECRET=...
- Run the Server
npm run dev
- Video Transcoding (HLS/DASH)
- Real-time Comments (Socket.io)
- Redis Caching for Trending Videos
Built by Aryan Pandey