Monorepo Microservices using nestjs kafka and docker, k8s
To get a local copy up and running, please follow these simple steps.
Here is what you need.
- Node.js (Version: >= 20.x)
- docker, docker-compose (if not using k8s) (Version: >= 26.x, 2.x)
- minikube (Version >= v1.33.1)
- minikube ingress addon
- skaffold (Version >= v2.10.0)
- helm (Version >= v3.14.3)
-
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
-
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
- Duplicate
-
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 packagesnpm run dev
-
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 modeskaffold dev -f ./infra/skaffold.yaml --tail=true
- Setup the project
- create a jwt token jwt.io, with
sub
andisAdmin
object in the payload, or use dummy jwt intest-jwt.json
- call the apis with bearer token in the header
- POST (isAdmin should be true)
- GET
- PATCH
- DELETE
- GET (access-key as key generated from /api/keys in the req headers)
-
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
- unit test
- Integration test