Skip to content

yadav-saurabh/monorepo-microservice

Repository files navigation

Monorepo Microservice

Monorepo Microservices using nestjs kafka and docker, k8s

Getting Started

To get a local copy up and running, please follow these simple steps.

Prerequisites

Here is what you need.

If using k8s

Setup (development)

  • Setup Node If your Node version does not meet the project's requirements as instructed by the docs, either manually or using a tool like nvm or volta (recommended)

  • Clone the repo

    git clone git@github.com:yadav-saurabh/monorepo-microservice.git
  • Go to the project folder

    cd monorepo-microservice

Using docker and docker-compose

  • Install packages with npm

    npm i
  • Set up your .env file

    • Duplicate .env.example to .env
    • Configure environment variables in the .env file. Replace the placeholder values with their applicable values
  • Run docker compose to get all the services up and running

    docker-compose --env-file .env -f ./infra/compose.yaml up
  • Run npm command dev it will start dev script for all the services and packages

    npm run dev

Using kubernetes (minikube)

  • Start minikube

    minikube start
  • Get minikube ip and add it to hosts minikube ip to get the IP then edit the /etc/hosts files and add <minikube ip> <ingress host>

    minikube ip
    192.168.49.2  microservices.test
  • Run skaffold command dev it will run the skaffold in dev mode

    skaffold dev -f ./infra/skaffold.yaml --tail=true

Test project

  • Setup the project
  • create a jwt token jwt.io, with sub and isAdmin object in the payload, or use dummy jwt in test-jwt.json
  • call the apis with bearer token in the header

Apis

/api/keys (key-management)

  • POST (isAdmin should be true)
  • GET
  • PATCH
  • DELETE

/api/tokens (web3-token)

  • GET (access-key as key generated from /api/keys in the req headers)

Project structure

  • Infra: All infrastructure as code (IaC)

  • Services: All the microservices directory

    • key-management (microservice 1): generate keys with some meta data like rateLimit, expiration ...
    • web3-token (microservice 2): get token information using the rateLimit and key info generated by key-management
  • Packages: Common code used by Services

    • auth: Auth middleware get the tokens, decodes it and append it in req object.
    • config: General config used by Services
    • error: Common Error Exception class
    • events: Events Object used in Services

TODO

  • unit test
  • Integration test