How umputun/reproxy works
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: proxy.go Proxy · discovery.go Discovery · main.go Main · conductor.go Plugins
Components 21
Runtime
Main binary and in-process servers
- Main · Wires discovery, proxy, TLS, management, and plugins
app/main.go - Mgmt API · Separate listener for routes and metrics
app/mgmt/server.go - Plugins · External plugin processes participate in request decisions
app/plugin/conductor.go - Plugin RPC · Shared RPC client/server boundary for plugins
lib/rpc.go
Control Plane
Route discovery and external integrations
- Discovery · Aggregates provider inputs into a common route model
app/discovery/discovery.go - Static · CLI/env-defined routes
app/discovery/provider/static.go - File · YAML-based routing config with reloads
app/discovery/provider/file.go - Docker · Reads Docker labels and container state
app/discovery/provider/docker.go - Consul Catalog · Polls Consul for tagged services
app/discovery/provider/consulcatalog/consulcatalog.go
Data Plane
Request handling and edge behaviors
- Proxy · Matches routes and drives request handling
app/proxy/proxy.go - Handlers · Upstream proxying, redirects, errors, and asset serving
app/proxy/handlers.go - Policy · Auth, IP allowlists, headers, gzip, limits, and timeouts
app/proxy/handlers.go - Health & LB · Health checks, failover, and load balancing across targets
app/proxy/health.go - TLS/SSL · Static certificates and ACME challenge handling
app/proxy/ssl.go - Assets · Global and route-scoped static content with SPA fallback
app/proxy/handlers.go
External Systems
Backends and dependencies outside the repo
- Clients · Browsers and API consumers hitting the edge proxy
- Backends · Target services and asset origins behind routes
- Docker API · Container metadata source for discovery
- Consul API · Service catalog source for discovery
- ACME/DNS · Certificate authority and DNS challenge providers
- Plugin Procs · External executables that extend proxy behavior
Connections 25
- 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