Giter Club home page Giter Club logo

arcase's Introduction

Messaging Service Case Study for Armut.com

This document provides useful informations about the project and its deployment process.

Table of Contents

  1. About the project
    1. Why is it scalable?
  2. How does it work?
  3. What is the deployment process?
  4. Use cases
  5. API endpoints
  6. Project utilities
    1. Logging
    2. Tests

This project provides services which users can register/login and send message to other users. Also users can block other users. Messaging functionality is not realtime, but implemented as an inbox.

To make it scalable, I both separated mongo service and dbprovider service from app to make app service isolated. app service authenticates and handles business logic. It makes requests to get resources from dbprovider. dbprovider acts as an interface service for database. dbprovider uses mongo service to provide resources to clients. It may seem reduntant but it helps us to change our database engine without breaking our app. Also other services (if developed in the future) can also use database. I planned to implement it as auth, user and message services at first but later on I thought it will be quicker to implement an app service to handle multiple functionalities and to met acceptance criterias.

Also while writing the code, I tried to apply Clean Code and SOLID principles. So it is easy to add new features for future development with less bug.

Services

Services

Flow and routing in detail

Flow

This project designed to run as docker containers. It uses docker-compose.yml file and .env file to set env variables for services. Currently there are 3 services:

  • app: authenticates user and implements functionalites
  • dbprovider: provides db. Currently uses mongo service. Acts as a db interface.
  • mongo: runs mongo db.

Currently sessions are on ram (express session module) and passwords are not hashed (not the best practise).

This project can be deployed on a host by using docker-compose commands. All services are isolated and can communicate through a network (currently on the same host). Run provided ./init.sh to run project with docker-compose.

  1. Users can register with username and password
  2. Users can login with username and password
  3. Users can send messages to other users by their username
  4. Users can block another user by their username
  5. Users cannot send message if reciever is blocked him/her
  6. Users can view their all incoming messages
Method Route Function
POST /auth/register Register user
POST /auth/login Login user
GET /api/user/:id/message?type=incoming Get incoming messages
POST /api/user/:id/message Send message
PUT /api/user/:id/block Block user with username

Also dbprovider has its own API but I didn't include here.

In this project, a logger module which uses winston package provides log persistency. Sample log is as below:

2021-02-12T21:57:57.719Z | /api/user | 500 | A message couldn't send. request={safe(req.body)} | {error.stack}

There is a duplication at logger module (is used in both app and dbprovider services) but it can be solved by deploying the logger module as a package so it is possible to use it by installing via a package manager (currently npm).

In this project Jest package is used to write unit tests. Currently tests are written only for the app service, dbprovider service has a similar structure so I skipped it. In the app service folder, run npm test to start testing and also npm run test-coverage to view coverage reports.

arcase's People

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.