Olara Gateway Service (Java)
Welcome to the Olara Gateway Service! This project serves as the API gateway for the Olara platform, handling routing, authentication, authorization, and service discovery for all backend microservices.
Table of Contents
- Project Overview
- Features
- Architecture
- Technologies Used
- Configuration
- Running the Service
- API Gateway Routing
- Security & Auth
- Logging & Troubleshooting
- Contributing
- License
- Support
π Project Overview
The gateway acts as a single entry point for all client requests, forwarding them to the appropriate backend services. It enforces security, manages cross-cutting concerns, and simplifies client interactions with the microservices architecture.
β¨ Features
- Dynamic Routing via
routes.json - JWT Authentication & Role-based Authorization (Keycloak integration)
- Tenant-aware Routing
- Service Discovery (Eureka)
- Resilience (Circuit Breaker, Retry, Rate Limiting via Resilience4j)
- Centralized Logging (Loki, Spring Logging)
- Swagger API Docs Proxying (Gateway exposes and proxies Swagger/OpenAPI docs from backend services at
/swagger/{service})
ποΈ Architecture
+---------+ +-------------------+ +-------------------+
| Client | ---> | Gateway Service | ---> | Microservices |
+---------+ +-------------------+ +-------------------+
| |
| +-- user-service
| +-- order-service
| +-- payment-service
| +-- wallet-service
| +-- stockmarket-service
| +-- kyc-service
|
+-- Eureka Discovery
+-- Keycloak Auth
π οΈ Technologies Used
- Java 17+
- Spring Cloud Gateway
- Spring Security (OAuth2, JWT)
- Keycloak
- Eureka (Service Discovery)
- Resilience4j
- Loki (Logging)
- Gradle
βοΈ Configuration
Environment Files
application.yml(base)application-local.yml(local dev)application-uat.yml(UAT)
Route Configuration
- All routes are defined in
src/main/resources/routes.json - Each route specifies:
paths: URL patternsuri: Target serviceroles,permissions: Access controlrequiresTenantId,requiresRoles,isAuthenticated: Security flags
Keycloak
- Used for authentication and role-based access
- Configured via
application-*.ymlfiles - JWT tokens are validated for protected routes
πββοΈ Running the Service
Prerequisites
- Java 17+
- Gradle
- Docker (for running dependencies like Keycloak, Eureka, Loki)
Local Development
- Clone the repo:
git clone https://github.com/olara-tech/gateway-service-java.git cd gateway-service-java - Start dependencies:
docker-compose -f docker-compose-uat.yml up -d - Run the gateway:
./gradlew bootRun --args='--spring.profiles.active=local'
UAT/Production
- Set environment variables and use
application-uat.yml. - Deploy with Docker or your preferred orchestrator.
π API Gateway Routing
- All requests are matched against
routes.json. - Example route:
{ "routeId": "user-service-customer", "paths": ["/api/v1/profile/**"], "uri": "lb://user-service", "isAuthenticated": true } - The gateway enforces authentication and forwards the request to the correct service.
Swagger API Docs Proxying
- The gateway exposes and proxies Swagger/OpenAPI documentation endpoints from backend services.
- Access Swagger docs for a service via:
For example,
GET /swagger/{service}/swagger/user-serviceproxies the Swagger UI or OpenAPI docs from theuser-servicebackend. - This allows you to view and interact with the API documentation for each microservice through a unified gateway endpoint.
- The proxying logic is handled in the gateway routing configuration and/or filter classes (see
GatewayRouterandGatewayFilterFactory).
π Security & Auth
- JWT tokens are required for most routes (see
isAuthenticatedinroutes.json). - Role and tenant checks are enforced as configured.
- Keycloak is the identity provider.
π Logging & Troubleshooting
- Logs are output to console and can be shipped to Loki.
- Log level can be set in
application-*.yml(e.g.,com.olara.gatewayservice: DEBUGfor verbose logs). - For troubleshooting route issues:
- Check logs for route matching and header extraction.
- Ensure your JWT contains required claims (tenantId, userId).
- Review
routes.jsonfor correct path and security settings.
π€ Contributing
- Fork the repo
- Create your feature branch (
git checkout -b feature/your-feature) - Commit your changes
- Push to the branch
- Open a Pull Request
π License
This project is licensed under the MIT License. See LICENSE for details.
π Support
For questions or support, please open an issue or contact the Olara Tech team.