# asenalabs/asena architecture

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

- Interactive diagram: https://gitdiagram.com/asenalabs/asena
- Repository: https://github.com/asenalabs/asena

## Overview

Asena is a lightweight reverse proxy. Its principal workflow is to load static settings and watch dynamic YAML, compile routing rules and build service proxies, then accept HTTP(S) requests, match a router, select an upstream, and relay the response. Separate capabilities include TLS certificate reload with HTTP fallback, request logging, and several load-balancing strategies. The graph reflects the supplied excerpts and README; unsampled algorithms and TLS certificate management are represented at their supported directory or file paths, without assuming unseen wiring.

Main entry points: [`cmd/startasena.go`](https://github.com/asenalabs/asena/blob/main/cmd/startasena.go) (Startup orchestration), [`internal/proxy/manager.go`](https://github.com/asenalabs/asena/blob/main/internal/proxy/manager.go) (Proxy manager), [`internal/server/server.go`](https://github.com/asenalabs/asena/blob/main/internal/server/server.go) (HTTP(S) server), [`internal/config/defaults.go`](https://github.com/asenalabs/asena/blob/main/internal/config/defaults.go) (Config normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Program entry<br/>[main.go]"]
  node_startup["Startup orchestration<br/>[startasena.go]"]
  node_middleware["Logging middleware<br/>[logging.go]"]
  node_server["HTTP&#40;S&#41; server<br/>[server.go]"]
  node_certs["TLS certificates<br/>[cert.go]"]
end

subgraph group_configuration["Configuration"]
  node_cli["CLI options<br/>[parser.go]"]
  node_staticconfig["Static config loading<br/>[service.go]"]
  node_configdefaults["Config normalization<br/>[defaults.go]"]
  node_dynamicconfig["Dynamic config watcher<br/>[service.go]"]
end

subgraph group_routing["Routing"]
  node_handler["Request handler<br/>[handler.go]"]
  node_routes["Route compilation<br/>[route.go]"]
  node_rules["Rule parsing and matching<br/>[matcher.go]"]
end

subgraph group_proxy["Proxying"]
  node_proxymanager["Proxy manager<br/>[manager.go]"]
  node_balancers["Load-balancing strategies"]
end

subgraph group_operations["Operations"]
  node_logger["Structured logging<br/>[zap.go]"]
end

node_client(("HTTP client"))
node_upstreams(("Backend services"))

node_main -->|"starts"| node_startup
node_startup -->|"parses options"| node_cli
node_startup -->|"loads settings"| node_staticconfig
node_staticconfig -->|"normalizes"| node_configdefaults
node_configdefaults -->|"uses options"| node_cli
node_startup -->|"starts watcher"| node_dynamicconfig
node_dynamicconfig -->|"validates settings"| node_configdefaults
node_startup -->|"builds proxies"| node_proxymanager
node_proxymanager -->|"compiles routes"| node_routes
node_routes -->|"parses rules"| node_rules
node_startup -->|"wraps handler"| node_middleware
node_startup -->|"registers routes"| node_handler
node_startup -->|"starts listener"| node_server
node_server -->|"loads certificates"| node_certs
node_client -.->|"sends requests"| node_server
node_handler -->|"matches and serves"| node_proxymanager
node_proxymanager -->|"selects backend"| node_balancers
node_proxymanager -->|"proxies requests"| node_upstreams
node_logger -.->|"logs proxy failures"| node_upstreams
node_startup -->|"initializes logger"| node_logger

click node_main "https://github.com/asenalabs/asena/blob/main/main.go"
click node_startup "https://github.com/asenalabs/asena/blob/main/cmd/startasena.go"
click node_middleware "https://github.com/asenalabs/asena/blob/main/internal/middleware/logging.go"
click node_server "https://github.com/asenalabs/asena/blob/main/internal/server/server.go"
click node_certs "https://github.com/asenalabs/asena/blob/main/internal/server/cert.go"
click node_cli "https://github.com/asenalabs/asena/blob/main/pkg/cli/parser.go"
click node_staticconfig "https://github.com/asenalabs/asena/blob/main/internal/config/service.go"
click node_configdefaults "https://github.com/asenalabs/asena/blob/main/internal/config/defaults.go"
click node_dynamicconfig "https://github.com/asenalabs/asena/blob/main/internal/config/service.go"
click node_handler "https://github.com/asenalabs/asena/blob/main/internal/handler/handler.go"
click node_routes "https://github.com/asenalabs/asena/blob/main/internal/proxy/route.go"
click node_rules "https://github.com/asenalabs/asena/blob/main/internal/rule/matcher.go"
click node_proxymanager "https://github.com/asenalabs/asena/blob/main/internal/proxy/manager.go"
click node_balancers "https://github.com/asenalabs/asena/tree/main/internal/proxy/balancer"
click node_logger "https://github.com/asenalabs/asena/blob/main/pkg/logger/zap.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_main,node_startup,node_middleware,node_server,node_certs,node_client toneBlue
class node_cli,node_staticconfig,node_configdefaults,node_dynamicconfig toneAmber
class node_handler,node_routes,node_rules toneMint
class node_proxymanager,node_balancers toneRose
class node_logger,node_upstreams toneIndigo
```

## Components

### Runtime

- [Program entry](https://github.com/asenalabs/asena/blob/main/main.go): `main.go`
- [Startup orchestration](https://github.com/asenalabs/asena/blob/main/cmd/startasena.go): `cmd/startasena.go`
- [Logging middleware](https://github.com/asenalabs/asena/blob/main/internal/middleware/logging.go): `internal/middleware/logging.go`
- [HTTP(S) server](https://github.com/asenalabs/asena/blob/main/internal/server/server.go): `internal/server/server.go`
- [TLS certificates](https://github.com/asenalabs/asena/blob/main/internal/server/cert.go): `internal/server/cert.go`

### Configuration

- [CLI options](https://github.com/asenalabs/asena/blob/main/pkg/cli/parser.go): `pkg/cli/parser.go`
- [Static config loading](https://github.com/asenalabs/asena/blob/main/internal/config/service.go): `internal/config/service.go`
- [Config normalization](https://github.com/asenalabs/asena/blob/main/internal/config/defaults.go): `internal/config/defaults.go`
- [Dynamic config watcher](https://github.com/asenalabs/asena/blob/main/internal/config/service.go): `internal/config/service.go`

### Routing

- [Request handler](https://github.com/asenalabs/asena/blob/main/internal/handler/handler.go): `internal/handler/handler.go`
- [Route compilation](https://github.com/asenalabs/asena/blob/main/internal/proxy/route.go): `internal/proxy/route.go`
- [Rule parsing and matching](https://github.com/asenalabs/asena/blob/main/internal/rule/matcher.go): `internal/rule/matcher.go`

### Proxying

- [Proxy manager](https://github.com/asenalabs/asena/blob/main/internal/proxy/manager.go): `internal/proxy/manager.go`
- [Load-balancing strategies](https://github.com/asenalabs/asena/tree/main/internal/proxy/balancer): `internal/proxy/balancer`

### Operations

- [Structured logging](https://github.com/asenalabs/asena/blob/main/pkg/logger/zap.go): `pkg/logger/zap.go`

### Other components

- **HTTP client**
- **Backend services**

## Connections

- Program entry → Startup orchestration: starts (evidence: `main.go`)
- Startup orchestration → CLI options: parses options (evidence: `cmd/startasena.go`)
- Startup orchestration → Static config loading: loads settings (evidence: `cmd/startasena.go`)
- Static config loading → Config normalization: normalizes (evidence: `internal/config/service.go`)
- Config normalization → CLI options: uses options (evidence: `internal/config/defaults.go`)
- Startup orchestration → Dynamic config watcher: starts watcher (evidence: `cmd/startasena.go`)
- Dynamic config watcher → Config normalization: validates settings (evidence: `internal/config/defaults.go`)
- Startup orchestration → Proxy manager: builds proxies (evidence: `cmd/startasena.go`)
- Proxy manager → Route compilation: compiles routes (evidence: `internal/proxy/manager.go`)
- Route compilation → Rule parsing and matching: parses rules (evidence: `internal/proxy/route.go`)
- Startup orchestration → Logging middleware: wraps handler (evidence: `cmd/startasena.go`)
- Startup orchestration → Request handler: registers routes (evidence: `cmd/startasena.go`)
- Startup orchestration → HTTP(S) server: starts listener (evidence: `cmd/startasena.go`)
- HTTP(S) server → TLS certificates: loads certificates (evidence: `internal/server/server.go`)
- HTTP client → HTTP(S) server: sends requests (evidence: `README.md`)
- Request handler → Proxy manager: matches and serves (evidence: `internal/handler/handler.go`)
- Proxy manager → Load-balancing strategies: selects backend (evidence: `internal/proxy/manager.go`)
- Proxy manager → Backend services: proxies requests (evidence: `internal/proxy/manager.go`)
- Structured logging → Backend services: logs proxy failures
- Startup orchestration → Structured logging: initializes logger (evidence: `cmd/startasena.go`)
