Skip to content

GavinRuff007/adaptive-service-router

Repository files navigation


🌐 Adaptive Service Router

A Clean Architecture–Driven, Pluggable Integration Layer for Multi-Provider Systems


πŸš€ Overview

Adaptive Service Router is a modular, high-performance integration layer built using Clean Architecture, Hexagonal Design, and provider-based routing.

It enables any application to dynamically select external service providers at runtime β€” without modifying business logic.

You simply define domain rules, use cases, and provider adapters, and this framework handles the routing, orchestration, and abstraction.


✨ Key Features

πŸ”Ή Clean Architecture from the ground up

Strict separation: Domain β†’ Application β†’ Infrastructure

πŸ”Ή Provider Routing

Choose an active provider via config:

provider:
  active: gsb

Supports unlimited providers:

  • sandbox
  • gsb
  • astan
  • future custom providers…

πŸ”Ή Domain-Driven Value Objects

  • NationalId (with algorithm validation)
  • BirthDate
  • Domain rules live in domain β€” not in controllers or services.

πŸ”Ή Framework-Independent Core

Domain & Application have zero Spring annotations β†’ highly testable & reusable.

πŸ”Ή Infrastructure with Spring Boot

REST API, provider wiring, configs, outgoing adapters.

πŸ”Ή Extensible for enterprise integrations

Ideal for government, banking, fintech, telecom, and any system needing multi-provider routing.


🧩 Architecture

.
β”œβ”€β”€ rip-government-domain
β”‚   β”œβ”€β”€ entity
β”‚   β”œβ”€β”€ valueobject
β”‚   β”œβ”€β”€ exception
β”‚   └── Domain rules only
β”‚
β”œβ”€β”€ rip-government-application
β”‚   β”œβ”€β”€ port
β”‚   β”‚   β”œβ”€β”€ input  (Use Cases)
β”‚   β”‚   └── output (Provider interfaces)
β”‚   └── service (Business logic)
β”‚
β”œβ”€β”€ rip-government-infrastructure
β”‚   β”œβ”€β”€ api (Controllers)
β”‚   β”œβ”€β”€ adapter (External provider adapters)
β”‚   β”œβ”€β”€ config (Routing & Spring beans)
β”‚   └── GovernmentServiceApplication.java
└── pom.xml (root)

🧠 High-level flow

Controller β†’ UseCase β†’ ProviderPort β†’ ProviderAdapter β†’ External System

πŸ›  Tech Stack

  • Java 21
  • Spring Boot 3.4+
  • Spring Web MVC
  • Clean Architecture principles
  • DDD Value Objects
  • MapStruct (optional mapping)
  • OpenAPI / Swagger UI
  • Resilience4j (optional future use)

βš™οΈ Configuration

The router chooses the provider based on:

application.yml:

provider:
  active: sandbox  # or gsb / astan / your-custom-provider

Add your provider configs like:

providers:
  gsb:
    url: https://example.com/api

🚦 Running the Project

1️⃣ Install all modules

mvn clean install

2️⃣ Run the service

Using IntelliJ or:

cd rip-government-infrastructure
mvn spring-boot:run

3️⃣ Access Swagger UI

http://localhost:8080/swagger-ui.html

πŸ“‘ Example API Request

POST /api/v1/identity/inquiry

Request body:

{
  "nationalId": "0025235141",
  "birthDate": "13810903"
}

Sample response:

{
  "match": true,
  "firstName": "Ali",
  "lastName": "Ahmadi",
  "fatherName": "Reza",
  "birthDate": "13810903"
}

πŸ§ͺ Testing Strategy

  • Domain tests β†’ validate NationalId algorithm, BirthDate rules
  • UseCase tests β†’ mock output ports
  • Adapter tests β†’ HTTP mocking (WireMock recommended)
  • Integration tests β†’ Spring Boot + Testcontainers (future enhancement)

πŸ“‘ Provider Routing Logic

The router receives all provider beans:

Map<String, CivilRegistryProviderPort> providers

Then selects:

providers.get(activeProvider)

This makes adding new providers as simple as:

  1. Creating a new Adapter class
  2. Marking it with @Service("providerName")
  3. Updating config:
provider.active: providerName

Done β€” no core change.


πŸ› οΈ Future Enhancements

  • πŸ”„ Provider fallback + chain of responsibility
  • 🧡 Async & non-blocking providers
  • πŸ”Œ gRPC providers
  • πŸ“Š OpenTelemetry tracing
  • πŸ›‘ Circuit breaker per provider
  • 🧩 Multi-provider aggregation strategy
  • πŸ” API security module

🀝 Contributions

PRs, forks, suggestions, and feature requests are warmly welcomed.


⭐ If you like this architecture, consider giving the repository a star!


About

Adaptive Service Router is a high-performance, pluggable integration layer designed to route incoming service requests across multiple external providers using Clean Architecture, Hexagonal boundaries, and config-driven runtime selection.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors