An open API service indexing awesome lists of open source software.

https://github.com/jawherkl/nodejs-microservices

Scalable and modular microservices system ready for production built with Node.js, PostgreSQL, MongoDB, RabbitMQ and Docker.
https://github.com/jawherkl/nodejs-microservices

expressjs mongodb nestjs nodejs postgresql rabbitmq swagger-ui

Last synced: 3 months ago
JSON representation

Scalable and modular microservices system ready for production built with Node.js, PostgreSQL, MongoDB, RabbitMQ and Docker.

Awesome Lists containing this project

README

          

# ๐Ÿ›’ NodeJS Microservices: Order & Inventory System

![Repository Size](https://img.shields.io/github/repo-size/JawherKl/nodejs-microservices)
![Last Commit](https://img.shields.io/github/last-commit/JawherKl/nodejs-microservices)
![Issues](https://img.shields.io/github/issues-raw/JawherKl/nodejs-microservices)
![Forks](https://img.shields.io/github/forks/JawherKl/nodejs-microservices)
![Stars](https://img.shields.io/github/stars/JawherKl/nodejs-microservices)

Scalable and modular microservices architecture built with Node.js (NestJS & ExpressJS), PostgreSQL, MongoDB and Docker. It leverages RabbitMQ for event-driven communication, ideal for modern e-commerce and real-time systems.

![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white)
![NestJS](https://img.shields.io/badge/nestjs-E0234E?style=for-the-badge&logo=nestjs&logoColor=white)
![ExpressJS](https://img.shields.io/badge/express.js-000000?style=for-the-badge&logo=express&logoColor=white)
![PostgreSQL](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white)
![MongoDB](https://img.shields.io/badge/mongodb-4EA94B?style=for-the-badge&logo=mongodb&logoColor=white)
![RabbitMQ](https://img.shields.io/badge/rabbitmq-FF6600?style=for-the-badge&logo=rabbitmq&logoColor=white)
![Docker](https://img.shields.io/badge/docker-2496ED?style=for-the-badge&logo=docker&logoColor=white)

---

nodejs-microservice

## โœจ Overview

This project demonstrates a modern microservices architecture for an Order & Inventory System, suitable for real-world companies. Each service is designed with a single responsibility, clear separation, and scalable technologies.

- **Tech Focus:** TypeScript-first, RESTful APIs, event-driven messaging, containerised infrastructure
- **Monorepo:** All services managed together for easy orchestration and development
- **Best Practices:** Security, scalability, and maintainability in mind

---

## ๐Ÿ—๏ธ Architecture

```mermaid
graph TB
%% Application Layer
subgraph "Application Layer"
agw[API Gateway]
us[User Service
NestJS]
ps[Product Service
ExpressJS]
os[Order Service
NestJS]
isvc[Inventory Service
ExpressJS]
ns[Notification Service
ExpressJS]
end

%% Database Layer
subgraph "Database Layer"
pg[(PostgreSQL)]
mongo[(MongoDB)]
end

%% Messaging Layer
subgraph "Messaging"
rmq[[RabbitMQ
Message Broker]]
end

%% Dependencies and Connections
agw -->|REST| us
agw -->|REST| ps
agw -->|REST| os
agw -->|REST| isvc
agw -->|REST| ns

us -- "DATABASE_URL" --> pg
os -- "DATABASE_URL" --> pg
ps -- "mongodb://..." --> mongo
isvc -- "mongodb://..." --> mongo
ns -- "mongodb://..." --> mongo

us -- "RABBITMQ_URL" --> rmq
os -- "RABBITMQ_URL" --> rmq
isvc -- "RABBITMQ_URL" --> rmq
ns -- "RABBITMQ_URL" --> rmq

%% Messaging Events
rmq -- "Events" --> os
rmq -- "Events" --> isvc
rmq -- "Events" --> ns

%% External Ports Exposure
agw -->|":3000"| extgw[External Access]
us -->|":3001"| extus[External Access]
ps -->|":3002"| extps[External Access]
os -->|":3003"| extos[External Access]
isvc -->|":3004"| extis[External Access]
ns -->|":3005"| extns[External Access]
pg -->|":9091"| extpg[External Access]
mongo -->|":9092"| extmongo[External Access]
rmq -->|":9093/9094"| extrmq[External Access]

%% Class Styling
classDef app fill:#2ecc71,stroke:#27ae60,color:white
classDef db fill:#3498db,stroke:#2980b9,color:white
classDef msg fill:#e67e22,stroke:#d35400,color:white
classDef ext fill:#95a5a6,stroke:#7f8c8d,color:white

class agw,us,ps,os,isvc,ns app
class pg,mongo db
class rmq msg
class extgw,extus,extps,extos,extis,extns,extpg,extmongo,extrmq ext
```

| Microservice | Tech Stack | DB | Responsibility |
| ------------------------ | ---------------- | ---------- | ----------------------------------------------- |
| **User Service** | NestJS | PostgreSQL | User registration, login, authentication, roles |
| **Product Service** | ExpressJS | MongoDB | Product CRUD (create, update, list, delete) |
| **Order Service** | NestJS | PostgreSQL | Order creation, validation, and processing |
| **Inventory Service** | ExpressJS | MongoDB | Stock tracking, update on orders |
| **Notification Service** | ExpressJS | MongoDB | Email/log notifications on events |
| **API Gateway** | ExpressJS/NestJS | - | Unified API entry, routing, token verification |
| **Message Broker** | RabbitMQ | - | Inter-service event bus |

---

## ๐Ÿ“ Project Structure

```bash
nodejs-microservices/
โ”œโ”€โ”€ api-gateway/ # API Gateway (routing, auth)
โ”œโ”€โ”€ user-service/ # User microservice
โ”œโ”€โ”€ product-service/ # Product microservice
โ”œโ”€โ”€ order-service/ # Order microservice
โ”œโ”€โ”€ inventory-service/ # Inventory microservice
โ”œโ”€โ”€ notification-service/ # Notification microservice
โ”œโ”€โ”€ docker-compose.yml # Infrastructure orchestration
โ”œโ”€โ”€ docs/ # Architecture diagrams, docs
โ”œโ”€โ”€ README.md
```

---

## ๐Ÿ”— Communication

* **API Gateway โ‡„ Services:** REST (HTTP)
* **Between Services:** Messaging (RabbitMQ)

* `OrderService` emits `order_created`
* `InventoryService` listens and adjusts stock
* `NotificationService` listens and sends notification

---

## ๐Ÿš€ Features

### ๐Ÿ‘ค User Service

* Secure sign up & login
* JWT authentication
* Role-based access (admin/user)

### ๐Ÿ›๏ธ Product Service

* Create/list/delete products
* Fetch by product ID
* Simple MongoDB schema

### ๐Ÿ›’ Order Service

* Place new orders
* Validate users & product stock
* Emits `order_created` event

### ๐Ÿฌ Inventory Service

* Listens to `order_created`
* Decreases stock or rejects if insufficient

### ๐Ÿ“ข Notification Service

* Listens to events (`order_created`, etc)
* Sends notification (email/log)

### ๐ŸŒ API Gateway

* One entry point for frontend
* Reverse proxy, JWT verification
* Routes `/products`, `/orders`, `/users` to services

---

## ๐Ÿณ Dockerized Infrastructure

Powered by `docker-compose.yml`:

* All microservices (with build contexts)
* MongoDB, PostgreSQL databases
* RabbitMQ for messaging
* Optional admin UIs: pgAdmin, Mongo Express, RabbitMQ dashboard

### ๐Ÿงช Docker Network & Setup

Before starting the app, **create the Docker network**:

```bash
docker network create \
--driver=bridge \
--subnet=172.21.0.0/24 \
nodejs_network
```

Then run the entire system:

```bash
sudo docker-compose up --build -d
```

All services will be available on their respective internal IP addresses and ports, or via the API Gateway.

---

## ๐Ÿ›ฃ๏ธ Roadmap

* [ ] Add OpenAPI/Swagger docs for each service
* [ ] Service discovery and dynamic routing
* [ ] Production-ready monitoring & logging
* [ ] Integration with frontend (React/Angular)
* [ ] Advanced notification channels (SMS, Push)
* [ ] Create CI/CD Pipeline with GitHub Actions

---

## ๐Ÿค Contributing

We welcome contributions, ideas, and feedback.
Feel free to open issues or submit pull requests.

---

## ๐Ÿ“œ License

MIT License. See [LICENSE](LICENSE) for details.

---

## ๐Ÿ‘จโ€๐Ÿ’ป Author

**Jawher Kallel**
[GitHub @JawherKl](https://github.com/JawherKl)

---

Made with โค๏ธ for scalable, real-world systems.

## ๐ŸŒŸ Stargazers over time

[![Stargazers over time](https://starchart.cc/JawherKl/nodejs-microservices.svg?variant=adaptive)](https://starchart.cc/JawherKl/nodejs-microservices)