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.
- Host: GitHub
- URL: https://github.com/jawherkl/nodejs-microservices
- Owner: JawherKl
- Created: 2025-06-16T14:31:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-16T16:30:03.000Z (5 months ago)
- Last Synced: 2026-01-17T05:22:40.278Z (5 months ago)
- Topics: expressjs, mongodb, nestjs, nodejs, postgresql, rabbitmq, swagger-ui
- Language: TypeScript
- Homepage: https://medium.com/@jawherkl/nodejs-microservices-product-order-inventory-system-3fc868ab3417
- Size: 1.06 MB
- Stars: 41
- Watchers: 1
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ NodeJS Microservices: Order & Inventory System





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.







---

## โจ 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
[](https://starchart.cc/JawherKl/nodejs-microservices)