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 👇
Screenshot of Frontend (not completed) 👇
live demo (server) - https://wetube-server-production.up.railway.app
For the development, I used the Redis-OM node
.
There are 4 different schemas: the User, Token, Video, and Comment Schemas.
- 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.
- entityId: string
- user: string
- token: string
- passwordReset: boolean
This was used to store the password reset and email verification tokens.
So everything
is indexed.
- 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 user
are primarily indexed, so we can find videos with _id and user.
- 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.
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
, andpasswordReset
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();
- Node - v16
- NPM
- clone the repo
git clone https://github.com/Rinshin-Jalal/WeTube-Server
- install packages
cd WeTube-Server/server
npm i
- 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
- Run
npm start
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.
- Sign up for a free Redis Cloud account using this link and use the Redis Stack database in the cloud.
- Based on the language/framework you want to use, you will find the following client libraries:
- Redis OM .NET (C#)
- Watch this getting started video
- Follow this getting started guide
- Redis OM Node (JS)
- Watch this getting started video
- Follow this getting started guide
- Redis OM Python
- Watch this getting started video
- Follow this getting started guide
- Redis OM Spring (Java)
- Watch this getting started video
- Follow this getting started guide
- Redis OM .NET (C#)
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:
- Developer Hub - The main developer page for Redis, where you can find information on building using Redis with sample projects, guides, and tutorials.
- 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.
- Redis Rediscover - Provides use-cases for Redis as well as real-world examples and educational material
- 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
- Youtube Videos
- Official Redis Youtube channel
- Redis Stack videos - Help you get started modeling data, using Redis OM, and exploring Redis Stack
- Redis Stack Real-Time Stock App from Ahmad Bazzi
- Build a Fullstack Next.js app with Fireship.io
- Microservices with Redis Course by Scalable Scripts on freeCodeCamp