Skip to content

Repository files navigation

🛒 NodeJS Microservices: Order & Inventory System

Repository SizeLast CommitIssuesForksStars

A modular, production-ready microservices system inspired by e-commerce architectures, built with TypeScript, Node.js, NestJS, ExpressJS, PostgreSQL, MongoDB, Docker, and RabbitMQ/NATS for event-driven communication.

NodeJSNestJSExpressJSPostgreSQLMongoDBRabbitMQDocker


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 single responsibility, clear separation, and scalable technologies.

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

🏗️ Architecture

graph TB
%% Application Layer
subgraph "Application Layer"
agw[API Gateway]
us[User Service<br/>NestJS]
ps[Product Service<br/>ExpressJS]
os[Order Service<br/>NestJS]
isvc[Inventory Service<br/>ExpressJS]
ns[Notification Service<br/>ExpressJS]
end
%% Database Layer
subgraph "Database Layer"
pg[(PostgreSQL)]
mongo[(MongoDB)]
end
%% Messaging Layer
subgraph "Messaging"
rmq[[RabbitMQ<br/>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
Loading
MicroserviceTech StackDBResponsibility
User ServiceNestJSPostgreSQLUser registration, login, authentication, roles
Product ServiceExpressJSMongoDBProduct CRUD (create, update, list, delete)
Order ServiceNestJSPostgreSQLOrder creation, validation, and processing
Inventory ServiceExpressJSMongoDBStock tracking, update on orders
Notification ServiceExpressJSMongoDBEmail/log notifications on events
API GatewayExpressJS/NestJS-Unified API entry, routing, token verification
Message BrokerRabbitMQ/NATS-Inter-service event bus

📁 Project Structure

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/NATS)
    • 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 entrypoint 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 or NATS for messaging
  • Optional admin UIs: pgAdmin, Mongo Express, RabbitMQ dashboard
docker-compose up --build

🛣️ 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)

🤝 Contributing

Contributions, ideas, and feedback are welcome!
Feel free to open issues or submit pull requests.


📜 License

MIT License. See LICENSE for details.


👨‍💻 Author

Jawher Kallel
GitHub @JawherKl


Made with ❤️ for scalable, real-world systems.

About

A modular production ready microservices system inspired by e-commerce architectures.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages