Skip to content

abdullahbutt09/stream-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

54 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฌ Stream-Core

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.


๐Ÿ“Œ Features

๐Ÿ” Authentication

  • 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

๐ŸŽฅ Video Management

  • 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)

โค๏ธ Likes

  • Toggle like/unlike on videos, comments, and tweets
  • Get all liked videos of current user

๐Ÿ“‚ Playlists

  • Create, update, delete playlists
  • Add / remove videos from a playlist
  • Get playlist by ID (with populated videos)
  • Get all playlists of a user

๐Ÿ”” Subscriptions

  • 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

๐Ÿง  Concepts Covered

  • 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

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“ Project Structure

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

โš™๏ธ Installation

# 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

๐Ÿฅ Health

Method Endpoint Auth Description
GET /healthcheck โŒ Server health check

๐Ÿ‘ค Users

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

๐ŸŽฅ Videos

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

โค๏ธ Likes

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

๐Ÿ“‚ Playlists

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

๐Ÿ”” Subscriptions

Method Endpoint Auth Description
POST /subscriptions/s/:channelId โœ… Toggle subscribe
GET /subscriptions/s/:channelId โœ… Get channel subscribers
GET /subscriptions/s/:subscriberId โœ… Get subscribed channels

๐Ÿ“Š Dashboard

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


๐Ÿง‘โ€๐Ÿ’ป Author

Abdullah Bin Mughira
Full Stack Developer (MERN Stack)
LinkedIn


๐Ÿ”ฎ Future Improvements

  • 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

About

A backend-focused project for building a social platform where users can share short posts and upload videos, inspired by Twitter and YouTube.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors