Coder Social home page Coder Social logo

be-nest-micro's Introduction

Description

Nest application example involing microservices, restful api, chat, jwt auth, mongo, docker, dto, validation, file upload, socket io, rabbitmq queue, swagger, kong & unit tests.

Installation

$ npm install
$ docker-compose pull
$ docker-compose build

List of sub apps

  • api (main api) :3001
  • auth (authentication endpoint) :3002
  • stream (consumer & socket io server) :3003

Running the app

For testing purposes there's no need to setup yer env file. If you got trouble with port conflicts, add .env file to root project according to these configuration

# run database & message broker instance
$ docker-compose up -d mongo rabbitmq

# development
$ npm run start [<app>]

# watch mode
$ npm run start:dev [<app>]

# production mode
$ npm run start:prod [<app>]

# or run as unified api through kong gateway
# and all api will have prefix /api & listen on port 8000
$ docker-compose up -d kong api auth stream

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

API Documentation

OpenAPI format available at (Try On The Go)

  • http://localhost:3001
  • http://localhost:3002

make sure the instance is running.

Because of incapability of swagging websocket, you can try it on my Postman workspace

FAQ

Q: Talk about data flow, it seems in api the data are queried straight, and doesn't use microservice thing, why?

A: It's indeed need to be distributed to the next service like that. But it can cause network congestion just because to get simple thing, alternatively, the service (sub app) can be scaled too to achieve same goal. In other words, i use the broker for async purpose like chatting, where it's possible to have some serious delay because of queuing behaviour.

Q: Why doesn't use socket.io room feature? and instead you use traditional websocket transport.

A: Rooms stand on server side so it cost memory to process & store, imagine if we have thousands of user at time, with rooms u need to allocate for each of user who's communicate to few friends exponentially, from here i hope you got the points. That's why for private message we dont need to use room, as room is intended to be grouped message channel.

Q: There's a api gateway service, kong isn't it? what are they for?

A: As we use micro service, api gateway hold the important role to manage them, such as for abstraction layer between upstream & client, reduce the pain of managing route through service api itself(Rate limiting, authentication & authorization, transformation, etc), wrap them up, integrate with tracing to give better analytical usage, security purpose & etc.

be-nest-micro's People

Contributors

yanuarizalk 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.