Skip to content

rohitsoni007/express-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Architecture

A Node.js-based microservices architecture with API Gateway and authentication service.

🏗️ Architecture Overview

This project implements a microservices architecture with the following components:

  • API Gateway: Entry point for all client requests, handles routing and request forwarding
  • Auth Service: Handles user authentication, authorization, and JWT token management

📁 Project Structure

microservice/
├── gateway/                 # API Gateway service
│   ├── src/
│   │   └── index.js        # Gateway main entry point
│   ├── .env                # Gateway environment variables
│   └── package.json        # Gateway dependencies
│
├── auth-service/           # Authentication service
│   ├── src/
│   │   └── server.js       # Auth service entry point
│   ├── .env                # Auth service environment variables
│   └── package.json        # Auth service dependencies
│
├── .gitignore
└── README.md

🚀 Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB (for auth-service)

Installation

  1. Clone the repository:
git clone <repository-url>
cd microservice
  1. Install dependencies for each service:

Gateway Service:

cd gateway
npm install

Auth Service:

cd auth-service
npm install

Configuration

Each service requires environment variables. Create .env files in each service directory:

Gateway (.env):

PORT=3000
AUTH_SERVICE_URL=http://localhost:3001

Auth Service (.env):

PORT=3001
MONGODB_URI=mongodb://localhost:27017/auth-db
JWT_SECRET=your-secret-key

🎯 Running the Services

Development Mode

Run each service in development mode with hot-reload:

Gateway:

cd gateway
npm run dev

Auth Service:

cd auth-service
npm run dev

Production Mode

Gateway:

cd gateway
npm start

Auth Service:

cd auth-service
npm start

🛠️ Technologies Used

Gateway

  • Express.js
  • http-proxy-middleware
  • dotenv

Auth Service

  • Express.js
  • MongoDB with Mongoose
  • JWT (jsonwebtoken)
  • bcryptjs
  • dotenv

📝 API Documentation

Gateway

  • Main entry point: http://localhost:3000
  • Routes requests to appropriate microservices

Auth Service

  • Base URL: http://localhost:3001
  • Endpoints:
    • POST /register - User registration
    • POST /login - User authentication
    • GET /verify - Token verification

🔒 Security

  • JWT-based authentication
  • Password hashing with bcryptjs
  • Environment variables for sensitive data
  • Token-based authorization

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License.

📧 Contact

For questions or support, please open an issue in the repository.

About

Node.js Express Microservices Starter Project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors