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.
ββ node-microservices-suite
β ββ api-gateways/
| β ββ app-1/
| β β ββ nginx
| β β ββ apache
| β β ββ README.md
β ββ graphql/
| β ββ app-1/
| β β ββ apollo-server # placeholder file atm
| β β ββ README.md
β ββ data-persistence/
| β ββ db-1/
| β β ββ Dockerfile
| β β ββ README.md
| β ββ sqlite/ #for in memory or disk db for miniature devices or prototyping
| β ββ ββ db/
| β β ββ README.md
β ββ k8s/
| β ββ service-1/
| β β ββ cluster-ip-service.yml
| β β ββ cluster-deployment.yml
| β β ββ ingress-service.yml
| β β ββ README.md
| ββ microservices/
| β ββ service-1/
| β β ββ src
| β β ββ .env
| β β ββ .env.dev
| β β ββ app.js
| β β ββ Dockerfile
ββ β β ββ Dockerfile.dev
| β β ββ ecosystem.config.js
| β β ββ index.js
| β β ββ package.json
| β β ββ task.json
| ββ shared/
| β ββ library-1/
| β β ββ APIError.js
| β β ββ catchAsync.js
| β β ββ index.js
| β β ββ package.json
| β β ββ pick.js
| β β ββ README.md
| β β ββ validate
β ββ tests/
| β ββ service-1/
| β β ββ e2e/
| β β ββ integration/
| β β ββ snapshot/ #if it's a micro-frontend service
| β β ββ unit/
| β β ββ README.md
| ββ .gitignore
| ββ .npmrc
| ββ .yarnrc.yml
| ββ docker-compose.yml
| ββ package.json
| ββ production.yml
| ββ README.md
| ββ Taskfile.yml
| ββ yarn.lock
-
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 to the npm registry with
yarn publish
yarn add <@microservices-suite/foo> or
yarn @microservices-suite/<workspace-name> add <@microservices-suite/foo>
- 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
- Task Runner Automation Tool:
- For task automation and workflow management.
- π Install task runner here.
- 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
- This project uses Task Runner Automation Tool to streamline the process of starting services in both development and production. Follow these steps to get your environment up and running:
- You can derive the
service_name
of a service from the workspace name found in thepackage.json "name":
property e.g
"name": "@microservices-suite/<service_name>"
- To run a service in either modes [dev,staging,prod]:
- Action is similar to [up,down] docker compose syntax where
up
&down
start
andstop
theservice
respectively withdocker-compose <action>
task do:<service_name>:<mode>:<action>
- This command uses docker-compose to start your service(s)
- The task runner will handle the setup, ensuring your service is ready.
- If you prefer not to use Docker, you can use the
vanilla
task command to start services using nodePM2
engine in production ornodemon
in any other mode:
task vanilla:<service_name>:<mode>
- Should you need to use docker-compose directly for more control over the container orchestration, you can utilize the standard commands provided by Docker:
docker-compose up
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.
- Commit your changes using the Angular commit message convention:
- For more details, please refer to the Angular commit message convention.
- 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 gilbertandanje@gmail.com)
- π 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