A chat server based on the microservice architecture to ensure high availability, high throughput, horizontal scalability
Find a file
Raman 099a1cba84
Fix/push notification (#98)
* fix: switch to #send method of fcm

* fix: firebase ttl keys
2024-09-30 16:21:56 +05:30
.github bump: github actions 2024-09-30 09:43:22 +00:00
.gitpod update dependencies (#96) 2024-09-30 15:03:42 +05:30
.husky update dependencies (#96) 2024-09-30 15:03:42 +05:30
.vscode Binary message support (#87) 2022-09-04 13:59:13 +05:30
deployment feat expose metrics for monitoring (#90) 2022-10-08 18:17:56 +05:30
docs feat: changes docs for Nats support 2022-07-31 18:20:04 +05:30
helper update dependencies (#96) 2024-09-30 15:03:42 +05:30
libs update dependencies (#96) 2024-09-30 15:03:42 +05:30
proto Binary message support (#87) 2022-09-04 13:59:13 +05:30
services Fix/push notification (#98) 2024-09-30 16:21:56 +05:30
www update dependencies (#96) 2024-09-30 15:03:42 +05:30
.babelrc message broker agnostic (#44) 2022-02-19 18:24:51 +05:30
.dockerignore message broker agnostic (#44) 2022-02-19 18:24:51 +05:30
.editorconfig Updated to architecture v2.x (#23) 2021-10-19 17:53:30 +05:30
.env.tmpl Binary message support (#87) 2022-09-04 13:59:13 +05:30
.gitignore message broker agnostic (#44) 2022-02-19 18:24:51 +05:30
.gitpod.yml feat expose metrics for monitoring (#90) 2022-10-08 18:17:56 +05:30
.prettierrc.json update dependencies (#96) 2024-09-30 15:03:42 +05:30
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#35) 2021-11-11 08:26:19 +05:30
CONTRIBUTING.md Create CONTRIBUTING.md (#69) 2022-04-16 19:01:19 +05:30
Dockerfile fix: docker base image tag 2024-09-30 09:47:25 +00:00
eslint.config.js update dependencies (#96) 2024-09-30 15:03:42 +05:30
LICENSE Create LICENSE 2020-06-29 19:02:37 +05:30
package.json fix: switch to #send method of fcm (#97) 2024-09-30 15:59:45 +05:30
README.md feat: changes docs for Nats support 2022-07-31 18:20:04 +05:30
SECURITY.md Update SECURITY.md 2022-05-28 17:11:59 +05:30
yarn.lock update dependencies (#96) 2024-09-30 15:03:42 +05:30

Chat Server

Contributor Covenant Gitpod Ready-to-Code

A chat server based on the microservice architecture to ensure high availability, high throughput, horizontal scalability.

Architecture

Architecture

Components

  • Nginx: Nginx act as API gateway as well as load balancer.

    • Responsibility
      • API Gateway
      • Authentication
      • Load Balancing
  • Web Socket Gateway: It's handling client websocket connection and sending message to message broker

    • Responsibility
      • Maintaining Web Socket Connection
      • Forwarding event like onConnect, onDisconnect, new-message to message broker
      • Sending message back to client
  • Rest Http Gateway: It handle rest call to send messages.

    • Responsibility
      • Send Message to message broker.
  • Profile MS: Rest Api Service provides functionality like login, auth, contact-sync

    • Responsibility
      • Login, Auth
      • Contact Sync
  • Group MS: Rest Api Service provides functionality to create, update

    • Responsibility
      • Create Group
      • Add, Remove Members
      • Fetch groups
  • Message Delivery MS: Message delivery in real time when the user is connected, syncing messages when user is offline

    • Responsibility
      • Maintaining User connection state.
      • Message push in real time when a user in connected.
      • Store message when the user is disconnected.
      • Guaranteed message delivery to the receiver.
      • Ability to sync message in background.
  • Message Router: Route the incoming new message to respective destination

    • Responsibility
      • Parse message.
      • Redirect message to respective destination for e.g.
        • Route group message to Group Message Router.
  • Group Message Router: Route the incoming group messages to respective destination

    • Responsibility
      • Fetch group users for particular user.
      • Update message meta with user list.
      • Redirect Message to respective destination.
  • Push Notification: Deliver message to user when user is offline

    • Responsibility
      • Deliver message to offline user

Message Format

{
    "_v": 2.1,
    "id": "string",
    "head" : {
        "type": "chat|group|channel|bot|notification",
        "to": "username|group_id|channel_id|bot_id",
        "from": "username",
        "chatid": "chatid", // to be deperciated, added for backward comptibility only,
        "ephemeral": "true/false",
        "category": "user|system",
        "contentType": "json|text|video|audio|location|form",
        "action": "message|ack|subscribe|unsubscribe|join|leave|create|add-member|remove-member"
    },
    "meta": {
        "hash": "md5:hash",
        "content_hash": "md5:hash",
        "generate_ts": 123455667890
    },
    "body": {
        "text": "Hello this a text message",
        "ts":123455667890
    }
}
{
    "_v": 2.0,
    "id": "string",
    "head" : {
        "type": "chat|group|channel|bot|notification",
        "to": "username|group_id|channel_id|bot_id",
        "from": "username",
        "chatid": "chatid", // to be deperciated, added for backward comptibility only
        "contentType": "json|text|video|audio|location|form",
        "action": "message|ack|subscribe|unsubscribe|join|leave|create|add-member|remove-member"
    },
    "meta": {
        "hash": "md5:hash",
        "content_hash": "md5:hash",
        "generate_ts": 123455667890
    },
    "body": {
        "text": "Hello this a text message",
        "ts":123455667890
    }
}

Mapping with previous Message format

{
    "msgId": "id",
    "from": "head.from",
    "type": "head.content_type",
    "to": "head.to",
    "chatId": "head.to",
    "text": "body.text",
    "state": "n/a",
    "module": "head.type",
    "action": "head.action",
    "chatType": "head.type"
}

Directory Structure

Name Description
.github Configuration files related to github like workflows, funding
.gipod Configuration files for gitpod dev enviroment setup
.husky git hooks configuration via husky
deployment Deployment scripts
docs Docs related to the project
helper Common utility functions
libs Project specific libs like base class for microservice, resource configuration and initialization
services Microservice
www Web based testing interface
.env.tmpl Environment template file
.gitpod.yml Gitpod configuration file
LICENSE Project License file (MIT)
package.json Node project configuration file
README.md Project description and other details

How to setup

Use Gitpod as development environment

Click on the Gitpod badge it will start the fully setup development environment.

Gitpod Ready-to-Code

Development environment on local machine

Prerequisites

Steps

  • Clone the master branch of the project

  • Install dependencies

    npm install 
    

    Or

    yarn install 
    
  • Make copy of .env.tmpl to .env and update the required variables

    cp .env.tmpl .env
    
  • Initialize Message Broker

    cd deployment/scripts
    

    Setup Kafka

    ./init-kafka.bash ${KAFKA_INSTALLATION_DIRECTORY} .env
    

    OR

    Setup Nats

    ./init-nats.bash .env
    
  • Open project in vscode

  • Start the required microservice from RUN and DEBUG option

  • (Optional) Start nginx using the configuration deployment/config/nginx.config

Deployment

For deployment guide refer to deployment/README.md.

Resources

API specs doc

Run in Postman

  • API documentation here

  • Open API specs 3.0 here

Blog posts

To follow the update keep a eye on vartalap blogs on blog.one9x.org Some of the relevent blogs are:

LICENSE

MIT