20

Twitube

Youtube and Twitter entire backend.

Backend Video Streaming Project - Model Link

Table of Contents

Overview

This project is a backend system for a YouTube-like application that supports user registration, login, and logout functionalities. As development progresses, more features like video uploading, comments, likes, and subscriptions are being added.

Features

User Management:

  • Registration, login, logout, change password
  • Profile management (avatar, cover image, other details)
  • Watch history tracking and Clearing Watch History
  • Liked videos tracking

Seeding:

  • Seed Random Users with Dummy information
  • Get Seeded Informaiton of the Pre-seeded users.
  • Seed user with @faker-js.

Video Management:

  • Video upload
  • Canceling Video upload with all resources cleaned up on backend.
  • Visibility control (publish/un-publish)
  • Video editing and deletion
  • Video Search and pagination

Tweet Management:

  • Tweet creation and publishing
  • Viewing user tweets
  • Updating and deleting tweets
  • Liking-disliking tweets

Subscription Management:

  • Subscribing to channels
  • Viewing Channel subscriber
  • Viewing Subscribed channel lists

Playlist Management:

  • Creating, updating, and deleting playlists
  • Adding videos to playlists
  • Removing videos from playlists and undoing them
  • Viewing user playlists

Like Management:

  • Liking and Un-liking videos, comments, and tweets
  • Viewing liked videos

Comment Management:

  • Adding, updating, and deleting comments on videos

Dashboard:

  • Viewing channel statistics (views, subscribers, videos, likes)
  • Accessing uploaded videos and Controls
  • Viewing Video statistics (PublishStatus, VideoName, DateUploaded, Views, TotalComments, LikeRatings)

Health Check:

  • Endpoint to verify the server's health

Technologies Used

  • Backend Framework: Node.js with Express
  • Database: MongoDB with Mongoose
  • Authentication: JSON Web Token (JWT)
  • Message Broker (for future features): RabbitMQ
  • File Storage: (e.g., cloudinary, local storage, etc.)
  • Containerization: (for future features) Docker (for RabbitMQ and other services)

Installation

Method 1: Docker-compose.yml

  1. Clone the repository then do:
    docker compose up -d

Method 2: Manual

  1. Clone the repository:

    git clone git@github.com:Barmanji/Youtube-and-Twitter-Compelete-Backend.git
    cd Youtube-and-Twitter-Compelete-Backend
  2. Install dependencies:

    pnpm install
  3. Set up environment variables:

    Create a .env file in the root of your project and add the following OR Change .env.example -> .env

    PORT=8000
    ORIGIN_KEY_CORS=*
    MONGODB_URI=MAKE_IT_YOUR_OWN_ALSO_DONT_AND_I_MEAN_IT_DONT_PUT_@_IN_PASS_SPECIALLY_IN_THE_END
    ACCESS_TOKEN_SECERET = Your ACCESS_TOKEN_SECERET
    ACCESS_TOKEN_EXPIRY = Your ACCESS_TOKEN_EXPIRY
    REFRESH_TOKEN_SECERET = Your REFRESH_TOKEN_SECERET
    REFRESH_TOKEN_EXPIRY = Your REFRESH_TOKEN_EXPIRY //use numbers like 10d === 10days
    CLOUDNARY_APISECRET = Your_Api_Seceret-from-Cloudinary
    CLOUDNARY_APIKEY = Your_Api_Key-from-Cloudinary
    CLOUDNARY_CLOUDNAME = Your-Cloud-name
  4. Start the server:

    pnpm run dev

Running the Project

Once you have completed the setup, you can run the project using:

pnpm start

This will start the server, and the application will be available on http://localhost:8000.

API Endpoints

User

