Skip to content

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

  1. Project Overview
  2. Features
  3. Architecture
  4. Technologies Used
  5. Configuration
  6. Running the Service
  7. API Gateway Routing
  8. Security & Auth
  9. Logging & Troubleshooting
  10. Contributing
  11. License
  12. 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 patterns
  • uri: Target service
  • roles, permissions: Access control
  • requiresTenantId, requiresRoles, isAuthenticated: Security flags

Keycloak

  • Used for authentication and role-based access
  • Configured via application-*.yml files
  • JWT tokens are validated for protected routes

πŸƒβ€β™‚οΈ Running the Service

Prerequisites

  • Java 17+
  • Gradle
  • Docker (for running dependencies like Keycloak, Eureka, Loki)

Local Development

  1. Clone the repo:
    git clone https://github.com/olara-tech/gateway-service-java.git
    cd gateway-service-java
    
  2. Start dependencies:
    docker-compose -f docker-compose-uat.yml up -d
    
  3. 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:
    GET /swagger/{service}
    
    For example, /swagger/user-service proxies the Swagger UI or OpenAPI docs from the user-service backend.
  • 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 GatewayRouter and GatewayFilterFactory).

πŸ”’ Security & Auth

  • JWT tokens are required for most routes (see isAuthenticated in routes.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: DEBUG for verbose logs).
  • For troubleshooting route issues:
  • Check logs for route matching and header extraction.
  • Ensure your JWT contains required claims (tenantId, userId).
  • Review routes.json for correct path and security settings.

🀝 Contributing

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit your changes
  4. Push to the branch
  5. 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.