A robust and scalable Gateway service designed to manage, secure, and route traffic across multiple microservices in an e-commerce ecosystem. This service acts as the central entry point for all client requests, handling authentication, session management, rate limiting, and intelligent load balancing via service discovery.
The API Gateway is a high-performance Go-based service that streamlines communication between external clients and internal microservices. It integrates seamlessly with Eureka for service discovery and uses Redis for high-speed caching and rate limiting, ensuring the platform remains responsive and secure under load.
- Languge: Go (1.21+)
- Router: Gorilla Mux
- Database: PostgreSQL (via GORM)
- Caching & Rate Limiting: Redis
- Service Discovery: Netflix Eureka (via Fargo)
- Security: JWT (JSON Web Tokens) with Session Management
- Infrastructure: Docker
- Centralized Authentication: OAuth2-style flows with Access and Refresh tokens.
- Microservices Proxying: Dynamic routing to Products, Orders, and Chat services.
- Service Discovery: Automatic registration and heartbeat monitoring with Eureka.
- Session Management: Robust session handling with revocation and renewal capabilities.
- Performance: Integrated caching layer and rate limiting to protect downstream services.
- Observability: Structured logging and centralized error handling for all proxied requests.
The Gateway provides a unified API surface under the /api prefix.
| Endpoint | Method | Description |
|---|---|---|
/api/auth/signin |
POST |
Register a new user account with profile details. |
/api/auth/login |
POST |
Authenticate credentials and receive a JWT Access & Refresh token. |
/api/auth/logout |
POST |
Terminate the current session (requires id query parameter). |
/api/tokens/renew |
POST |
Use a valid Refresh Token to generate a new Access Token. |
/api/tokens/revoke |
POST |
Revoke a specific session by its ID (requires id query parameter). |
| Endpoint | Method | Description |
|---|---|---|
/api/health |
GET |
Health check endpoint to verify the Gateway's operational status. |
All requests to the following paths are automatically proxied to their respective backend services. These routes require a valid JWT token.
- Endpoint:
/api/products/* - Proxy Target:
PRODUCTS-SERVICE - Supported Methods:
GET,POST,PUT,DELETE - Features: Rate limiting, Caching, Authentication
- Endpoint:
/api/orders/* - Proxy Target:
ORDERS-SERVICE - Supported Methods:
GET,POST,PUT,DELETE - Features: Rate limiting, Caching, Authentication
- Endpoint:
/api/chat/* - Proxy Target:
CHAT-CLIENT-SERVICE - Supported Methods:
GET,POST,PUT,DELETE - Features: Rate limiting, Caching, Authentication
- Endpoint:
/api/generate/* - Proxy Target:
CHAT-CLIENT-SERVICE(AI Implementation) - Supported Methods:
GET,POST,PUT,DELETE - Features: Rate limiting, Caching, Authentication
- Go installed on your local machine.
- Docker and Docker Compose (recommended for local infrastructure).
- A running Eureka Server for service discovery.
- Ensure your database and Redis instances are reachable.
- Initialize the service:
go mod download
- Run the application:
go run main.go
docker pull risbernfernandes/micro-ecomm-api-gateway:latest.
├── handler/ # HTTP Handlers & Request/Response Logic
├── internal/ # Core Logic (Database, Cache, Token Maker, Middleware)
├── model/ # GORM Models & Database Operations
├── routes/ # Router Definitions & Proxy Logic
├── util/ # Helper functions (Hashing, etc.)
└── main.go # Application Entry PointDesigned with ❤️ for High-Scale E-Commerce.