# ia-generative/gatewai architecture

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

- Interactive diagram: https://gitdiagram.com/ia-generative/gatewai
- Repository: https://github.com/ia-generative/gatewai

## Overview

GatewAI is a Kubernetes inference API gateway with asynchronous jobs, synchronous service proxying, and an OpenAI-compatible LLM proxy; a separate relay executes queued jobs. Clients submit work or inference requests, then receive synchronous responses or retrieve job results and webhooks. The gateway also applies identity and model policies, guardrails, quotas, caching, and usage tracking. Redis and S3 support job processing and result storage. The graph preserves documented capabilities; source excerpts are incomplete, so unshown component-level calls are omitted rather than inferred.

Main entry points: [`cmd/gateway/main.go`](https://github.com/ia-generative/gatewai/blob/main/cmd/gateway/main.go) (Gateway server), [`internal/llmproxy/handler.go`](https://github.com/ia-generative/gatewai/blob/main/internal/llmproxy/handler.go) (LLM proxy), [`relay/internal/relay/relay.go`](https://github.com/ia-generative/gatewai/blob/main/relay/internal/relay/relay.go) (Relay worker), [`internal/handler/jobs.go`](https://github.com/ia-generative/gatewai/blob/main/internal/handler/jobs.go) (Job API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway API"]
  node_gateway["Gateway server<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_sync["Sync proxy<br/>[sync.go]"]
end

subgraph group_inference["Inference Routing"]
  node_llm["LLM proxy<br/>[handler.go]"]
  node_providers["Provider adapters<br/>[anthropic.go]"]
  node_registry["Service registry<br/>[registry.go]"]
  node_adapter["Input adapter<br/>[inputadapter.go]"]
end

subgraph group_async["Async Jobs"]
  node_jobs["Job API<br/>[jobs.go]"]
  node_completion["Job completion<br/>[relaycomplete.go]"]
  node_consumer["Completion manager<br/>[manager.go]"]
  node_webhook["Webhook delivery<br/>[webhook.go]"]
  node_retry["Webhook retries<br/>[webhook_retry.go]"]
  node_relay["Relay worker<br/>[relay.go]"]
  node_relayqueue["Relay queue<br/>[queue.go]"]
  node_relaymain["Relay process<br/>[main.go]"]
end

subgraph group_policy["Access and Safety"]
  node_auth["Authentication<br/>[auth.go]"]
  node_authz["Model access policy<br/>[authz.go]"]
  node_guardrails["PII and secret controls<br/>[guardrails.go]"]
  node_ratelimit["Consumer quotas<br/>[ratelimit.go]"]
end

subgraph group_operations["State and Observability"]
  node_redis[("Redis state<br/>[redis.go]")]
  node_s3[("S3 object storage<br/>[s3.go]")]
  node_usage["Usage reporting<br/>[store.go]"]
  node_metrics["Prometheus metrics<br/>[metrics.go]"]
  node_telemetry["OpenTelemetry<br/>[telemetry.go]"]
end

node_client(("API client"))
node_inferencebackend{{"Inference backends"}}
node_consumerapp(("Webhook recipient"))
node_otlp{{"OTLP collector"}}

node_client -->|"sends requests"| node_gateway
node_gateway -->|"routes job API"| node_jobs
node_gateway -.->|"loads configuration"| node_config
node_gateway -->|"routes sync API"| node_sync
node_gateway -->|"routes LLM API"| node_llm
node_gateway -->|"routes completion"| node_completion
node_jobs -->|"queues jobs"| node_relayqueue
node_relaymain -->|"runs worker"| node_relay
node_relay -->|"retrieves jobs"| node_relayqueue
node_relay -.->|"stores results"| node_s3
node_relay -.->|"forwards inference"| node_inferencebackend
node_relay -.->|"notifies completion"| node_completion
node_completion -->|"claims completion work"| node_consumer
node_consumer -.->|"delivers callbacks"| node_webhook
node_webhook -->|"schedules failures"| node_retry
node_webhook -->|"posts result"| node_consumerapp
node_llm -->|"routes provider requests"| node_providers
node_providers -.->|"calls backend"| node_inferencebackend
node_sync -.->|"selects service"| node_registry
node_sync -.->|"adapts input"| node_adapter
node_llm -.->|"selects service"| node_registry
node_auth -.->|"provides principal"| node_authz
node_llm -.->|"checks content"| node_guardrails
node_llm -->|"checks token quota"| node_ratelimit
node_jobs -.->|"persists job state"| node_redis
node_jobs -.->|"stores input"| node_s3
node_webhook -->|"reads results"| node_s3
node_llm -.->|"uses response cache"| node_redis
node_usage -.->|"stores usage"| node_redis
node_gateway -->|"serves metrics"| node_metrics
node_gateway -.->|"configures tracing"| node_telemetry
node_telemetry -->|"pushes telemetry"| node_otlp
node_client -->|"requests reports"| node_usage

click node_gateway "https://github.com/ia-generative/gatewai/blob/main/cmd/gateway/main.go"
click node_config "https://github.com/ia-generative/gatewai/blob/main/internal/config/config.go"
click node_sync "https://github.com/ia-generative/gatewai/blob/main/internal/handler/sync.go"
click node_jobs "https://github.com/ia-generative/gatewai/blob/main/internal/handler/jobs.go"
click node_completion "https://github.com/ia-generative/gatewai/blob/main/internal/handler/relaycomplete.go"
click node_consumer "https://github.com/ia-generative/gatewai/blob/main/internal/consumer/manager.go"
click node_webhook "https://github.com/ia-generative/gatewai/blob/main/internal/consumer/webhook.go"
click node_retry "https://github.com/ia-generative/gatewai/blob/main/internal/consumer/webhook_retry.go"
click node_relay "https://github.com/ia-generative/gatewai/blob/main/relay/internal/relay/relay.go"
click node_relayqueue "https://github.com/ia-generative/gatewai/blob/main/relay/internal/queue/queue.go"
click node_llm "https://github.com/ia-generative/gatewai/blob/main/internal/llmproxy/handler.go"
click node_providers "https://github.com/ia-generative/gatewai/blob/main/internal/llmproxy/provider/anthropic.go"
click node_registry "https://github.com/ia-generative/gatewai/blob/main/internal/service/registry.go"
click node_adapter "https://github.com/ia-generative/gatewai/blob/main/internal/inputadapter/inputadapter.go"
click node_auth "https://github.com/ia-generative/gatewai/blob/main/internal/auth/auth.go"
click node_authz "https://github.com/ia-generative/gatewai/blob/main/internal/authz/authz.go"
click node_guardrails "https://github.com/ia-generative/gatewai/blob/main/internal/guardrails/guardrails.go"
click node_ratelimit "https://github.com/ia-generative/gatewai/blob/main/internal/ratelimit/ratelimit.go"
click node_redis "https://github.com/ia-generative/gatewai/blob/main/internal/storage/redis.go"
click node_s3 "https://github.com/ia-generative/gatewai/blob/main/internal/storage/s3.go"
click node_usage "https://github.com/ia-generative/gatewai/blob/main/internal/usage/store.go"
click node_metrics "https://github.com/ia-generative/gatewai/blob/main/internal/metrics/metrics.go"
click node_telemetry "https://github.com/ia-generative/gatewai/blob/main/internal/telemetry/telemetry.go"
click node_relaymain "https://github.com/ia-generative/gatewai/blob/main/relay/cmd/relay/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_config,node_sync,node_client toneBlue
class node_llm,node_providers,node_registry,node_adapter toneAmber
class node_jobs,node_completion,node_consumer,node_webhook,node_retry,node_relay,node_relayqueue,node_relaymain,node_consumerapp toneMint
class node_auth,node_authz,node_guardrails,node_ratelimit toneRose
class node_redis,node_s3,node_usage,node_metrics,node_telemetry,node_inferencebackend,node_otlp toneIndigo
```

## Components

### Gateway API

- [Gateway server](https://github.com/ia-generative/gatewai/blob/main/cmd/gateway/main.go): `cmd/gateway/main.go`
- [Configuration](https://github.com/ia-generative/gatewai/blob/main/internal/config/config.go): `internal/config/config.go`
- [Sync proxy](https://github.com/ia-generative/gatewai/blob/main/internal/handler/sync.go): `internal/handler/sync.go`

### Inference Routing

- [LLM proxy](https://github.com/ia-generative/gatewai/blob/main/internal/llmproxy/handler.go): `internal/llmproxy/handler.go`
- [Provider adapters](https://github.com/ia-generative/gatewai/blob/main/internal/llmproxy/provider/anthropic.go): `internal/llmproxy/provider/anthropic.go`
- [Service registry](https://github.com/ia-generative/gatewai/blob/main/internal/service/registry.go): `internal/service/registry.go`
- [Input adapter](https://github.com/ia-generative/gatewai/blob/main/internal/inputadapter/inputadapter.go): `internal/inputadapter/inputadapter.go`

### Async Jobs

- [Job API](https://github.com/ia-generative/gatewai/blob/main/internal/handler/jobs.go): `internal/handler/jobs.go`
- [Job completion](https://github.com/ia-generative/gatewai/blob/main/internal/handler/relaycomplete.go): `internal/handler/relaycomplete.go`
- [Completion manager](https://github.com/ia-generative/gatewai/blob/main/internal/consumer/manager.go): `internal/consumer/manager.go`
- [Webhook delivery](https://github.com/ia-generative/gatewai/blob/main/internal/consumer/webhook.go): `internal/consumer/webhook.go`
- [Webhook retries](https://github.com/ia-generative/gatewai/blob/main/internal/consumer/webhook_retry.go): `internal/consumer/webhook_retry.go`
- [Relay worker](https://github.com/ia-generative/gatewai/blob/main/relay/internal/relay/relay.go): `relay/internal/relay/relay.go`
- [Relay queue](https://github.com/ia-generative/gatewai/blob/main/relay/internal/queue/queue.go): `relay/internal/queue/queue.go`
- [Relay process](https://github.com/ia-generative/gatewai/blob/main/relay/cmd/relay/main.go): `relay/cmd/relay/main.go`

### Access and Safety

- [Authentication](https://github.com/ia-generative/gatewai/blob/main/internal/auth/auth.go): `internal/auth/auth.go`
- [Model access policy](https://github.com/ia-generative/gatewai/blob/main/internal/authz/authz.go): `internal/authz/authz.go`
- [PII and secret controls](https://github.com/ia-generative/gatewai/blob/main/internal/guardrails/guardrails.go): `internal/guardrails/guardrails.go`
- [Consumer quotas](https://github.com/ia-generative/gatewai/blob/main/internal/ratelimit/ratelimit.go): `internal/ratelimit/ratelimit.go`

### State and Observability

- [Redis state](https://github.com/ia-generative/gatewai/blob/main/internal/storage/redis.go): `internal/storage/redis.go`
- [S3 object storage](https://github.com/ia-generative/gatewai/blob/main/internal/storage/s3.go): `internal/storage/s3.go`
- [Usage reporting](https://github.com/ia-generative/gatewai/blob/main/internal/usage/store.go): `internal/usage/store.go`
- [Prometheus metrics](https://github.com/ia-generative/gatewai/blob/main/internal/metrics/metrics.go): `internal/metrics/metrics.go`
- [OpenTelemetry](https://github.com/ia-generative/gatewai/blob/main/internal/telemetry/telemetry.go): `internal/telemetry/telemetry.go`

### Other components

- **API client**
- **Inference backends**
- **Webhook recipient**
- **OTLP collector**

## Connections

- API client → Gateway server: sends requests
- Gateway server → Job API: routes job API (evidence: `cmd/gateway/main.go`)
- Gateway server → Configuration: loads configuration
- Gateway server → Sync proxy: routes sync API
- Gateway server → LLM proxy: routes LLM API
- Gateway server → Job completion: routes completion (evidence: `cmd/gateway/main.go`)
- Job API → Relay queue: queues jobs
- Relay process → Relay worker: runs worker (evidence: `relay/cmd/relay/main.go`)
- Relay worker → Relay queue: retrieves jobs (evidence: `relay/internal/relay/relay.go`)
- Relay worker → S3 object storage: stores results
- Relay worker → Inference backends: forwards inference
- Relay worker → Job completion: notifies completion
- Job completion → Completion manager: claims completion work (evidence: `internal/consumer/manager.go`)
- Completion manager → Webhook delivery: delivers callbacks
- Webhook delivery → Webhook retries: schedules failures (evidence: `internal/consumer/webhook.go`)
- Webhook delivery → Webhook recipient: posts result (evidence: `internal/consumer/webhook.go`)
- LLM proxy → Provider adapters: routes provider requests (evidence: `internal/llmproxy/handler.go`)
- Provider adapters → Inference backends: calls backend
- Sync proxy → Service registry: selects service
- Sync proxy → Input adapter: adapts input
- LLM proxy → Service registry: selects service
- Authentication → Model access policy: provides principal
- LLM proxy → PII and secret controls: checks content
- LLM proxy → Consumer quotas: checks token quota (evidence: `internal/llmproxy/handler.go`)
- Job API → Redis state: persists job state
- Job API → S3 object storage: stores input
- Webhook delivery → S3 object storage: reads results (evidence: `internal/consumer/webhook.go`)
- LLM proxy → Redis state: uses response cache
- Usage reporting → Redis state: stores usage
- Gateway server → Prometheus metrics: serves metrics (evidence: `cmd/gateway/main.go`)
- Gateway server → OpenTelemetry: configures tracing
- OpenTelemetry → OTLP collector: pushes telemetry
- API client → Usage reporting: requests reports
