Skip to content

Rinshin-Jalal/WeTube-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WeTube Server 🌐

logo

WeTube Server - The backend of WeTube, an OpenSource YouTube clone.

This project has been in my plans🗂️ for about a year.

At the same time I started this two days ago, I received an email about the hackathon, and

I attempted to build it using redis and express

Accessible Routes 👇‍

Accessible Routes

Screenshot of Frontend (not completed) 👇‍ image


How it works

How the data is stored:

For the development, I used the Redis-OM node. There are 4 different schemas: the User, Token, Video, and Comment Schemas.

1. User schema :

  • entityID: string
  • email: string
  • username: string
  • password: number
  • profile: string
  • followers: string[]
  • isVerified: boolean
  • videos: string[]

The entityId and username are indexed here, allowing us to find users by entityId and username.

2. Token schema :

  • entityId: string
  • user: string
  • token: string
  • passwordReset: boolean

This was used to store the password reset and email verification tokens. So everything is indexed.

3. Video schema :

  • entityId: string
  • _id: string
  • token: string
  • description: boolean
  • thumbnail: string
  • url: string
  • user: string
  • createdAt: date
  • likes: string[]
  • dislikes: string[]
  • comments: string[]

here, the _id - short id and userare primarily indexed, so we can find videos with _id and user.

4. Comments schema

  • entityId: string
  • message: string
  • video: string
  • likes: string[]
  • dislikes: string[]
  • user: string

here, the video is primarily indexed, so we can find comments of a certain video.

How the data is accessed:

It is very simple to access the data using redis-om. There are many requests in the server; here are some of the most important ones.

  • Get user using email address - loginUser controller
  const user = await userRepo
    .search()
    .where("email")
    .equals(email)
    .return.first();
  • Get all videos of a user - getUser controller
  const videos = await videoRepo
   .search()
   .where("user")
   .equals(user.entityId)
   .return.all();
  • Get a token using a specific user, token, and passwordReset is true - changePassword controller
  const token = await tokenRepo
    .search()
    .where("user")
    .equals(req.params.id)
    .where("token")
    .equals(req.params.token)
    .where("passwordReset")
    .is.true()
    .return.first();
  • Get a video based on it's _id - getVideo controller
  const video = await videoRepo
    .search()
    .where("_id")
    .equals(req.params.id)
    .return.first();

How to run it locally?

Prerequisites

  • Node - v16
  • NPM

Local installation

  1. clone the repo
git clone https://github.com/Rinshin-Jalal/WeTube-Server
  1. install packages
cd WeTube-Server/server
npm i
  1. setup environmental variables
PORT=6521
JWT_SECRET

// Cloudinary setup
CLOUD_NAME
CLOUD_API_KEY
CLOUD_API_SECRET

// Redis setup
REDIS_URL

// nodemailer setup
EMAIL
HOST
PASS
BASE_URL
MAIL_PORT
  1. Run
npm start

More Information about Redis Stack

Here some resources to help you quickly get started using Redis Stack. If you still have questions, feel free to ask them in the Redis Discord or on Twitter.

Getting Started

  1. Sign up for a free Redis Cloud account using this link and use the Redis Stack database in the cloud.
  2. Based on the language/framework you want to use, you will find the following client libraries:

The above videos and guides should be enough to get you started in your desired language/framework. From there you can expand and develop your app. Use the resources below to help guide you further:

  1. Developer Hub - The main developer page for Redis, where you can find information on building using Redis with sample projects, guides, and tutorials.
  2. Redis Stack getting started page - Lists all the Redis Stack features. From there you can find relevant docs and tutorials for all the capabilities of Redis Stack.
  3. Redis Rediscover - Provides use-cases for Redis as well as real-world examples and educational material
  4. RedisInsight - Desktop GUI tool - Use this to connect to Redis to visually see the data. It also has a CLI inside it that lets you send Redis CLI commands. It also has a profiler so you can see commands that are run on your Redis instance in real-time
  5. Youtube Videos

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages