Skip to content

backend clone of youtube - media storage and sharing api written in go using microservice architecture

License

Notifications You must be signed in to change notification settings

rzaf/youtube-clone

Repository files navigation

youtube-clone

media storage and sharing api written in go using microservice architecture.

  • for simplicity and data integrity used a central database for user related data except media files
  • written in a request-response architecture
  • services communicate to each other using gRPC

microservices

auth service

authentication microservice used for registering user and retrieving user JWT token and refreshing it

gateway service

main api of app for user related data (users,medias,comments,playlists,likes,tags,followings)

file service

  • has a Rest api for recieving and uploading media files (photo,video,music)
  • stores all media files and its meta data (other services communicate with file service to know media file url exist and belong to which user)
  • media files are stored in system files and meta data is stored in a mongodb database
  • handles video,music formating and compression (using ffmpeg)

database service

  • central database (postgres) for storing all user user related data (users,medias,comments,playlists,likes,tags,followings)
  • other services communicate with database service to get user related data

notification service

  • recieves notifications from other services to send to user
  • send emails to users for verifications and notifications

api endpoints

protected routes require authentication with bearer tokens

auth service routes

type url protected
GET api/login
GET api/register
GET api/refresh

gateway service routes

USERS

type url protected
GET api/users/{username}
GET api/users
GET api/users/search/{term}
POST api/users/{username}/verify/{code}
POST api/users/resend-email
PUT api/users/{username}/profile-photo
GET /users/{username}/followings
PUT api/users/{username}/channel-photo
PUT api/users/{username}
DELETE api/users/{username}
POST api/follows/{username}
DELETE api/follows/{username}

MEDIAS

type url protected
GET api/medias
GET api/medias/search/{term}
GET api/medias/{url}
POST api/medias
PUT api/medias/{url}
DELETE api/medias/{url}
POST api/medias/{url}/tag/{name}
DELETE api/medias/{url}/tag/{name}
POST api/medias/{url}/playlists/{playlistUrl}
PUT api/medias/{url}/playlists/{playlistUrl}
DELETE api/medias/{url}/playlists/{playlistUrl}

COMMENTS

type url protected
GET api/comments/{commentUrl}
GET api/comments/medias/{url}
GET /comments/{commentUrl}/replies
POST api/comments/medias/{url}
PUT api/comments/{commentUrl}
DELETE api/comments/{commentUrl}

LIKES

type url protected
POST api/medias/{url}/likes
DELETE api/medias/{url}/likes
POST api/comments/{url}/likes
DELETE api/comments/{url}/likes

PLAYLISTS

type url protected
GET api/playlists
GET api/playlists/search/{term}
GET api/playlists/{url}
GET api/playlists/{url}/medias
POST api/playlists
PUT api/playlists/{url}
DELETE api/playlists/{url}

file service routes

type url protected
GET api/photos/{url}
GET api/videos/{url}
GET api/musics/{url}
POST api/photos/upload
POST api/videos/upload
POST api/musics/upload

Prerequisites

  • Go (1.20)
  • docker and docker compose
  • Protobuf compiler (protoc) & go plugins (optional):
    • install protocol buffer compiler link
    • install protoc-gen-go and and protoc-gen-go-grpc by running go install google.golang.org/protobuf/cmd/protoc-gen-go and go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
    • have protoc and GOPATH in your PATH env

build

docker

  1. Build Go Files and Docker Containers

    To build the Go binaries and Docker containers, use:

    make build 

    If protoc and the Go plugins are installed, you can generate Protocol Buffer files and build Swagger docs files along with the Go binaries:

    make all 
  2. Create .env file

    cp .env.example .env 
  3. Run Docker containers

    Start the Docker containers using:

    make run

    or simply run docker compose up

docker swarm

Deploy using Docker Swarm

make swarm

features

  • video,music,photo storage and sharing
  • video and music streaming
  • swagger documentations (at /docs)
  • user subscribing (following)
  • comment and reply on medias
  • media and comment likes
  • searching users,medias,playlists
  • multi media playlists
  • email verification
  • user upload limit
  • notifications:
    • new media from following user (subscribing)
    • new comment on users media
    • new reply on users commnet
    • new like on users media,comment,reply
    • new follower (subscriber)

todo

  • image compression
  • multiple video quality and bitrate
  • video subtitle
  • video thumbnail from video
  • adding image to musics

About

backend clone of youtube - media storage and sharing api written in go using microservice architecture

Topics

Resources

License

Stars

Watchers

Forks

Languages