# umputun/reproxy architecture

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

- Interactive diagram: https://gitdiagram.com/umputun/reproxy
- Repository: https://github.com/umputun/reproxy

## Overview

1. **What this repo is**
   Reproxy is a single Go binary that acts as an edge HTTP(S) reverse proxy and optional static file server. It is designed around **route discovery**: one or more providers continuously supply routing rules, and the proxy layer uses those rules to handle requests.

2. **Top-level runtime shape**
   The main process lives in `app/main.go`. From there, the binary wires together:
   - provider discovery,
   - the proxy server,
   - optional HTTPS/ACME termination,
   - optional management API,
   - optional plugin RPC support.
   The same binary can run as a standalone host process or in a Docker container.

3. **Core routing boundary**
   The `app/discovery` package is the normalization layer between sources of truth and the proxy. It aggregates rules from providers into a common route model. The proxy itself does not care whether a rule came from command-line flags, a YAML file, Docker labels, or Consul tags.

4. **Provider subsystem**
   Provider implementations live under `app/discovery/provider`:
   - `static.go` for CLI/env-defined routes,
   - `file.go` for YAML-based dynamic config,
   - `docker.go` for Docker discovery,
   - `consulcatalog/` for Consul Catalog discovery.
   These are dynamic sources where applicable: file changes, container changes, or Consul polling can update routing without restarting the binary.

5. **External discovery dependencies**
   Two providers integrate with external systems:
   - **Docker provider** talks to the Docker API/socket to discover running containers and read `reproxy.*` labels.
   - **Consul Catalog provider** polls the Consul HTTP API for services tagged with `reproxy.` metadata.
   These are the main external control-plane dependencies in the architecture.

6. **Request handling path**
   The `app/proxy` package is the main data-plane. Requests come in through the public listener, are matched against discovered routes, and then either:
   - proxied to an upstream destination,
   - served from the assets server,
   - redirected,
   - or rejected with an error response.
   The proxy layer also applies header mutation, access control, auth, size limits, and timeouts.

7. **Static assets as a parallel serving path**
   The proxy can also function as a file server. Assets handling is integrated into the proxy package rather than being a separate service. It supports:
   - a global assets root,
   - provider-defined asset routes,
   - SPA fallback behavior,
   - cache control and custom not-found pages.
   This is an alternate response path that bypasses upstream proxying.

8. **Traffic policy and route behavior**
   Several cross-cutting policies are enforced in the proxy layer:
   - per-route and global basic auth,
   - IP allowlisting,
   - request/response header sanitation,
   - gzip compression,
   - request size limits,
   - per-route and global throttling,
   - per-route timeouts,
   - redirect rules.
   These are all applied after route match, before or during upstream forwarding.

9. **Upstream resilience and load balancing**
   The proxy includes live health-checking and failover/load-balancing logic. Route targets can have ping URLs, health checks can be forwarded or handled locally, and load balancing can choose among multiple healthy destinations. This makes the upstream selection part of the routing pipeline, not an external responsibility.

10. **TLS/SSL termination**
    HTTPS is handled inside the same process via the proxy/SSL layer. The binary supports:
    - static certificates,
    - ACME/Let’s Encrypt automation,
    - HTTP-01 and DNS-01 challenge flows,
    - multiple DNS provider integrations for DNS-01.
    This means TLS termination is part of the edge gateway boundary, not delegated to another front proxy.

11. **Management plane**
    The `app/mgmt` package exposes a separate management listener. It serves:
    - `/routes` for discovered route inventory,
    - `/metrics` for Prometheus metrics.
    This is a distinct control/observability plane from the main proxy listener, and it is optional.

12. **Plugin extension boundary**
    The `app/plugin` package and `lib/` directory define an RPC-based plugin system. External plugin processes register with the main binary and participate in the request middleware chain, returning header mutations and status decisions. This is the repo’s extensibility boundary for custom behavior.

13. **Operational packaging**
    The repo is built for multiple delivery formats:
    - a single binary,
    - Docker images,
    - release artifacts via GoReleaser,
    - systemd service support.
    The `Dockerfile`, `Dockerfile.site`, release/workflow configs, and scripts indicate that production deployment is a first-class concern.

14. **Examples and documentation as architecture references**
    The `examples/` tree provides runnable configurations for the main modes: file provider, Docker discovery, static assets, SSL, metrics, and plugins. The docs and completed design notes under `docs/` capture behavioral decisions like per-route timeout/throttle and security-related fixes.

15. **How to diagram it**
    A good architecture diagram should show:
    - external users hitting the main proxy listener,
    - separate management listener for routes/metrics,
    - provider sources feeding a route aggregation layer,
    - the proxy engine applying policy and routing,
    - optional assets serving path,
    - optional plugin RPC sidecar/processes,
    - upstream backends as destinations,
    - and external control-plane services like Docker API, Consul API, and ACME/DNS providers.

