How dotnet/yarp works
Project Type and Purpose
• YARP (“Yet Another Reverse Proxy”) is a .NET-based reverse proxy toolkit/library plus a reference ASP.NET Core host and a Kubernetes ingress controller.
• It ships as reusable components (NuGet libraries and project templates) to build highly customizable proxy servers, and includes:
• Core ReverseProxy library (src/ReverseProxy)
• Kubernetes ingress controller (src/Kubernetes.Controller)
• Telemetry/event‐listener library (src/TelemetryConsumption)
• A CLI host/app (src/Application)
• Sample apps and end-to-end tests under samples/ and test/
High-level File Structure & Architectural Patterns
• src/ReverseProxy
• Configuration: providers, validators, in-memory snapshot
• Management: ProxyConfigManager, builder extensions
• Routing: endpoint factory, match policies
• Transforms: request/response pipeline enrichment
• SessionAffinity, LoadBalancing, Health, Limits, Delegation, ServiceDiscovery, Utilities, WebSocketsTelemetry
• Forwarder: HttpForwarder middleware using HttpClient
• Model: in-memory representation of clusters/routes
• src/Kubernetes.Controller
• Watches Kubernetes API (via ResourceInformer, informers)
• Converts Ingress resources to YARP config (YarpParser)
• Runs as a background hosted service in ASP.NET Core
• src/TelemetryConsumption
• Listens to .NET EventSources (Forwarder, Http, Kestrel, WebSockets, etc.)
• Exposes consumable metrics for Prometheus or custom sinks
• src/Application
• A console/ASP.NET Core host wiring up the ReverseProxy and optional Kubernetes controller or telemetry modules
• Integration with ASP.NET Core’s IEndpointRouteBuilder and middleware pipeline (IReverseProxyApplicationBuilder)
• ASP.NET Core Host (Program.cs / Generic Host)
• Configuration Providers
• Appsettings.json / InMemoryConfigProvider
• KubernetesConfigProvider (if running controller)
• ProxyConfigManager / Management Layer
• ReverseProxy Pipeline
• Routing Middleware
• Transform Middleware
• SessionAffinity Middleware
• LoadBalancing Middleware
• HealthCheck Middleware
• Limits Middleware
• Delegation Middleware
• Forwarder Middleware (HttpForwarder → HttpClient)
• ServiceDiscovery (DNS / Custom resolvers)
• Backend Clusters / Destinations (external services)
• Kubernetes API Server (for the controller)
• TelemetryConsumers (EventListenerService modules)
• Prometheus / External Metrics Store (optional)
• Host → loads Configuration → feeds ProxyConfigManager
• ProxyConfigManager → (on change) → updates in-memory Model
• Host → attaches ReverseProxy pipeline into ASP.NET Core request loop
• Incoming HTTP Request → Routing → Transforms → SessionAffinity → LoadBalancing → HealthCheck → Limits → Delegation → Forwarder → Backend
• Forwarder → uses HttpClientFactory → outbound HTTP to Destination
• Kubernetes Controller (sidecar or integrated) → watches K8s API → sends translated config into ProxyConfigManager
• TelemetryConsumers → subscribe to EventSources from Forwarder, Kestrel, WebSockets → emit metrics to Prometheus/console
c. Architectural Patterns & Principles:
• Modular middleware pipeline (ASP.NET Core style)
• In-memory dynamic configuration with change notifications
• Strategy patterns for load‐balancing, health, session affinity, transforms
• Separation of concerns: Config → Model → Pipeline → Forwarding
• Observer pattern: EventSource → TelemetryConsumers
• Adapter for Kubernetes CRDs → YARP config
d. Key Technologies & Frameworks:
• .NET 6+ Generic Host / ASP.NET Core
• Microsoft.ReverseProxy libraries
• Kubernetes .NET client (informers)
• System.Net.Http.HttpClient / HttpClientFactory
• EventSource / DiagnosticSource
Final Advice
• Control-plane (config, K8s controller) separately from data-plane (request pipeline)