trustgate) that boots one HTTP server, chosen
by its first argument. In production each pod runs the same image with a different
argument, so the planes scale independently.
The three planes
| Plane | Port | Responsibility |
|---|---|---|
| Admin | 8080 | REST CRUD for gateways, registries, consumers, auth, policies, roles, and catalogs. Applies DB migrations on boot. |
| Proxy | 8081 | Request routing, auth validation, policy execution, load balancing, provider forwarding, streaming, telemetry. |
| MCP | 8082 | Model Context Protocol server: exposes registered MCP servers and tools to agents, with an OAuth2 authorization server. |
Request lifecycle (proxy)
- A client calls the proxy with a consumer API key (or OAuth2/IDP token).
- TrustGate resolves the gateway (from
X-AG-Gateway-Slugor the host), the consumer (from the URLslug), and the applicable policies. - The applicable policies run at their stages — rate limit, token rate limit, request size, semantic cache, CORS — sequentially or in parallel.
- The load balancer picks a healthy registry from the consumer’s pool (round-robin, weighted, least-connections, random, or semantic), with fallback.
- The request is forwarded to the selected provider adapter (OpenAI, Anthropic, Bedrock, …), streaming when the client asked for it.
- The response returns, the semantic cache is populated, and a telemetry event is emitted to Kafka.
Gateway discovery
GATEWAY_DISCOVERY_MODE controls how the proxy finds the gateway:
header(default, self-hosted) — reads theX-AG-Gateway-Slugheader, falling back to aHostmatch against{slug}.<GATEWAY_BASE_DOMAIN>.subdomain(cloud) —Host-only.
Infrastructure
| Component | Role |
|---|---|
| PostgreSQL | Source of truth for all configuration (gateways, registries, consumers, …). The Admin plane runs migrations on boot. |
| Redis | Rate-limit counters, the semantic-cache vector store, session store, and a pub/sub channel for cache invalidation. |
| Kafka | Asynchronous telemetry export (TELEMETRY_KAFKA_TOPIC). Off the request critical path. |
Caching & invalidation
To avoid a database round-trip per request, the proxy keeps an in-process TTL cache (CACHE_LOCAL_TTL, default 5m) of resolved gateways, consumers, and auths. Admin
mutations publish invalidation events over Redis pub/sub, and the proxy flushes the
affected entries — so config changes propagate without a restart.
Endpoints the proxy serves
All proxy traffic is shaped as/{consumer_slug}/..., and the inbound format is detected
from the path:
| Path | Format |
|---|---|
POST /{consumer_slug}/v1/chat/completions | OpenAI Chat Completions |
POST /{consumer_slug}/v1/messages | Anthropic Messages |
POST /{consumer_slug}/v1/responses | OpenAI Responses API |
"stream": true) is supported on all three; the proxy flushes each SSE chunk
and surfaces mid-stream upstream failures as an explicit error event rather than a silent
truncation.
Repository layout
TrustGate follows a hexagonal layout — domain entities and ports inpkg/domain,
use-cases in pkg/app, and adapters in pkg/infra (providers, policies, load balancer,
database, telemetry). Configuration is environment-only; see
Configuration.