Giter Club home page Giter Club logo

chat-app-backend's Introduction

Chat-App-Backend

Backend side of a Chat application made with Express, PostgreSQL and Websocket and RabbitMQ.

The system is composed of 3 microservices:

  • ws-server: handles ws connections and broadcasts messages to connected users, publishes incoming messages to the RabbitMQ message queue for later process;
  • msg-api: simple API to retrieve old messages (GET method) stored in PostgreSQL db and store them trough POST method;
  • msg-store-worker: worker that consumes the message queue and stores them by POSTing to msg-api;

The servers connects to a PostgreSQL database available locally to store all incoming messages and allow the frontend to fetch them. When launched, it connects to PostgreSQL and listens to incoming Websocket connections from clients. It then broadcasts incoming messages to all the other clients connected to form a group chat.

Install

Run

npm install

to install the npm packages.

Docker

PostgreSQL and RabbitMQ can be installed either locally or made available in a container easily using the docker-compose.yaml file in the root of the project.

If using the latter, be sure to have Docker installing and running on your system.

Create .env

Create in the root folder a file called .env, writing the variables copying the contents of .env.example. You can of course also change their values.

To generate the JWT_SECRET you can use

"ts-node-dev \"./src/services/generateJWTSecret.ts\""

It will generate 32 random bytes in hex form and make with it a 64 length string.

Postgres

First, be sure PostgreSQL is installed and running on your computer. If instead of using a local instance you are using Docker, just run

docker-compose up

from the root of the project.

Then, run prisma migrate to have your local db in sync with the schema

npx prisma migrate dev

Launch the project

Launch the microservices with

ts-node-dev \"./src/ws-server.ts\"
ts-node-dev \"./src/msg-api.ts\"
ts-node-dev \"./src/msg-store-server.ts\"

chat-app-backend's People

Contributors

andra961 avatar

Watchers

 avatar

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.