Skip to content

Demo project showing how to convert a Node.js monolithic app into a scalable microservices architecture with API Gateway and independent services.

Notifications You must be signed in to change notification settings

suryathink/nodejs-monolith-to-microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Monolith to Microservices

A demo project to demonstrate how to convert a Node.js monolithic application into a microservices architecture. This project is structured to help beginners understand the concepts of microservices, service isolation, and API gateways.


🚀 Project Structure

nodejs-monolith-to-microservices/
 ├── api-gateway/
 │    ├── src/
 │    └── package.json
 ├── services/
 │    ├── user-service/
 │    │    ├── src/
 │    │    └── package.json
 │    ├── order-service/
 │    │    ├── src/
 │    │    └── package.json
 │    └── product-service/
 │         ├── src/
 │         └── package.json
 ├── shared/
 │    ├── db/
 │    └── utils/
 ├── docker-compose.yml
 └── README.md

💾 Features

  • Independent services: Each microservice (User, Order, Product) runs independently.
  • API Gateway: Routes client requests to the appropriate service.
  • Database isolation: Each service can have its own database.
  • Scalable architecture: Microservices allow independent scaling and development.
  • CORS & JSON parsing configured in each service.

🛠 Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • MongoDB / PostgreSQL (per service)
  • Docker & Docker Compose
  • CORS

⚡ Getting Started

1. Clone the repository

git clone https://github.com/yourusername/nodejs-monolith-to-microservices.git
cd nodejs-monolith-to-microservices

2. Install dependencies for root (for dev tools)

npm install

3. Run services individually

For example, to run the user service:

cd services/user-service
npm install
npm run dev

Then the API will be available at: http://localhost:3001

4. Run API Gateway

cd api-gateway
npm install
npm run dev

Requests to http://localhost:3000/api/users will be forwarded to the user service.


📌 API Endpoints

Health Check

GET /health

Response:

{
  "status": "user service is up and running"
}

User Registration

POST /api/users/register

Body:

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}

🔗 Roadmap

  • Convert user module to microservice
  • Convert order module to microservice
  • Convert product module to microservice
  • Add message queue (RabbitMQ / Kafka) for async communication
  • Add service discovery (optional)
  • Dockerize all services

📖 References


👤 Author

Surya Singh


⭐ License

MIT

About

Demo project showing how to convert a Node.js monolithic app into a scalable microservices architecture with API Gateway and independent services.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published