This project demonstrates a cloud-native microservice architecture featuring a custom-built API Gateway (Node.js/Express.js), Nginx for load balancing, JWT-based security, and Prometheus/Grafana for monitoring. The system is fully containerized using Docker and Docker Compose.
- Custom API Gateway (Node.js/Express.js):
- Centralized request routing, JWT authentication, rate limiting, and CORS.
- Nginx Reverse Proxy/Load Balancer:
- System entry point, distributes load to API Gateway instances.
- Microservices (Node.js/Express.js):
user-service: User management & authentication (PostgreSQL).product-service: Product catalog management (MongoDB).order-service: Order processing (MongoDB).
- Database per Service Principle: Ensures data isolation and independent scalability.
- Containerization: Docker & Docker Compose for consistent environments and orchestration.
- Monitoring: Prometheus for metrics collection, Grafana for visualization.
- Backend & API Gateway: Node.js, Express.js
- Load Balancer: Nginx
- Databases: PostgreSQL, MongoDB
- Authentication: JSON Web Tokens (JWT)
- Containerization: Docker, Docker Compose
- Monitoring: Prometheus, Grafana
Client requests are routed through Nginx to a custom API Gateway. The Gateway handles authentication and other cross-cutting concerns before forwarding requests to the appropriate backend microservice. Each service has its dedicated database. Prometheus scrapes metrics, visualized in Grafana.
- Docker Desktop (with Docker Engine and Docker Compose) installed.
- Git.
-
Clone the repository:
git clone https://github.com/your-username/api-gateway-project.git cd api-gateway-project -
Environment Configuration:
- Create a
.envfile in theuser-service/directory. Example:# user-service/.env DB_HOST=user-db DB_NAME=app_user_db DB_USER=appuser DB_PASSWORD=apppassword JWT_SECRET=your_strong_jwt_secret_for_user_service # Ensure this is secure PORT=3001
- Ensure the
jwtSecretinapi-gateway/config/gateway.config.jsonis securely set and consistent with how tokens are managed/verified. - Review and adjust database credentials or ports in
docker-compose.ymlif necessary.
- Create a
-
Build and Run with Docker Compose:
docker-compose up --build -d
(The
-dflag runs containers in detached mode.) -
Accessing Endpoints:
- API Gateway (via Nginx):
http://localhost:8080- Example Health Check (if configured):
GET http://localhost:8080/api/health
- Example Health Check (if configured):
- Grafana Dashboard:
http://localhost:3000(Default: admin/admin) - Prometheus UI:
http://localhost:9090
- API Gateway (via Nginx):
-
Example API Interactions (via API Gateway):
- Register User:
POST http://localhost:8080/users/register{ "username": "testuser", "email": "test@example.com", "password": "securePassword123" } - Login:
POST http://localhost:8080/users/login{ "email": "test@example.com", "password": "securePassword123" } - Get Products (Requires JWT):
GET http://localhost:8080/products(Include JWT inAuthorization: Bearer <token>header)
- Register User:
-
Viewing Container Logs:
# View logs for a specific service docker-compose logs -f api-gateway # View logs for all services docker-compose logs -f
-
Stopping the Application:
docker-compose down
(This stops and removes containers, networks, and optionally volumes if specified.)
.
├── api-gateway/ # Custom Express.js API Gateway
│ ├── config/ # Gateway and route configurations
│ └── middleware/ # Custom middleware (auth, rate limiting, etc.)
├── user-service/ # User management microservice
├── product-service/ # Product catalog microservice
├── order-service/ # Order processing microservice
├── monitoring/ # Prometheus and Grafana configurations
├── docker-compose.yml # Docker Compose orchestration file
├── nginx.conf # Nginx configuration for load balancing
└── README.md
