A production-style YouTube-like backend built with Node.js , Express , and MongoDB .
Covers real-world concepts like JWT auth, Cloudinary media uploads, aggregation pipelines, and a full channel/subscription system.
Register with avatar + cover image upload (Multer โ Cloudinary)
JWT-based login with access token + refresh token
httpOnly cookie security
Refresh token rotation
Change password, logout
Upload video + thumbnail (Cloudinary)
Get all videos, get by ID
Update title, description, thumbnail
Toggle publish/unpublish status
Delete video
๐ฌ Tweets
Create, update, delete tweets
Bulk delete tweets
Get all tweets of a user
๐จ๏ธ Comments
Add, update, delete comments on videos
Get all comments for a video (with pagination via mongoose-aggregate-paginate-v2)
Toggle like/unlike on videos, comments, and tweets
Get all liked videos of current user
Create, update, delete playlists
Add / remove videos from a playlist
Get playlist by ID (with populated videos)
Get all playlists of a user
Toggle subscribe/unsubscribe to a channel
Get all subscribers of a channel
Get all channels a user is subscribed to
๐ Dashboard (Aggregation Pipelines)
Total videos uploaded
Total views across all videos
Total subscribers
Total likes (via $lookup across Like collection)
Get all videos of a channel
RESTful API design
JWT authentication (access + refresh tokens)
MongoDB Aggregation Pipeline ($lookup, $group, $project)
Mongoose Relationships (ref + populate)
File uploads with Multer + Cloudinary
Custom error handling (ApiError, asyncHandler)
Modular MVC structure
Mongoose indexes for performance + uniqueness
Layer
Technology
Runtime
Node.js
Framework
Express.js v5
Database
MongoDB + Mongoose
Auth
JWT (jsonwebtoken)
Media Storage
Cloudinary
File Uploads
Multer
Validation
Custom middleware
Dev Tools
Nodemon, Prettier
src/
โโโ config/ # Environment variable exports
โโโ controllers/ # Business logic (one file per module)
โ โโโ user.controller.js
โ โโโ video.controller.js
โ โโโ tweet.controller.js
โ โโโ comment.controller.js
โ โโโ like.controller.js
โ โโโ playlist.controller.js
โ โโโ subscription.controller.js
โ โโโ dashboard.controller.js
โ โโโ healthCheck.controller.js
โโโ db/ # MongoDB connection
โโโ middlewares/
โ โโโ auth.middleware.js # verifyJWT
โ โโโ multer.middleware.js # file uploads
โโโ models/ # Mongoose schemas
โ โโโ user.models.js
โ โโโ video.models.js
โ โโโ tweet.models.js
โ โโโ comment.models.js
โ โโโ like.models.js
โ โโโ playlist.models.js
โ โโโ subscription.models.js
โโโ routes/ # Express routers (one file per module)
โโโ utils/
โ โโโ Cloudinary.js # upload/delete helpers
โ โโโ apiError.js # custom error class
โ โโโ apiResponse.js # standard response wrapper
โ โโโ asyncHandlerPromise.js
โ โโโ asyncHandlerTrycatch.js
โโโ app.js # Express app setup, middleware, routes
โโโ index.js # Entry point โ DB connect + server start
# Clone the repo
git clone https://github.com/abdullahbutt09/stream-core.git
# Move into the project
cd stream-core
# Install dependencies
npm install
# Start development server
npm run dev
๐ Environment Variables
Create a .env file in the root and add:
PORT = 8000
MONGODB_URI = your_mongodb_uri
CORS_ORIGIN = http://localhost:3000
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_cloud_name
CLOUDINARY_API_KEY = your_api_key
CLOUDINARY_API_SECRET = your_api_secret
๐ฌ API Endpoints โ Full Reference
Base URL: http://localhost:8000/api/v1
Method
Endpoint
Auth
Description
GET
/healthcheck
โ
Server health check
Method
Endpoint
Auth
Description
POST
/users/register
โ
Register with avatar + cover image
POST
/users/login
โ
Login, get tokens
POST
/users/refresh-token
โ
Refresh access token
POST
/users/logout
โ
Logout current user
POST
/users/change-password
โ
Change password
GET
/users/get-current-user
โ
Get logged in user
PATCH
/users/update-account
โ
Update fullName / email
PATCH
/users/change-avatar
โ
Update avatar
PATCH
/users/change-cover-image
โ
Update cover image
GET
/users/c/:username
โ
Get channel profile
GET
/users/history
โ
Get watch history
Method
Endpoint
Auth
Description
POST
/videos/upload-video
โ
Upload video + thumbnail
GET
/videos/get-all-videos
โ
Get all videos
GET
/videos/v/:videoId
โ
Get video by ID
PATCH
/videos/v/:videoId
โ
Update title / description
PATCH
/videos/v/:videoId/thumbnail
โ
Update thumbnail
PATCH
/videos/v/:videoId/publish
โ
Toggle publish status
DELETE
/videos/delete-videos
โ
Delete a video
๐ฆ Tweets
Method
Endpoint
Auth
Description
POST
/tweets/create-tweet
โ
Create a tweet
GET
/tweets/get-tweets
โ
Get user tweets
PATCH
/tweets/t/:tweetId
โ
Update a tweet
DELETE
/tweets/t/:tweetId
โ
Delete a tweet
DELETE
/tweets/delete-bulk-tweets
โ
Bulk delete tweets
๐จ๏ธ Comments
Method
Endpoint
Auth
Description
GET
/comments/c/:videoId
โ
Get comments for a video
POST
/comments/c/:videoId/add-comment
โ
Add a comment
PATCH
/comments/c/:commentId/v/:videoId/update-comment
โ
Update a comment
DELETE
/comments/c/:commentId/v/:videoId/delete-comment
โ
Delete a comment
Method
Endpoint
Auth
Description
POST
/likes/l/:videoId
โ
Toggle like on video
POST
/likes/c/:commentId
โ
Toggle like on comment
POST
/likes/t/:tweetId
โ
Toggle like on tweet
GET
/likes/get-liked-videos
โ
Get liked videos
Method
Endpoint
Auth
Description
POST
/playlists/create-playlist
โ
Create playlist
GET
/playlists/p/:playlistId
โ
Get playlist by ID
PATCH
/playlists/p/:playlistId
โ
Update playlist
DELETE
/playlists/p/:playlistId
โ
Delete playlist
GET
/playlists/users/:userId/playlists
โ
Get user playlists
PUT
/playlists/p/:playlistId/v/:videoId
โ
Add video to playlist
DELETE
/playlists/p/:playlistId/v/:videoId
โ
Remove video from playlist
Method
Endpoint
Auth
Description
POST
/subscriptions/s/:channelId
โ
Toggle subscribe
GET
/subscriptions/s/:channelId
โ
Get channel subscribers
GET
/subscriptions/s/:subscriberId
โ
Get subscribed channels
Method
Endpoint
Auth
Description
GET
/dashboard/stats
โ
Channel stats (views, subs, likes, videos)
GET
/dashboard/videos
โ
All videos of current channel
โ
= Requires Bearer token ย ย โ = Public
๐ API Documentation (Swagger UI)
Open: http://localhost:8000/api-docs
Abdullah Bin Mughira
Full Stack Developer (MERN Stack)
LinkedIn
Pagination on all list endpoints
Role-based access control (Admin panel)
Redis caching for dashboard stats
Video streaming with byte-range support
Search and filter videos
Notification system