Skip to content

rndevoo/chat

Repository files navigation

rndevoo's Chat Microservice

Greenkeeper badge Build Status CircleCI Coverage Status David PRs Welcome

Introduction

This is rndevoo's chat microservice. It handles the real-time chat within the app.

It is written in TypeScript. Fully containerized using Docker.

It uses RabbitMQ for inter-service communication and ws for the WebSockets server.

The tests are written with Mocha, Chai (expect variant) and Sinon.

Installation

Getting the Code

Ideally, you'd want all rndevoo's services inside a folder, so create a rndevoo folder somewhere:

$ mdkir -p ~/projects/rndevoo
$ cd ~/projects/rndevoo         # Change directory to the newly created.

Now clone the repository with Git:

$ git clone https://github.com/rndevoo/chat

Common Configuration to All Services

You'll need Docker and Docker Compose installed in your machine. If you don't have them, follow their guides: for Docker and for Docker Compose.

Now, if it hasn't already been created, we need to create a custom Docker network so we run all of our services containers and the RabbitMQ server in the same network and they can communicate with each other.

So, check if the network already exists:

$ docker network ls | grep rndevoo_network

If nothing shows up, then create it:

$ docker network create --driver bridge rndevoo_network

Now we need to have a RabbitMQ server running in a docker container in order to let the inter-service communication happen.

First check if it hasn't been created already:

$ docker ps -a | grep rabbit

If you see nothing, it is time to spin up a RabbitMQ container:

$ docker run -d --hostname rabbitmq --network rndevoo_network --name rabbit \
-p 15672:15672 -p 5672:5672 rabbitmq:3-management

If you want to access RabbitMQ's management panel, go to http://localhost:15672.

To learn more about Docker see their docs.

Install System Requirements

You don't need Node or Yarn, because the Docker container has them, but it may be useful to have them installed in your machine.

To install them, follow their guides: for Node and for Yarn

Configure Environmental Variables

Generate your local .env file:

$ yarn run gen_env_file

Now that you have your local .env file, fill it!

Install App Dependencies

$ yarn install

Spinning Up the Development Container

Build and start the development container:

$ docker-compose up

In order to open a terminal session from inside the web Docker container run:

$ docker-compose exec web /bin/bash

To learn more about Docker Compose see their docs.

Directory Layout

├── scripts/       # Useful scripts.
├── src/           # The source code. Contains unit tests.
│   ├── config/    # Configuration files of some modules (e.g. Winston).
│   ├── handlers/  # WebSocket server event handlers.
│   ├── utils/     # Utility functions.
│   └── server.ts  # The main server.
├── test/          # Integration tests.

Testing

Run the tests:

$ yarn test

Other Services and API Gateway

License

GPL-3.0