Welcome to the π¦ Microservices Suite project! This suite is a collection of Node.js microservices built using the 𦧠mono-repo strategy and leveraging the yarn workspaces concept. Each microservice runs in its isolated Docker container
, and Kubernetes
orchestrates the deployment, providing scalability and efficiency.
To easily work with a @microservices-suite monorepo
you need to install Suite CLI. With Suite
you can easily scaffold,manage and automate your monorepo in development, CI as well as production. Check the installation guidelines in the README.md
section of the .suite-cli
root.
.
βββ CHANGELOG.md
βββ CODE_OF_CONDUCT.md
βββ CONTRIBUTING.md
βββ LICENSE
βββ README.md
βββ docker
βΒ Β βββ README.md
βΒ Β βββ apps
βΒ Β βββ nyati
βΒ Β βββ docker-compose.dev.yml
βΒ Β βββ docker-compose.yml
βΒ Β βββ krakend
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ krakend.json
βΒ Β βββ nginx
βΒ Β βββ Dockerfile
βΒ Β βββ Dockerfile.dev
βΒ Β βββ default.conf
βββ graphql
βΒ Β βββ nyati-app
βΒ Β βββ appollo-server.yml
βββ k8s
βΒ Β βββ README.md
βΒ Β βββ broker
βΒ Β βΒ Β βββ clusterIp.yaml
βΒ Β βΒ Β βββ deployment.yaml
βΒ Β βΒ Β βββ loadBalancer.yaml
βΒ Β βΒ Β βββ nodePort.yaml
βΒ Β βββ ingress
βΒ Β βΒ Β βββ ingress.yaml
βΒ Β βββ ns
βΒ Β βββ default
βΒ Β βββ nyati
βΒ Β βββ combo.yaml
βΒ Β βββ payment
βΒ Β βββ configMap.yaml
βΒ Β βββ db
βΒ Β βΒ Β βββ clusterIp.yaml
βΒ Β βΒ Β βββ deployment.yaml
βΒ Β βΒ Β βββ loadBalancer.yaml
βΒ Β βΒ Β βββ nodePort.yaml
βΒ Β βββ secret.yaml
βΒ Β βββ server
βΒ Β βββ clusterIp.yaml
βΒ Β βββ deployment.yaml
βΒ Β βββ loadBalancer.yaml
βΒ Β βββ nodePort.yaml
βββ microservices
βΒ Β βββ payment
βΒ Β βββ Dockerfile.dev
βΒ Β βββ ecosystem.config.js
βΒ Β βββ index.js
βΒ Β βββ package.json
βΒ Β βββ src
βΒ Β βββ controllers
βΒ Β βΒ Β βββ controllers.js
βΒ Β βΒ Β βββ index.js
βΒ Β βββ models
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ models.js
βΒ Β βββ routes
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ routes.js
βΒ Β βββ services
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ services.js
βΒ Β βββ subscriber
βΒ Β βββ index.js
βΒ Β βββ subscriber.js
βββ package.json
βββ production.yml
βββ shared
βΒ Β βββ README.md
βΒ Β βββ broker
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ package.json
βΒ Β βΒ Β βββ rabbitmq
βΒ Β βΒ Β βββ exchange.js
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ publisher.js
βΒ Β βΒ Β βββ subscriber.js
βΒ Β βΒ Β βββ worker.queue.js
βΒ Β βββ config
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ config.js
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ logger.js
βΒ Β βΒ Β βββ morgan.js
βΒ Β βΒ Β βββ package.json
βΒ Β βββ constants
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ package.json
βΒ Β βββ errors
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ errors.handler.js
βΒ Β βΒ Β βββ index.js
βΒ Β βΒ Β βββ package.json
βΒ Β βββ middlewares
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ package.json
βΒ Β βββ utilities
βΒ Β βββ APIError.js
βΒ Β βββ README.md
βΒ Β βββ asyncErrorHandler.js
βΒ Β βββ index.js
βΒ Β βββ package.json
βΒ Β βββ pick.js
βΒ Β βββ validate.js
βββ suite.config
βββ suite.docker
βββ suite.html
βββ suite.json
βββ suite.k8s
βββ suite.ms
βββ tests
βββ README.md
βββ cli
βββ scripts
βββ retrieveWorkspaceName.test.js
36 directories, 84 files
-
Enforce DRY Principles:
- @Japheth Obala the Prophet π has done a sleek job demystifying πSOLID & best practice here.
- Collocating code encourages code sharing.
- Reduce duplication πread about SOLID here
- Save time by building on existing boilerplate or reusable functionality.
-
Collaboration:
- Working within the same repository facilitates learning from peers.
- Enables the adoption of good coding practices and the avoidance of bad ones.
-
Centralized Development Chores:
- Manage common files like
.gitignore
centrally from the root directory - Reduce unnecessary repetitions in the codebase.
- Manage common files like
-
Easily Integrate Development Automation:
- Task runner configurations and docker-compose can be managed from the root directory.
- simplify the automation of repetitive workflows.
-
Code Sharing Anywhere:
- Publish and import organization-scoped libraries from the npm registry with
yarn release
yarn add <@microservices-suite/foo>
yarn workspace @microservices-suite/<workspace-name> add @microservices-suite/<library>
- Using
Suite CLI
you could achieve the results with the following commands
suite release
suite add <@microservices-suite/foo>
suite -W <workspace-name> add @microservices-suite/<library>
- Easily Containerize and Scale:
- Decouple every microservice to scale individually.
- Leverage the no-hoist yarn workspace feature and custom scripts to enable efficient packaging of microservices into isolated containers.
-
Yarn Workspaces:
- Simplifies managing multiple packages within a single repository.
- Encourage code sharing & reduce duplication
- Make it easier to handle dependencies and scripts.
-
Docker Containers:
- Provides lightweight, portable, and self-sufficient containers for packaging and deploying microservices.
- Alpine images are very minimalistic Linux minidistros that cost you only
~5MB
of real estate. That is why they are used inside your favouritesmart watch βοΈ
. - One objective of this project is to
optimize image builds for Continuous Integration (CI)
andproduction
environments through the utilization of the slimmest possible images so that you dont bloatβ οΈ your machine in dev and we have a lean server in prod.
-
Multi-Stage Builds:
- We employ simple Docker constructs like
multi-stage builds
to optimize our image size.
- We employ simple Docker constructs like
-
Hoisting and Symlinking:
- While these practices promote the
DRY
(Don't Repeat Yourself) principle, they pose a threat to our objective of achieving minimized images. To mitigate this, we leverageno-hoisting and symlinked libraries
- selectively copying only the
node_modules
generated bynon-hoisted workspaces
. - These are optimized to consume less disk space, ensuring that only the essential shared libraries required by a specific service are included, thereby maintaining the slim profile of our images.
- The service itself will build her core node modules normally inside the dockerfile from her
package.json
- While these practices promote the
- For an in-depth guide and best practices on using Docker with Node.js, visit the Docker & Node Best Practices repository.
- Kubernetes offers automated deployment, scaling, and management of containerized applications, ensuring reliability and scalability.
Welcome to our project! To ensure a smooth setup and development experience, ensure you have the following tools installed on your machine:
- Docker:
- For containerization and managing containerized applications.
- π Install docker here.
- We love π alpine images <small,simple,secure>.
- You can read about the specific flavor here
- Suite CLI:
- For easy project scaffolding task automation and workflow management.
- Install
suite
: check the installation guidelines below.
- Node.js:
- As the runtime environment for executing the application code.
- π Download LTS version here
- At the project <service_root> create
.env
,.env.dev
and.env.staging
files and copyenvironment variables
from the.env.example
file
- A
component
in oursuite
jargon refers to aservice
orapplication
. With@microservices-suite
you can create 1 or more services as well as applications. - Suite is
component-scoped
, giour strategy that enhances modularity and at the same time makes using the monorepo intuitive. Its is inspired bySingle Responsibility
principle. - Apps are simply
cohessive
microservicesaggregated
under the./gateway/apps/
directory to create decoupled services to serve your client. An example is anEcommerce app
. This app can havecustomer, supplier,orders and products
microservices under the./microservices/
directory. These microservices are then referenced indocker-compose
file definitions placed under the./gateway/apps/ecommerce-app/
directory. Other apps can be added to the./gateway/apps
directory with theirdocker-compose
definitions andapi-gateway configs(nginx/appache)
. - Suite scales applications with
kubernetes
and app-scopedk8s
configs are located under the./k8s/
directory. Therefore the kubernetes configurations for our Ecommerce app will be located at./k8s/ecommerce-app
- Suite CLI streamlines the process of starting a service(s) or app(s) in
development
&production
. Follow these steps to get your environment up and running: - You can derive the
service_name
orapp-name
from the workspace name found in thepackage.json "name":
property e.g
"name": "@microservices-suite/<component-name>"
- To run an app in either modes [dev,staging,prod]:
- If -k or --kubectl flag is specified
suite
spins your app withkubectl
. You need to have minikube installed and kubectl. Otherwise defaults to docker compose - If -m or --mode is specified you need to have a
docker-compose.<mode>
specified but this is not necessary with kubectl since we only run the development version of kubectl.
suite start [--kubectl,--mode]|[-km] <mode> <app-name...>
- This command uses docker-compose to start your app(s)
- Suite will handle the setup, ensuring your app is ready.
- If you prefer not to use Docker, you can use the
-v,--vanilla
command to start service(s) using nodePM2
engine in production ornodemon
in any other mode:
suite start [--vanilla,--mode]|[-vm] <mode> <service_name...>
- Should you need to use docker-compose directly for more control over the container orchestration, you can utilize the standard commands provided by Docker:
- You can replace the yml files with your compose file path and production.yml has been used as an overide. There are many ways to kill the cat in dockers world π.
docker-compose -f docker-compose.yml -f production.yml up --build -d
docker-compose down
Contributions are welcome! If you'd like to contribute to the Microservices Suite project, please follow these guidelines:
- Fork the repository and clone it to your local machine.
git clone https://github.com/microservices-suite/node-microservices-suite.git
- Create a new branch for your feature or bug fix:
git checkout -b feat/<my-feature>
-
Make your changes and make sure that tests pass.
-
Before committing your changes, make sure it follows the conventional commits specification:
- We recommend you use the Better Commits CLI tool. It is a CLI for writing better commits, following the conventional commits specification.
-
Push to the branch:
git push origin feat/<my-feature>
-
Submit a pull request detailing your changes.
-
Please ensure that your pull request adheres to the project's code style and conventions.
- This project is licensed under the MIT License. Feel free to use, modify, and distribute this code for any purpose.
We would like to thank the developers and contributors to the following technologies used in this project:
- Yarn
- Yarn workspace.
- Also checkout yarn workspaces
- No-hoist
- βοΈ Docker
- π‘ Kubernetes
- Curated Resouces(by [email protected])
- π Read Book by Sam Newman
- π³οΈ containerization, orchestration & CICD
- π¦ microservices
- 𦧠Monorepos
- π Monorepo is not code collocation
- π Read Medium article here
- For design patterns,best practice and DSA checkout this sheet on the Resources sheet