# fabiolb/fabio architecture

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

- Interactive diagram: https://gitdiagram.com/fabiolb/fabio
- Repository: https://github.com/fabiolb/fabio

## Overview

##### Main Components Identification
- Load Balancer/Router Core:
- The actual request routing logic lives in several packages (e.g., proxy, route, trace, transport). The file tree shows many proxy-related packages that handle HTTP, TCP, websockets, and TLS, and even specific logic like gzip handling.
- Service Discovery Integration:
- The registry section (with subdirectories for consul, custom, file, and static) indicates how fabio fetches service registration data from Consul and possibly other sources.
- Administration Interface:
- The admin folder (with subdirectories for API and UI) contains the components which give users a web UI and API for managing routes and getting status.
- Configuration and Certificate Management:
- The config and cert directories show that fabio supports dynamic configurations, certificate stores, and even integration with Vault for TLS certificate management.
- Metrics and Logging:
- The metrics and logger directories show support for collecting, formatting, and exporting application metrics and logs. Various metrics providers (including Prometheus, DogStatsD) are present.
- Additional Modules:
- Other functional parts include the auth package (handling authentication logic) and bgp (for BGP anycast address advertisements on non-Windows platforms).

##### Relationships and Interactions
- Client Traffic Flow:
- External client requests (HTTP(S) or TCP) arrive at the load balancing component.
- The proxy modules (HTTP, TCP, WS) determine the route based on request attributes.
- Service Discovery:
- The registry sub-system continually pulls data from Consul (or alternative registries) to build/update the routing table.
- Administrative and Monitoring Layers:
- The admin API/UI components serve monitoring, management, and manual override functions. They show status, routes, and metrics.
- Certificate and Security:
- The certificate management components are invoked when dynamic TLS termination is needed. They integrate with sources like file, HTTP, or Vault.
- Metrics and Logging:
- Throughout the flow, logger and metrics services capture performance, error logs, and operational data. The metrics provider interfaces with Prometheus, Graphite, DogStatsD, etc.
- BGP Module:
- Optionally, the bgp component advertises anycast addresses when enabled, representing an external broadcast layer.

##### Architectural Patterns & Design Principles
- Modular and Layered Architecture:
- The code is split into separate packages each responsible for a distinct functionality (e.g., proxying, service registry, configuration), encouraging separation of concerns.
- Dynamic Configuration & Routing:
- The design supports hot reloading and dynamic configuration changes without restarts.
- Integration with External Systems:
- The registry (especially with Consul) and certificate management point to a design meant for integration in microservices environments.
- Extensibility:
- Additional backends (metrics, custom registries, different certificate sources) are supported, indicating that the system was built with plug-in architecture in mind.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    client_requests["Client Requests"]:::client
    client_requests ---|sends traffic| router_core["fabio Router & Load Balancer Core"]:::core

    %% Routing Core -> Subsystems
    router_core ---> service_registry["Consul & Service Registry"]:::registry
    router_core ---> admin_subgraph[Administration API/UI]:::admin
    router_core ---> config_subgraph[Configuration & Certificate Management]:::config
    router_core ---> metrics_logging[Metrics & Logging]:::metrics
    router_core ---> auth_module["Authentication Module"]:::module
    router_core ---> bgp_module["BGP/Anycast Module"]:::module

    %% Feedback Loop
    service_registry --->|updatesRoutingTable| router_core

    %% Administration Subgraph
    subgraph "Administration API/UI"
        admin_api["Admin API"]:::admin
        admin_ui["Admin UI"]:::admin
        admin_api --- admin_ui
    end

    %% Configuration and Certificate Management Subgraph
    subgraph "Configuration & Certificate Management"
        config_mgmt["Configuration"]:::config
        certificate_store["Certificate Store"]:::config
        config_mgmt --- certificate_store
    end

    %% Metrics and Logging Subgraph
    subgraph "Metrics & Logging"
        metrics_service["Metrics Service"]:::metrics
        logging_service["Logging Service"]:::metrics
        metrics_service --- logging_service
    end

    %% Key Principles Annotation
    principles["DynamicReloading\nZero-confServiceDiscovery\nExtensiblePluginArchitecture"]:::note

    %% Link the principles to the core for emphasis
    router_core --- principles

    %% Click Events
    click router_core "https://github.com/fabiolb/fabio/tree/master/proxy"
    click service_registry "https://github.com/fabiolb/fabio/tree/master/registry/consul"
    click admin_api "https://github.com/fabiolb/fabio/tree/master/admin/api"
    click admin_ui "https://github.com/fabiolb/fabio/tree/master/admin/ui"
    click config_mgmt "https://github.com/fabiolb/fabio/tree/master/config"
    click certificate_store "https://github.com/fabiolb/fabio/tree/master/cert"
    click metrics_service "https://github.com/fabiolb/fabio/tree/master/metrics"
    click logging_service "https://github.com/fabiolb/fabio/tree/master/logger"
    click auth_module "https://github.com/fabiolb/fabio/tree/master/auth"
    click bgp_module "https://github.com/fabiolb/fabio/tree/master/bgp"

    %% Styles
    classDef client fill:#E6E6FA,stroke:#000,stroke-width:1px;
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef registry fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef admin fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef config fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef metrics fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef module fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef note fill:#F5F5F5,stroke:#808080,stroke-dasharray: 5 5,stroke-width:1px;
```
