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.
Strict separation: Domain β Application β Infrastructure
Choose an active provider via config:
provider:
active: gsbSupports unlimited providers:
sandboxgsbastan- future custom providersβ¦
NationalId(with algorithm validation)BirthDate- Domain rules live in domain β not in controllers or services.
Domain & Application have zero Spring annotations β highly testable & reusable.
REST API, provider wiring, configs, outgoing adapters.
Ideal for government, banking, fintech, telecom, and any system needing multi-provider routing.
.
βββ 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)
Controller β UseCase β ProviderPort β ProviderAdapter β External System
- 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)
The router chooses the provider based on:
application.yml:
provider:
active: sandbox # or gsb / astan / your-custom-providerAdd your provider configs like:
providers:
gsb:
url: https://example.com/apimvn clean installUsing IntelliJ or:
cd rip-government-infrastructure
mvn spring-boot:runhttp://localhost:8080/swagger-ui.html
{
"nationalId": "0025235141",
"birthDate": "13810903"
}{
"match": true,
"firstName": "Ali",
"lastName": "Ahmadi",
"fatherName": "Reza",
"birthDate": "13810903"
}- 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)
The router receives all provider beans:
Map<String, CivilRegistryProviderPort> providersThen selects:
providers.get(activeProvider)This makes adding new providers as simple as:
- Creating a new Adapter class
- Marking it with
@Service("providerName") - Updating config:
provider.active: providerNameDone β no core change.
- π Provider fallback + chain of responsibility
- π§΅ Async & non-blocking providers
- π gRPC providers
- π OpenTelemetry tracing
- π‘ Circuit breaker per provider
- π§© Multi-provider aggregation strategy
- π API security module
PRs, forks, suggestions, and feature requests are warmly welcomed.