# bhanafee/retryhttp architecture

> Architecture diagram of the GitHub repository bhanafee/retryhttp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhanafee/retryhttp
- Repository: https://github.com/bhanafee/retryhttp

## Overview

##### Project type and purpose
- This is a Java/Gradle extension library for Resilience4j that adds HTTP-aware retry logic based on status codes and `Retry-After` headers for `jakarta.servlet.http.HttpServletResponse`.
- It is not a standalone server or full-stack app but a drop-in resilience extension that client applications wire into their HTTP request pipelines.

##### File structure
- Top-level: Gradle build files (`build.gradle`, `settings.gradle`), GitHub CI configs, LICENSE, README.
- src/main/java/com/maybeitssquid/retry:
- `RetryAfterParser` – parses `Retry-After` header into a `Duration`
- `RetryStatusCodes` – defines which HTTP status codes warrant a retry
- `LimitRetryAfter` – predicate to block excessively long waits
- src/main/java/com/maybeitssquid/retry/resilience4j:
- `HeedRetryAfter` – an `IntervalBiFunction` that adjusts wait intervals according to parsed header
- `Retry` – factory methods that wire predicates + bulkhead functions into Resilience4j RetryConfig
- src/test mirrors production packages for unit tests.

##### README for additional insights
- The library provides two main capabilities:
a. Predicates for status-code-based retry decisions (idempotent vs non-idempotent)
b. Parsing & honoring of `Retry-After` headers via predicates and interval functions
- Integration points are through Resilience4j interfaces: `Predicate<HttpServletResponse>` and `IntervalBiFunction<Duration, Integer>`.

1. Client Application – issues HTTP calls
2. Resilience4j Core – provides Retry pattern interfaces
3. HTTP-Aware Retry Library
- Core Predicates (RetryStatusCodes, LimitRetryAfter)
- Header Parser (RetryAfterParser)
- Resilience4j Integration (HeedRetryAfter, Retry)
4. External HTTP Service – the target of requests
- Client App → Resilience4j Retry (configured via `Retry.of(...)` using our library’s `Retry.createIdempotent(...)` or similar)
- Resilience4j Retry wraps the HTTP request execution
- On each response, Retry core invokes our Predicate<HttpServletResponse>
- Predicate calls `RetryStatusCodes` for code check
- If a `Retry-After` header is present, Predicate defers to `LimitRetryAfter` + `RetryAfterParser`
- If header indicates a wait, `HeedRetryAfter` computes the delay and passes it to Resilience4j scheduler
- After backoff, Resilience4j retries the HTTP call → External HTTP Service
c. Architectural patterns & principles
- Decorator/Adapter: wrapping Resilience4j’s RetryConfig with HTTP-specific behavior
- Single Responsibility: separate modules for parsing, code-based logic, integration
- Open/Closed: users can supply custom clock or extended parser variations without modifying core logic
d. Key technologies & libs
- Java 17+ (Gradle build)
- Resilience4j core interfaces (`Retry`, `IntervalBiFunction`)
- Jakarta Servlet API (`HttpServletResponse`)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Application
    ClientApp["Client Application"]:::client

    %% Resilience4j Core
    Resilience4jCore["Resilience4j Core\n(interface Retry, IntervalBiFunction)"]:::external

    %% HTTP-Aware Retry Library
    subgraph "HTTP-Aware Retry Library"
        direction TB
        subgraph "com.maybeitssquid.retry"
            direction TB
            RetryStatusCodes["RetryStatusCodes\n(predicate logic)"]:::library
            RetryAfterParser["RetryAfterParser\n(parses Retry-After header)"]:::library
            LimitRetryAfter["LimitRetryAfter\n(block long waits)"]:::library
        end
        subgraph "com.maybeitssquid.retry.resilience4j"
            direction TB
            HeedRetryAfter["HeedRetryAfter\n(IntervalBiFunction)"]:::library
            RetryFactory["Retry\n(factory methods)"]:::library
        end
    end

    %% External HTTP Service
    HTTPService["External HTTP Service"]:::service

    %% Relationships
    ClientApp -->|"calls RetryFactory.createIdempotent()\n(config injection)"| RetryFactory
    RetryFactory -.->|"uses Predicate<HttpServletResponse>"| RetryStatusCodes
    RetryFactory -.->|"uses Predicate<HttpServletResponse>"| LimitRetryAfter
    RetryFactory -.->|"uses IntervalBiFunction" | HeedRetryAfter
    RetryFactory -->|"builds RetryConfig"| Resilience4jCore
    Resilience4jCore -->|"executes HTTP call"| HTTPService
    HTTPService -->|"HTTP response"| Resilience4jCore
    Resilience4jCore -->|"evaluates Predicate\n(HttpServletResponse)"| RetryStatusCodes
    Resilience4jCore -->|"evaluates Predicate\n(HttpServletResponse)"| LimitRetryAfter
    Resilience4jCore -->|"extracts header & defers\ninterval to HeedRetryAfter"| RetryAfterParser
    RetryAfterParser -->|"provides Duration"| HeedRetryAfter

    %% Click events
    click RetryStatusCodes "https://github.com/bhanafee/retryhttp/blob/main/src/main/java/com/maybeitssquid/retry/RetryStatusCodes.java"
    click RetryAfterParser "https://github.com/bhanafee/retryhttp/blob/main/src/main/java/com/maybeitssquid/retry/RetryAfterParser.java"
    click LimitRetryAfter "https://github.com/bhanafee/retryhttp/blob/main/src/main/java/com/maybeitssquid/retry/LimitRetryAfter.java"
    click HeedRetryAfter "https://github.com/bhanafee/retryhttp/blob/main/src/main/java/com/maybeitssquid/retry/resilience4j/HeedRetryAfter.java"
    click RetryFactory "https://github.com/bhanafee/retryhttp/blob/main/src/main/java/com/maybeitssquid/retry/resilience4j/Retry.java"

    %% Styles
    classDef library fill:#E0F7FA,stroke:#006064,color:#000;
    classDef external fill:#ECEFF1,stroke:#78909C,color:#000;
    classDef client fill:#C8E6C9,stroke:#388E3C,color:#000;
    classDef service fill:#FFE0B2,stroke:#EF6C00,color:#000;
```