MethodEndpointDescriptionProtected
POST/api/v1/user/registerRegister a new userNo
POST/api/v1/user/loginLogin and get tokenNo
POST/api/v1/user/logoutLogout userYes
GET/api/v1/user/refresh-tokenEndPoint to Refresh all TokensYes
POST/api/v1/user/change-passwordChange password from old to newYes
GET/api/v1/user/current-userGive login user detailsYes
PATCH/api/v1/user/update-accountUpdate user fullname and emailYes
PATCH/api/v1/user/avatarChange Avatar of the Login userYes
PATCH/api/v1/user/cover-imageChange Cover Image of the Login userYes
GET/api/v1/user/c/:usernameGive channel details like subcribers and allYes
GET/api/v1/user/historyGive watchHistory of login userYes

Dashboard

MethodEndpointDescriptionProtected
POST/api/v1/user/seedSeed the database with dummy users.No
GET/api/v1/user/seed-credentialsGet the credentials of the seeded users.No

Videos

MethodEndpointDescriptionProtected
POST/api/v1/videos/Upload a videoYes
GET/api/v1/videos/Get videos by searchYes
GET/api/v1/videos/:videoIdGet a specific video by its IDYes
DELETE/api/v1/videos/:videoIdDelete a video by its IDYes
PATCH/api/v1/videos/:videoIdUpdate video detailsYes
PATCH/api/v1/videos/toggle/publish:videoIdToggle publish statusYes

Comments

MethodEndpointDescriptionProtected
POST/api/v1/comments/:videoIdPost a comment on a videoYes
GET/api/v1/comments/:videoIdGet comments for a specific videoYes
DELETE/api/v1/comments/c/:commentIdDelete comments through IdYes
PATCH/api/v1/comments/c/:commentIdUpdate comment through IdYes

like

MethodEndpointDescriptionProtected
POST/api/v1/likes/toggle/v/:videoIdtoggle like of videoYes
POST/api/v1/likes/toggle/c/:commentIdtoggle like of commentYes
POST/api/v1/likes/toggle/t/:tweetIdtoggle like of tweetYes
GET/api/v1/likes/videosGet all the Likes of videoYes

Tweet(This is similar to community tab)

MethodEndpointDescriptionProtected
POST/api/v1/tweets/Create tweetYes
GET/api/v1/tweets/user/:userIdGet User tweetYes
PATCH/api/v1/tweets/:tweetIdupdate tweetYes
DELETE/api/v1/tweets/:tweetIddelete the TweetYes

PlaylistRouter

MethodEndpointDescriptionProtected
POST/api/v1/playlist/Create PlaylistYes
GET/api/v1/playlist/:playlistIdGet Playlist By IdYes
PATCH/api/v1/playlist/:playlistIdUpdate PlaylistYes
DELETE/api/v1/playlist/:playlistIddelete the PlaylistYes
PATCH/api/v1/playlist/add/:videoId/:playlistIdAdd video to playlist PlaylistYes
PATCH/api/v1/playlist/remove/:videoId/:playlistIdRemove video to playlistYes
GET/api/v1/playlist/user/:userIdGet Playlist of a userYes

Dashboard

MethodEndpointDescriptionProtected
GET/api/v1/dashboard/statsGet channel detailsYes
GET/api/v1/dashboard/videosGet Video upload by channelYes

Subscriptions

MethodEndpointDescriptionProtected
POST/api/v1/subscriptions/c/:channelIdToggle Subscription to channelYes
GET/api/v1/subscriptions/c/:channelIdGot Subsbcriber list of channelYes
GET/api/v1/subscriptions/u/:subscriberIdsubscriber list of a User channelYes

HealthCheck

MethodEndpointDescriptionProtected
GET/api/v1/healthcheckGet Health StatusYes

Future Improvements

  • Video Recommendations: Recommend videos based on user preferences.
  • Analytics: Track views and other engagement metrics.
  • Notifications: Real-time notifications for new comments, likes, and subscriptions.
  • Microservices Architecture: Plan to scale the application by breaking features into microservices.
  • CI/CD: Set up automated testing and deployment pipelines.

Liscense

Project is Liscensed under ChaiAurCode

Pull me