A Node.js-based microservices architecture with API Gateway and authentication service.
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
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
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (for auth-service)
- Clone the repository:
git clone <repository-url>
cd microservice- Install dependencies for each service:
Gateway Service:
cd gateway
npm installAuth Service:
cd auth-service
npm installEach service requires environment variables. Create .env files in each service directory:
Gateway (.env):
PORT=3000
AUTH_SERVICE_URL=http://localhost:3001Auth Service (.env):
PORT=3001
MONGODB_URI=mongodb://localhost:27017/auth-db
JWT_SECRET=your-secret-keyRun each service in development mode with hot-reload:
Gateway:
cd gateway
npm run devAuth Service:
cd auth-service
npm run devGateway:
cd gateway
npm startAuth Service:
cd auth-service
npm start- Express.js
- http-proxy-middleware
- dotenv
- Express.js
- MongoDB with Mongoose
- JWT (jsonwebtoken)
- bcryptjs
- dotenv
- Main entry point:
http://localhost:3000 - Routes requests to appropriate microservices
- Base URL:
http://localhost:3001 - Endpoints:
POST /register- User registrationPOST /login- User authenticationGET /verify- Token verification
- JWT-based authentication
- Password hashing with bcryptjs
- Environment variables for sensitive data
- Token-based authorization
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
For questions or support, please open an issue in the repository.