Giter Site home page Giter Site logo

sayeed1999 / home Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 10.0 597 KB

The monorepo contains unit microservices e.g home-service for sharing posts, chat-service for real-time dual/group chatting, auth-service, email-service, api-gateway for redirecting requests to appropriate services, bullmq as message bus, socket.io used for realtime data.

License: MIT License

TypeScript 99.58% Dockerfile 0.42%
docker modular-architecture nodejs onion-architecture typescript microservice mongodb mysql microservices message-queue websocket

home's Introduction

HOME

The monorepo project 'Home' will contain unit microservices targetting unit purposes e.g api-gateway for public access, home-service that acts like a facebook newsfeed, chat-service for dual or group conversation, auth-service for user authorization, ...

Design Patterns Used

Observer Pattern:

Used in auth-service for notifying other services about user creation/update/deletion. There are methods named fanout_user_creation, fanout_user_update, fanout_user_deletion but the method itself doesn't know who are its subscribers. When the project is started, message queues are subscribed to the subscription from main program. And the subscriber services just gets notified.

Provider Pattern:

This is not one of the 23 GoF patterns. But this is very useful when we centralize the access to all db tables or collections in our application. A application can have twenty models. But a single 'Provider' class contains all the database models or tables as its properties. So all the database models are centralized inside a single class. We can access any db models by creating an instance of the Provider class.

Singleton Pattern:

When creating the Provider class for accessing all db models, there is a chance that multiple instance of the Provider class may get created. So singleton pattern is used to ensure only one instance of the Provider class gets created and accessed by all end-users.

Generic Repository Pattern:

This is also not one of the 23 GoF patterns. But this is extremely handy in reducing the number of duplicate methods accross classes since all classes needs common CRUD methods. A single class acting as the generic repository provides common CRUD methods to all other classes, and any service inheriting from the generic class gets access to all of its methods.

OVERALL STRUCTURE

./api-gateway
  # the central service that client app will communicate with called the api gateway!!
  # runs on localhost:4000

./auth-service
  # microservice for user authentication & authorization
  # runs on localhost:4001
  # server dependency: mysql

./chat-service
  # microservice for messenger-like chatting
  # runs on localhost:4005
  # server dependency: mongodb

./ecom-service
  # microservice for e-commerce or marketplace
  # runs on localhost:4004
  # server dependency: mysql

./email-service
  # microservice for mailing tasks
  # runs on localhost:4003
  # server dependency: nodemailer, mailtrap

./home-service
  # microservice for the virtual home where people will gather to share emotions & thoughts..
  # runs on localhost:4002
  # server dependency: mongodb

How to run the project

You can run each microservice independently by npm start command.

EACH SERVICE FOLDER STRUCTURE

Each module inside ./modules dir will follow "Onion architecture" which says controller layer shall hold request-response processing, service layer shall hold businesses and repository layer shall hold database queries. This way, one layer will be topped over the other layer like a sandwitch!

src
│ app.js # App entry point
└─── api # Express route controllers for all the endpoints of the app
└───── routes
└───── middlewares
└─── config # Environment variables and configuration related stuff
└─── jobs # Jobs definitions for agenda.js
└─── loaders # Split the startup process into modules
└─── models # Database models
└─── modules
└───── base
└─────── controller
└─────── service
└─────── repository
└───── <module>
└─────── controller
└─────── service
└─────── repository
└─── subscribers # Event handlers for async task
└─── types # Type declaration files (d.ts) for Typescript
└─── utils
└───── constants
└───── helpers

Available endpoints through API Gateway

Accessible endpoints to auth-service

Register an account:-

POST /auth/register
body
{
  "name": "Md. Sayeed Rahman",
  "email": "[email protected]",
  "password": "123456Aa$"
}

Login an account:-

POST /auth/login
body
{
  "email": "[email protected]",
  "password": "123456Aa$"
}

Get current user:-

GET /auth/current-user
header: Authorization

Update current user:-

PATCH /auth/current-user
header: Authorization

Delete current user:-

DELETE /auth/current-user
header: Authorization

Accessible endpoints to home-service

Creates a post:-

POST /home/posts
body
{
  "message": "this is a new post"
}
header: Authorization

Updates a post:-

PATCH /home/posts/:id
body
{
  "message": "this is a updated post"
}
header: Authorization

Deletes a post:-

DELETE /home/posts/:id
header: Authorization

Gets all posts for admin:-

description: this will get all posts with comment ids only
GET /home/posts
header: Authorization

Gets all posts for user with top 03 comments:-

description: this will get all posts with top 03 comments embedded into it
GET /home/posts/active-posts
header: Authorization

Gets single post (for admin/user not worked on yet):-

GET /home/posts/:id
header: Authorization

Creates a comment:-

POST /home/posts/:post_id/comments
body
{
  "message": "this is a comment to a post"
}
header: Authorization

Accessible endpoints to chat-service

Gets all users for admin:-

GET /chat/users
header: Authorization

Gets current user for user:-

descripton: in microservice arch, every service should have own get current user(), because db different, user model different.
GET /chat/users/current-user
header: Authorization

Sends message to user in dual conversation:-

POST /chat/conversations/dual/:user_id
header: Authorization
body
{
  "text": "Hi ******"
}

Gets conversation with user in dual conversation:-

GET /chat/conversations/dual/:user_id
header: Authorization

Gets conversation list of current user:-

GET /chat/conversations/dual/conversation-list
header: Authorization

home's People

Contributors

munimrahman avatar sayeed1999 avatar tajul-islam-refath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

home's Issues

initiate conversations through REST API

-- backend

  • get all users endpoint
  • receive messages of single conversation (dual)
  • start dual conversation (dual)
  • get all conversation list for logged in user (dual)
  • send message to another user (dual)

chatapp/ write models for conversations

  • write enum for conversation_type
  • create Conversation mongoose model with props: participants[], messages[], conversation_type(Duo/Group), timestamps
  • create Message mongoose schema with props: sender, timestamps, message

newsfeed/ load comments with post

  • get all comments with getSinglePost endpoint by default
  • getAllPosts endpoint shall have top 03 comments with each post
  • getAllCommentsByPostId endpoint

newsfeed/ features

  • cascade delete posts when a user is permanently deleted from db (comment not needed to delete from user model's hook. if user deletes posts, posts will automatically delete comments as implemented)
  • restore post from recycle bin by deletedAt = null

create endpoints from group chatting

  • create group endpoint, first user will be logged in user
  • add users[] to group

Logic for adding user to group:-

  • added user cannot be added to group
  • filter out already present users from adding list, then add new users
  • remove single user from group

Logic for removing user:-

  • if only one user remains, and he removes himself, then delete entire conversation from db

newsfeed/ post delete: soft delete and hard delete

  • deletedAt property in post model default null

  • deletePostById endpoint -> should soft delete by default,

  • deletePostById endpoint -> ?hardDelete=true should permanently delete posts and postlogs

  • delete all comments for hard delete on post

  • take db operation for service to repo in post module

ecommerce/ category crud with log keeping

  • create category
  • edit category
  • delete category
  • get category(s)
  • Product Create /Update/Delete with ProductLog
  • deletedAt prop in product model (default value: null) implement soft delete
  • get all category should not bring deleted products
  • undo soft delete

API Security in chat service

  • outsiders should not see dual or group conversations messages
  • outsiders should not add or remove members from group

here outsider means those who are not participants of that chat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.