Main entry points: [`app/proxy/proxy.go`](https://github.com/umputun/reproxy/blob/master/app/proxy/proxy.go) (Proxy), [`app/discovery/discovery.go`](https://github.com/umputun/reproxy/blob/master/app/discovery/discovery.go) (Discovery), [`app/main.go`](https://github.com/umputun/reproxy/blob/master/app/main.go) (Main), [`app/plugin/conductor.go`](https://github.com/umputun/reproxy/blob/master/app/plugin/conductor.go) (Plugins)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_app_main["Main<br/>Go entrypoint<br/>[main.go]"]
  node_mgmt["Mgmt API<br/>control server<br/>[server.go]"]
  node_plugin["Plugins<br/>rpc middleware<br/>[conductor.go]"]
  node_lib["Plugin RPC<br/>rpc protocol<br/>[rpc.go]"]
end

subgraph group_control["Control Plane"]
  node_discovery["Discovery<br/>route normalizer<br/>[discovery.go]"]
  node_provider_static["Static<br/>route source<br/>[static.go]"]
  node_provider_file["File<br/>dynamic config<br/>[file.go]"]
  node_provider_docker["Docker<br/>container discovery<br/>[docker.go]"]
  node_provider_consul["Consul Catalog<br/>service discovery<br/>[consulcatalog.go]"]
end

subgraph group_data["Data Plane"]
  node_proxy["Proxy<br/>edge gateway<br/>[proxy.go]"]
  node_handlers["Handlers<br/>response paths<br/>[handlers.go]"]
  node_policy["Policy<br/>request controls<br/>[handlers.go]"]
  node_health_lb["Health & LB<br/>upstream selection<br/>[health.go]"]
  node_ssl["TLS/SSL<br/>edge termination<br/>[ssl.go]"]
  node_assets["Assets<br/>static file serving<br/>[handlers.go]"]
end

subgraph group_ext["External Systems"]
  node_users(("Clients"))
  node_backends[("Backends<br/>upstream services")]
  node_docker_api["Docker API<br/>external control plane"]
  node_consul_api["Consul API<br/>external control plane"]
  node_acme_dns["ACME/DNS<br/>tls providers"]
  node_plugin_procs["Plugin Procs<br/>sidecars"]
end

node_app_main -->|"load routes"| node_discovery
node_app_main -->|"serve traffic"| node_proxy
node_app_main -->|"enable HTTPS"| node_ssl
node_app_main -->|"serve mgmt"| node_mgmt
node_app_main -->|"wire plugins"| node_plugin
node_discovery -->|"source"| node_provider_static
node_discovery -->|"source"| node_provider_file
node_discovery -->|"source"| node_provider_docker
node_discovery -->|"source"| node_provider_consul
node_provider_docker -->|"queries"| node_docker_api
node_provider_consul -->|"polls"| node_consul_api
node_proxy -->|"dispatch"| node_handlers
node_proxy -->|"enforce"| node_policy
node_proxy -->|"select upstream"| node_health_lb
node_proxy -->|"serve files"| node_assets
node_proxy -->|"terminate TLS"| node_ssl
node_proxy -->|"middleware"| node_plugin
node_plugin -->|"rpc"| node_lib
node_plugin -->|"connects"| node_plugin_procs
node_handlers -->|"proxy to"| node_backends
node_assets -->|"read from"| node_backends
node_ssl -->|"challenge"| node_acme_dns
node_mgmt -->|"expose routes"| node_discovery
node_mgmt -->|"metrics/routes"| node_users
node_proxy -->|"serve requests"| node_users

click node_app_main "https://github.com/umputun/reproxy/blob/master/app/main.go"
click node_discovery "https://github.com/umputun/reproxy/blob/master/app/discovery/discovery.go"
click node_provider_static "https://github.com/umputun/reproxy/blob/master/app/discovery/provider/static.go"
click node_provider_file "https://github.com/umputun/reproxy/blob/master/app/discovery/provider/file.go"
click node_provider_docker "https://github.com/umputun/reproxy/blob/master/app/discovery/provider/docker.go"
click node_provider_consul "https://github.com/umputun/reproxy/blob/master/app/discovery/provider/consulcatalog/consulcatalog.go"
click node_proxy "https://github.com/umputun/reproxy/blob/master/app/proxy/proxy.go"
click node_handlers "https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go"
click node_policy "https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go"
click node_health_lb "https://github.com/umputun/reproxy/blob/master/app/proxy/health.go"
click node_ssl "https://github.com/umputun/reproxy/blob/master/app/proxy/ssl.go"
click node_assets "https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go"
click node_mgmt "https://github.com/umputun/reproxy/blob/master/app/mgmt/server.go"
click node_plugin "https://github.com/umputun/reproxy/blob/master/app/plugin/conductor.go"
click node_lib "https://github.com/umputun/reproxy/blob/master/lib/rpc.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_main,node_mgmt,node_plugin,node_lib toneBlue
class node_discovery,node_provider_static,node_provider_file,node_provider_docker,node_provider_consul toneAmber
class node_proxy,node_handlers,node_policy,node_health_lb,node_ssl,node_assets toneMint
class node_users,node_backends,node_docker_api,node_consul_api,node_acme_dns,node_plugin_procs toneRose
```

## Components

### Runtime

Main binary and in-process servers

- [Main](https://github.com/umputun/reproxy/blob/master/app/main.go): Go entrypoint · Wires discovery, proxy, TLS, management, and plugins · `app/main.go`
- [Mgmt API](https://github.com/umputun/reproxy/blob/master/app/mgmt/server.go): control server · Separate listener for routes and metrics · `app/mgmt/server.go`
- [Plugins](https://github.com/umputun/reproxy/blob/master/app/plugin/conductor.go): rpc middleware · External plugin processes participate in request decisions · `app/plugin/conductor.go`
- [Plugin RPC](https://github.com/umputun/reproxy/blob/master/lib/rpc.go): rpc protocol · Shared RPC client/server boundary for plugins · `lib/rpc.go`

### Control Plane

Route discovery and external integrations

- [Discovery](https://github.com/umputun/reproxy/blob/master/app/discovery/discovery.go): route normalizer · Aggregates provider inputs into a common route model · `app/discovery/discovery.go`
- [Static](https://github.com/umputun/reproxy/blob/master/app/discovery/provider/static.go): route source · CLI/env-defined routes · `app/discovery/provider/static.go`
- [File](https://github.com/umputun/reproxy/blob/master/app/discovery/provider/file.go): dynamic config · YAML-based routing config with reloads · `app/discovery/provider/file.go`
- [Docker](https://github.com/umputun/reproxy/blob/master/app/discovery/provider/docker.go): container discovery · Reads Docker labels and container state · `app/discovery/provider/docker.go`
- [Consul Catalog](https://github.com/umputun/reproxy/blob/master/app/discovery/provider/consulcatalog/consulcatalog.go): service discovery · Polls Consul for tagged services · `app/discovery/provider/consulcatalog/consulcatalog.go`

### Data Plane

Request handling and edge behaviors

- [Proxy](https://github.com/umputun/reproxy/blob/master/app/proxy/proxy.go): edge gateway · Matches routes and drives request handling · `app/proxy/proxy.go`
- [Handlers](https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go): response paths · Upstream proxying, redirects, errors, and asset serving · `app/proxy/handlers.go`
- [Policy](https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go): request controls · Auth, IP allowlists, headers, gzip, limits, and timeouts · `app/proxy/handlers.go`
- [Health & LB](https://github.com/umputun/reproxy/blob/master/app/proxy/health.go): upstream selection · Health checks, failover, and load balancing across targets · `app/proxy/health.go`
- [TLS/SSL](https://github.com/umputun/reproxy/blob/master/app/proxy/ssl.go): edge termination · Static certificates and ACME challenge handling · `app/proxy/ssl.go`
- [Assets](https://github.com/umputun/reproxy/blob/master/app/proxy/handlers.go): static file serving · Global and route-scoped static content with SPA fallback · `app/proxy/handlers.go`

### External Systems

Backends and dependencies outside the repo

- **Clients**: http clients · Browsers and API consumers hitting the edge proxy
- **Backends**: upstream services · Target services and asset origins behind routes
- **Docker API**: external control plane · Container metadata source for discovery
- **Consul API**: external control plane · Service catalog source for discovery
- **ACME/DNS**: tls providers · Certificate authority and DNS challenge providers
- **Plugin Procs**: sidecars · External executables that extend proxy behavior

## Connections

- Main → Discovery: load routes · Initializes route discovery and updates
- Main → Proxy: serve traffic · Starts the main edge listener
- Main → TLS/SSL: enable HTTPS · Configures TLS termination when enabled
- Main → Mgmt API: serve mgmt · Starts the optional management listener
- Main → Plugins: wire plugins · Connects plugin RPC into request handling
- Discovery → Static: source · Static routes provider
- Discovery → File: source · File-based dynamic provider
- Discovery → Docker: source · Docker discovery provider
- Discovery → Consul Catalog: source · Consul Catalog provider
- Docker → Docker API: queries · Discovers containers and labels
- Consul Catalog → Consul API: polls · Fetches service catalog state
- Proxy → Handlers: dispatch · Routes matched requests into response paths
- Proxy → Policy: enforce · Applies auth, allowlists, headers, limits, and timeouts
- Proxy → Health & LB: select upstream · Chooses healthy destinations and failover targets
- Proxy → Assets: serve files · Handles static asset responses and SPA fallback
- Proxy → TLS/SSL: terminate TLS · Uses edge certificate and ACME logic
- Proxy → Plugins: middleware · Invokes plugin chain during request processing
- Plugins → Plugin RPC: rpc · Uses shared RPC boundary
- Plugins → Plugin Procs: connects · Talks to external plugin processes
- Handlers → Backends: proxy to · Forwards requests to upstream services
- Assets → Backends: read from · Serves content from configured asset origins
- TLS/SSL → ACME/DNS: challenge · Uses ACME and DNS providers for certificate automation
- Mgmt API → Discovery: expose routes · Publishes discovered route inventory
- Mgmt API → Clients: metrics/routes · Serves operational endpoints to clients
- Proxy → Clients: serve requests · Receives public HTTP(S) traffic
