# bothrachhavi/secure-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/bothrachhavi/secure-gateway
- Repository: https://github.com/bothrachhavi/secure-gateway

## Overview

Secure Gateway is a small Go forward proxy. A client request enters the proxy handler, increments telemetry, passes per-IP rate limiting and domain filtering, then routes to HTTP forwarding or HTTPS CONNECT tunneling. A separate management listener serves JSON metrics. The blocklist is loaded once at startup. The sampled source is the complete runtime implementation; relationships below are based on its calls and the README’s documented behavior.

Main entry points: [`main.go`](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go) (Gateway handler), [`blocked_domains.txt`](https://github.com/bothrachhavi/secure-gateway/blob/main/blocked_domains.txt) (Domain blocklist)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_proxy["Proxy runtime"]
  node_gateway["Gateway handler<br/>[main.go]"]
  node_http_forward["HTTP forwarding<br/>[main.go]"]
  node_connect_tunnel["CONNECT tunnel<br/>[main.go]"]
end

subgraph group_controls["Traffic controls"]
  node_ip_extract["Client IP extraction<br/>[main.go]"]
  node_ip_limiter["Per-IP limiter<br/>[main.go]"]
  node_domain_filter["Domain filter<br/>[main.go]"]
  node_blocklist["Domain blocklist"]
end

subgraph group_telemetry["Metrics service"]
  node_metrics_counters[("Metrics counters<br/>[main.go]")]
  node_metrics_listener["Metrics listener<br/>[main.go]"]
end

node_client(("Proxy client"))
node_upstream(("Upstream host"))
node_metrics_client(("Metrics client"))

node_client -->|"sends request"| node_gateway
node_gateway -->|"increments counters"| node_metrics_counters
node_gateway -->|"extracts address"| node_ip_extract
node_gateway -->|"checks rate"| node_ip_limiter
node_gateway -->|"checks host"| node_domain_filter
node_domain_filter -->|"loads entries"| node_blocklist
node_gateway -->|"routes HTTP"| node_http_forward
node_gateway -->|"routes CONNECT"| node_connect_tunnel
node_http_forward -->|"forwards request"| node_upstream
node_connect_tunnel -->|"opens TCP tunnel"| node_upstream
node_metrics_client -->|"requests stats"| node_metrics_listener
node_metrics_listener -->|"reads counters"| node_metrics_counters

click node_gateway "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_http_forward "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_connect_tunnel "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_ip_extract "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_ip_limiter "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_domain_filter "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_blocklist "https://github.com/bothrachhavi/secure-gateway/blob/main/blocked_domains.txt"
click node_metrics_counters "https://github.com/bothrachhavi/secure-gateway/blob/main/main.go"
click node_metrics_listener "https://github.com/bothrachhavi/secure-gateway/blob/main/main.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_gateway,node_http_forward,node_connect_tunnel,node_client,node_metrics_client toneBlue
class node_ip_extract,node_ip_limiter,node_domain_filter,node_blocklist toneAmber
class node_metrics_counters,node_metrics_listener toneMint
class node_upstream toneIndigo
```

## Components

### Proxy runtime

- [Gateway handler](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [HTTP forwarding](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [CONNECT tunnel](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`

### Traffic controls

- [Client IP extraction](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [Per-IP limiter](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [Domain filter](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [Domain blocklist](https://github.com/bothrachhavi/secure-gateway/blob/main/blocked_domains.txt): `blocked_domains.txt`

### Metrics service

- [Metrics counters](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`
- [Metrics listener](https://github.com/bothrachhavi/secure-gateway/blob/main/main.go): `main.go`

### Other components

- **Proxy client**
- **Upstream host**
- **Metrics client**

## Connections

- Proxy client → Gateway handler: sends request (evidence: `README.md`)
- Gateway handler → Metrics counters: increments counters (evidence: `main.go`)
- Gateway handler → Client IP extraction: extracts address (evidence: `main.go`)
- Gateway handler → Per-IP limiter: checks rate (evidence: `main.go`)
- Gateway handler → Domain filter: checks host (evidence: `main.go`)
- Domain filter → Domain blocklist: loads entries (evidence: `main.go`)
- Gateway handler → HTTP forwarding: routes HTTP (evidence: `main.go`)
- Gateway handler → CONNECT tunnel: routes CONNECT (evidence: `main.go`)
- HTTP forwarding → Upstream host: forwards request (evidence: `main.go`)
- CONNECT tunnel → Upstream host: opens TCP tunnel (evidence: `main.go`)
- Metrics client → Metrics listener: requests stats (evidence: `README.md`)
- Metrics listener → Metrics counters: reads counters (evidence: `main.go`)
