Skip to content

Gateway Service API

🌐

The API Gateway REST service built with Java, Spring Boot, and PostgreSQL. Routes requests to microservices, enforces security policies, provides rate limiting, and aggregates responses.


Features

Feature Description Icon
Request Routing Route requests to appropriate microservices πŸ”€
Authentication OAuth2, JWT, and OIDC authentication πŸ”
Rate Limiting Protect services with rate limiting policies ⏱️
Request/Response Logging Comprehensive logging for audit and debugging πŸ“
Circuit Breaker Fail gracefully with circuit breaker pattern πŸ”Œ
Request Transformation Modify headers, parameters, and payload πŸ”„
Multi-Tenant Support Route requests based on tenant context 🏒

Architecture Overview

flowchart TD
    A[Client] -->|HTTP/REST| B(GatewayController)
    B --> C[AuthenticationFilter]
    C --> D[RateLimitFilter]
    D --> E[RoutingService]
    E --> F[ServiceRegistry]
    E --> G[CircuitBreaker]
    G --> H[Microservices]
    B --> I[AuditLogger]
Hold "Alt" / "Option" to enable pan & zoom

API Endpoints

Note: Real API endpoints to be provided and included here.

Method Endpoint Description Notes/Parameters
POST /api/v1/auth/login Authenticate user Username, password
POST /api/v1/auth/refresh Refresh access token Refresh token
POST /api/v1/routes Create route rule Service name, path pattern
GET /api/v1/health/services Check all services health

Sequence: Route and Authenticate Request

sequenceDiagram
    participant U as User
    participant G as Gateway
    participant A as AuthFilter
    participant R as RateLimitFilter
    participant S as RoutingService
    participant MS as Microservice
    U->>G: GET /api/v1/resource (Authorization header)
    G->>A: extract token
    A->>A: validate JWT
    A-->>G: token valid
    G->>R: check rate limit
    R-->>G: within limits
    G->>S: route to service
    S->>MS: forward request
    MS-->>S: response
    S-->>G: response
    G-->>U: 200 OK + data
Hold "Alt" / "Option" to enable pan & zoom

Database Schema

erDiagram
    route_rules {
        UUID id PK
        VARCHAR service_name
        VARCHAR path_pattern
        VARCHAR request_method
        VARCHAR target_url
        BOOLEAN enabled
        INTEGER priority
        TIMESTAMP created
        TIMESTAMP updated
    }

    rate_limit_policies {
        UUID id PK
        VARCHAR service_name
        VARCHAR limit_key
        INTEGER request_limit
        INTEGER window_seconds
        TIMESTAMP created
        TIMESTAMP updated
    }

    audit_logs {
        UUID id PK
        VARCHAR user_id
        VARCHAR endpoint
        VARCHAR method
        VARCHAR status_code
        TIMESTAMP timestamp
        TEXT user_agent
        VARCHAR ip_address
    }

    authentication_tokens {
        UUID id PK
        VARCHAR user_id
        VARCHAR token
        VARCHAR token_type
        TIMESTAMP expires_at
        TIMESTAMP created
    }
Hold "Alt" / "Option" to enable pan & zoom

Getting Started

Prerequisites

  • Java 17+
  • PostgreSQL
  • Gradle

Setup

git clone https://github.com/Olanna-tech/gateway-service-java.git
cd gateway-service-java
./gradlew build

Database

  • Configure your PostgreSQL credentials in src/main/resources/application.yml.
  • Run Flyway migrations (auto on startup).

Run

./gradlew bootRun

Configuration

Set the following environment variables in application.yml:

gateway:
  port: 8080
  auth-enabled: true
  jwt-secret: your-secret-key
  rate-limit-enabled: true
  circuit-breaker-enabled: true
  request-timeout-seconds: 30


Contributing

Pull requests are welcome! For major changes, please open an issue first.


License

MIT


Contact