# spring-cloud/spring-cloud-openfeign architecture

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

- Interactive diagram: https://gitdiagram.com/spring-cloud/spring-cloud-openfeign
- Repository: https://github.com/spring-cloud/spring-cloud-openfeign

## Overview

##### Project Type and Purpose
- This is a library (with starter and dependency management modules) that allows developers to define HTTP clients via annotated interfaces.
- It integrates tightly with Spring and improves how remote REST calls are handled, while abstracting away much of the boilerplate.

##### File Structure
- Look at the top-level directories:
- "spring-cloud-openfeign-core": Contains the main implementation of the library, including key interfaces, dynamic proxies, encoding/decoding modules, and integration with Spring context.
- "spring-cloud-openfeign-dependencies": Provides dependency management (likely using a BOM) for version control and consistent dependency resolution.
- "spring-cloud-starter-openfeign": The Spring Boot starter module that simplifies integrating OpenFeign into Spring-based applications.
- "docs" - contains Antora and AsciiDoc sources for project documentation.
- Maven wrappers, configuration files, and CI configuration indicate standard Java/Maven project practices.
- Numerous packages in the core module that pertain to:
- Annotation processing (e.g., for @FeignClient and other Spring MVC annotations).
- Dynamic client implementation creation (e.g., DefaultTargeter, FeignClientFactoryBean).
- Encoders/decoders, logging, load balancing, and circuit breaker support.
- Additional integrations for features such as compression, security (OAuth2), and alternative HTTP client configurations.

##### Extract Insights from the README
- It confirms the project’s nature as a feature-complete library for creating declarative REST clients.
- Mentions integration with Spring Cloud and Spring Boot (via the "starter" module) and that it’s built using Maven.
- It also mentions that only bug fixes or minor community features are being added as the project is considered feature complete.

a. Modules/Components:
- Core Library (spring-cloud-openfeign-core):
– Contains the core logic for creating dynamic implementations of REST interfaces.
– Handles annotation processing, dynamic proxy generation, and client configuration.
– Manages encoding/decoding of requests and responses (supporting gzip, form writers, etc.).
– Implements integration with load balancers, circuit breakers, logging, and security features.
- Starter Module (spring-cloud-starter-openfeign):
– Provides auto-configuration for Spring Boot applications.
– Simplifies integration by automatically creating beans based on Feign annotations.
- Dependency Management (spring-cloud-openfeign-dependencies):
– Defines and manages the set of dependencies and versions that work together.
b. Relationships and Interactions:
- The Starter Module acts as a bridge between the Spring Framework and the Core Library. It triggers auto-configuration, reads annotations (e.g., @FeignClient), and instantiates client implementations.
- The Core Library uses dynamic proxies to intercept method calls on client interfaces and translates these into REST calls.
- Encoders, Decoders, and Interceptors within the core module take care of the transformation of data to/from HTTP payloads.
- Support modules (circuit breaker, load balancer, logging, and security) interact with the core to enhance functionality and resiliency.
c. Architectural Patterns & Design Principles:
- Declarative client proxy pattern: Interfaces are dynamically implemented.
- Layered design: Separation between client interface, dynamic proxy implementation, and low-level HTTP client invocation.
- Modularity: Distinct modules for core functionality, Spring Boot auto-configuration, and dependency management enable flexibility and extensibility.
- Integration with Spring through auto-configuration and dependency injection.
d. Technologies, Frameworks, and Libraries:
- Java 17, Maven, and Spring Framework (including Spring Boot).
- HTTP client integrations (such as OkHttp, Apache HttpClient, or HTTP/2 clients through conditional configuration).
- Integration support for logging, circuit breakers, and load balancing (as indicated by specific classes in the clientconfig and loadbalancer packages).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Dev["Developer's FeignClient Interface"]:::external
    REST["External REST Service"]:::external

    %% Core Module Subgraph
    subgraph "Core Module (spring-cloud-openfeign-core)"
        AN["Annotation Processing"]:::core
        DP["Dynamic Proxy Implementation"]:::core
        ED["Encoder/Decoder & Interceptors"]:::core
        RI["Resiliency Integration (Circuit Breaker, Load Balancer, Logging, Security)"]:::core
        HE["HTTP Request Execution"]:::core
    end

    %% Starter Module Subgraph
    subgraph "Starter Module (spring-cloud-starter-openfeign)"
        AC["Spring Boot Auto-Configuration"]:::starter
    end

    %% Dependency Management Subgraph
    subgraph "Dependency Management (spring-cloud-openfeign-dependencies)"
        BOM["BOM & Dependency Control"]:::dependency
    end

    %% Documentation & CI Subgraph
    subgraph "Documentation & CI"
        DOC["Antora/AsciiDoc (docs)"]:::doc
        CI["CI Workflows (.github/workflows)"]:::doc
    end

    %% Relationships
    Dev -->|"defines annotatedInterface"| AN
    AN -->|"creates"| DP
    DP -->|"invokes"| HE
    DP -->|"triggers"| ED
    DP -->|"triggers"| RI
    ED -->|"pre/post processes"| HE
    RI -->|"wraps around"| HE
    HE -->|"HTTP calls"| REST
    
    %% Starter interactions with Core
    AC -->|"auto-configures"| AN
    AC -->|"auto-configures"| DP
    AC -->|"auto-configures"| ED
    AC -->|"auto-configures"| RI

    %% Dependency influences Core & Starter
    BOM --- AN
    BOM --- DP
    BOM --- ED
    BOM --- RI
    AC --- BOM

    %% Documentation & CI relation to Starter configuration
    DOC --- AC
    CI --- AC

    %% Click Events for Component Mappings
    click AN "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-core"
    click DP "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-core"
    click ED "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-core"
    click RI "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-core"
    click HE "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-core"
    click AC "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-starter-openfeign"
    click BOM "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/spring-cloud-openfeign-dependencies"
    click DOC "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/docs"
    click CI "https://github.com/spring-cloud/spring-cloud-openfeign/tree/main/.github/workflows"

    %% Styling
    classDef core fill:#f9f,stroke:#333,stroke-width:2px;
    classDef starter fill:#cff,stroke:#333,stroke-width:2px;
    classDef dependency fill:#fcf,stroke:#333,stroke-width:2px;
    classDef doc fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9,stroke:#333,stroke-width:2px;
```
