# steve3184/opencodeproxyhub architecture

> Architecture diagram of the GitHub repository steve3184/opencodeproxyhub, 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/steve3184/opencodeproxyhub
- Repository: https://github.com/steve3184/opencodeproxyhub

## Overview

OpenCodeProxyHub is a Fastify gateway exposing OpenCode models through OpenAI Chat Completions, Responses, Anthropic, and System One-compatible APIs. Client requests enter a protocol route, pass authentication and limits, then reach the Zen upstream through model-aware conversion and optional proxy egress. The admin console manages keys, models, aliases, settings, and proxies and presents monitoring data. Edges follow the README, excerpts, and SOURCE INDEX references; unsampled route internals are not expanded beyond documented capabilities.

Main entry points: [`src/routes/openai.ts`](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/openai.ts) (Chat Completions), [`src/routes/responses.ts`](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/responses.ts) (Responses API), [`src/routes/anthropic.ts`](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/anthropic.ts) (Anthropic API), [`src/providers/zenClient.ts`](https://github.com/steve3184/opencodeproxyhub/blob/main/src/providers/zenClient.ts) (Zen upstream client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway runtime"]
  node_app["Fastify app<br/>[app.ts]"]
  node_zen["Zen upstream client<br/>[zenClient.ts]"]
end

subgraph group_protocol["Protocol handling"]
  node_openai["Chat Completions<br/>[openai.ts]"]
  node_responses["Responses API<br/>[responses.ts]"]
  node_anthropic["Anthropic API<br/>[anthropic.ts]"]
  node_systemone["System One API<br/>[systemone.ts]"]
  node_converter["Protocol converters<br/>[openAiResponses.ts]"]
  node_sseconverter["SSE converters"]
  node_thinkconverter["Reasoning converter"]
  node_toolmapping["Tool mapping<br/>[toolMapping.ts]"]
end

subgraph group_operations["Operations and access"]
  node_keys["API key auth<br/>[apiKeys.ts]"]
  node_limiter["Rate limiting<br/>[limiter.ts]"]
  node_proxy["Proxy pool<br/>[proxyPool.ts]"]
  node_metrics["Metrics<br/>[metrics.ts]"]
  node_eventlog["Event logging<br/>[eventLogger.ts]"]
  node_tracker["Request tracker<br/>[requestTracker.ts]"]
  node_admin["Admin routes<br/>[admin.ts]"]
end

subgraph group_state["Configuration and state"]
  node_catalog[("Model catalog<br/>[catalog.ts]")]
  node_aliases[("Model aliases<br/>[aliases.ts]")]
  node_settings[("System settings<br/>[settingsStore.ts]")]
  node_jsonstore[("JSON persistence<br/>[jsonFile.ts]")]
end

subgraph group_console["Admin console"]
  node_console["Web console<br/>[App.tsx]"]
  node_consoledata["Console data hook<br/>[useConsoleData.ts]"]
  node_consoleapi["Console API client<br/>[api.ts]"]
end

node_client(("API client"))
node_upstream["OpenCode Zen"]
node_adminuser(("Administrator"))

node_client -->|"sends chat"| node_openai
node_client -->|"sends responses"| node_responses
node_client -->|"sends messages"| node_anthropic
node_client -->|"sends requests"| node_systemone
node_app -->|"registers"| node_openai
node_app -->|"registers"| node_responses
node_app -->|"registers"| node_anthropic
node_app -->|"registers"| node_systemone
node_openai -->|"calls upstream"| node_zen
node_responses -->|"calls upstream"| node_zen
node_anthropic -->|"calls upstream"| node_zen
node_systemone -.->|"calls upstream"| node_zen
node_zen -->|"sends requests"| node_upstream
node_openai -->|"converts protocol"| node_converter
node_responses -->|"converts protocol"| node_converter
node_anthropic -->|"converts protocol"| node_converter
node_openai -->|"normalizes streams"| node_sseconverter
node_openai -->|"extracts reasoning"| node_thinkconverter
node_converter -->|"maps tools"| node_toolmapping
node_zen -->|"maps upstream tools"| node_toolmapping
node_zen -->|"uses egress lease"| node_proxy
node_openai -->|"authenticates"| node_keys
node_responses -->|"authenticates"| node_keys
node_anthropic -->|"authenticates"| node_keys
node_openai -->|"checks limits"| node_limiter
node_responses -->|"checks limits"| node_limiter
node_anthropic -->|"checks limits"| node_limiter
node_openai -->|"resolves models"| node_catalog
node_responses -->|"resolves models"| node_catalog
node_anthropic -->|"resolves models"| node_catalog
node_openai -->|"resolves aliases"| node_aliases
node_responses -->|"resolves aliases"| node_aliases
node_anthropic -->|"resolves aliases"| node_aliases
node_app -.->|"initializes"| node_metrics
node_admin -->|"manages keys"| node_keys
node_admin -->|"manages models"| node_catalog
node_admin -->|"manages aliases"| node_aliases
node_admin -->|"updates settings"| node_settings
node_admin -->|"manages proxies"| node_proxy
node_console -->|"loads data"| node_consoledata
node_consoledata -->|"uses API client"| node_consoleapi
node_adminuser -->|"uses console"| node_console
node_consoleapi -.->|"calls management API"| node_admin
node_keys -->|"persists keys"| node_jsonstore
node_catalog -->|"persists models"| node_jsonstore
node_aliases -->|"persists aliases"| node_jsonstore
node_settings -->|"persists settings"| node_jsonstore
node_proxy -->|"persists proxy state"| node_jsonstore

click node_app "https://github.com/steve3184/opencodeproxyhub/blob/main/src/app.ts"
click node_openai "https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/openai.ts"
click node_responses "https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/responses.ts"
click node_anthropic "https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/anthropic.ts"
click node_systemone "https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/systemone.ts"
click node_converter "https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/openAiResponses.ts"
click node_sseconverter "https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/anthropicSseToOpenAi.ts"
click node_thinkconverter "https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/openAiThinkTagToReasoning.ts"
click node_toolmapping "https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/toolMapping.ts"
click node_zen "https://github.com/steve3184/opencodeproxyhub/blob/main/src/providers/zenClient.ts"
click node_keys "https://github.com/steve3184/opencodeproxyhub/blob/main/src/auth/apiKeys.ts"
click node_limiter "https://github.com/steve3184/opencodeproxyhub/blob/main/src/rateLimit/limiter.ts"
click node_proxy "https://github.com/steve3184/opencodeproxyhub/blob/main/src/proxy/proxyPool.ts"
click node_metrics "https://github.com/steve3184/opencodeproxyhub/blob/main/src/observability/metrics.ts"
click node_eventlog "https://github.com/steve3184/opencodeproxyhub/blob/main/src/observability/eventLogger.ts"
click node_tracker "https://github.com/steve3184/opencodeproxyhub/blob/main/src/runtime/requestTracker.ts"
click node_catalog "https://github.com/steve3184/opencodeproxyhub/blob/main/src/models/catalog.ts"
click node_aliases "https://github.com/steve3184/opencodeproxyhub/blob/main/src/models/aliases.ts"
click node_settings "https://github.com/steve3184/opencodeproxyhub/blob/main/src/settings/settingsStore.ts"
click node_jsonstore "https://github.com/steve3184/opencodeproxyhub/blob/main/src/storage/jsonFile.ts"
click node_admin "https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/admin.ts"
click node_console "https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/App.tsx"
click node_consoledata "https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/hooks/useConsoleData.ts"
click node_consoleapi "https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/api.ts"

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_app,node_zen,node_client toneBlue
class node_openai,node_responses,node_anthropic,node_systemone,node_converter,node_sseconverter,node_thinkconverter,node_toolmapping toneAmber
class node_keys,node_limiter,node_proxy,node_metrics,node_eventlog,node_tracker,node_admin toneMint
class node_catalog,node_aliases,node_settings,node_jsonstore toneRose
class node_console,node_consoledata,node_consoleapi,node_upstream,node_adminuser toneIndigo
```

## Components

### Gateway runtime

- [Fastify app](https://github.com/steve3184/opencodeproxyhub/blob/main/src/app.ts): `src/app.ts`
- [Zen upstream client](https://github.com/steve3184/opencodeproxyhub/blob/main/src/providers/zenClient.ts): `src/providers/zenClient.ts`

### Protocol handling

- [Chat Completions](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/openai.ts): `src/routes/openai.ts`
- [Responses API](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/responses.ts): `src/routes/responses.ts`
- [Anthropic API](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/anthropic.ts): `src/routes/anthropic.ts`
- [System One API](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/systemone.ts): `src/routes/systemone.ts`
- [Protocol converters](https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/openAiResponses.ts): `src/converters/openAiResponses.ts`
- [SSE converters](https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/anthropicSseToOpenAi.ts): `src/converters/anthropicSseToOpenAi.ts`
- [Reasoning converter](https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/openAiThinkTagToReasoning.ts): `src/converters/openAiThinkTagToReasoning.ts`
- [Tool mapping](https://github.com/steve3184/opencodeproxyhub/blob/main/src/converters/toolMapping.ts): `src/converters/toolMapping.ts`

### Operations and access

- [API key auth](https://github.com/steve3184/opencodeproxyhub/blob/main/src/auth/apiKeys.ts): `src/auth/apiKeys.ts`
- [Rate limiting](https://github.com/steve3184/opencodeproxyhub/blob/main/src/rateLimit/limiter.ts): `src/rateLimit/limiter.ts`
- [Proxy pool](https://github.com/steve3184/opencodeproxyhub/blob/main/src/proxy/proxyPool.ts): `src/proxy/proxyPool.ts`
- [Metrics](https://github.com/steve3184/opencodeproxyhub/blob/main/src/observability/metrics.ts): `src/observability/metrics.ts`
- [Event logging](https://github.com/steve3184/opencodeproxyhub/blob/main/src/observability/eventLogger.ts): `src/observability/eventLogger.ts`
- [Request tracker](https://github.com/steve3184/opencodeproxyhub/blob/main/src/runtime/requestTracker.ts): `src/runtime/requestTracker.ts`
- [Admin routes](https://github.com/steve3184/opencodeproxyhub/blob/main/src/routes/admin.ts): `src/routes/admin.ts`

### Configuration and state

- [Model catalog](https://github.com/steve3184/opencodeproxyhub/blob/main/src/models/catalog.ts): `src/models/catalog.ts`
- [Model aliases](https://github.com/steve3184/opencodeproxyhub/blob/main/src/models/aliases.ts): `src/models/aliases.ts`
- [System settings](https://github.com/steve3184/opencodeproxyhub/blob/main/src/settings/settingsStore.ts): `src/settings/settingsStore.ts`
- [JSON persistence](https://github.com/steve3184/opencodeproxyhub/blob/main/src/storage/jsonFile.ts): `src/storage/jsonFile.ts`

### Admin console

- [Web console](https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Console data hook](https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/hooks/useConsoleData.ts): `web/src/hooks/useConsoleData.ts`
- [Console API client](https://github.com/steve3184/opencodeproxyhub/blob/main/web/src/api.ts): `web/src/api.ts`

### Other components

- **API client**
- **OpenCode Zen**
- **Administrator**

## Connections

- API client → Chat Completions: sends chat (evidence: `README.md`)
- API client → Responses API: sends responses (evidence: `README.md`)
- API client → Anthropic API: sends messages (evidence: `README.md`)
- API client → System One API: sends requests (evidence: `README.md`)
- Fastify app → Chat Completions: registers (evidence: `src/app.ts`)
- Fastify app → Responses API: registers (evidence: `src/app.ts`)
- Fastify app → Anthropic API: registers (evidence: `src/app.ts`)
- Fastify app → System One API: registers (evidence: `src/app.ts`)
- Chat Completions → Zen upstream client: calls upstream (evidence: `src/routes/openai.ts`)
- Responses API → Zen upstream client: calls upstream (evidence: `src/routes/responses.ts`)
- Anthropic API → Zen upstream client: calls upstream (evidence: `src/routes/anthropic.ts`)
- System One API → Zen upstream client: calls upstream
- Zen upstream client → OpenCode Zen: sends requests (evidence: `README.md`)
- Chat Completions → Protocol converters: converts protocol (evidence: `src/routes/openai.ts`)
- Responses API → Protocol converters: converts protocol (evidence: `src/routes/responses.ts`)
- Anthropic API → Protocol converters: converts protocol (evidence: `src/routes/anthropic.ts`)
- Chat Completions → SSE converters: normalizes streams (evidence: `src/routes/openai.ts`)
- Chat Completions → Reasoning converter: extracts reasoning (evidence: `src/routes/openai.ts`)
- Protocol converters → Tool mapping: maps tools (evidence: `src/converters/openAiResponses.ts`)
- Zen upstream client → Tool mapping: maps upstream tools (evidence: `src/providers/zenClient.ts`)
- Zen upstream client → Proxy pool: uses egress lease (evidence: `src/providers/zenClient.ts`)
- Chat Completions → API key auth: authenticates (evidence: `src/routes/openai.ts`)
- Responses API → API key auth: authenticates (evidence: `src/routes/responses.ts`)
- Anthropic API → API key auth: authenticates (evidence: `src/routes/anthropic.ts`)
- Chat Completions → Rate limiting: checks limits (evidence: `src/routes/openai.ts`)
- Responses API → Rate limiting: checks limits (evidence: `src/routes/responses.ts`)
- Anthropic API → Rate limiting: checks limits (evidence: `src/routes/anthropic.ts`)
- Chat Completions → Model catalog: resolves models (evidence: `src/routes/openai.ts`)
- Responses API → Model catalog: resolves models (evidence: `src/routes/responses.ts`)
- Anthropic API → Model catalog: resolves models (evidence: `src/routes/anthropic.ts`)
- Chat Completions → Model aliases: resolves aliases (evidence: `src/routes/openai.ts`)
- Responses API → Model aliases: resolves aliases (evidence: `src/routes/responses.ts`)
- Anthropic API → Model aliases: resolves aliases (evidence: `src/routes/anthropic.ts`)
- Fastify app → Metrics: initializes (evidence: `src/app.ts`)
- Admin routes → API key auth: manages keys (evidence: `src/routes/admin.ts`)
- Admin routes → Model catalog: manages models (evidence: `src/routes/admin.ts`)
- Admin routes → Model aliases: manages aliases (evidence: `src/routes/admin.ts`)
- Admin routes → System settings: updates settings (evidence: `src/routes/admin.ts`)
- Admin routes → Proxy pool: manages proxies (evidence: `src/routes/admin.ts`)
- Web console → Console data hook: loads data (evidence: `web/src/App.tsx`)
- Console data hook → Console API client: uses API client (evidence: `web/src/hooks/useConsoleData.ts`)
- Administrator → Web console: uses console (evidence: `README.md`)
- Console API client → Admin routes: calls management API
- API key auth → JSON persistence: persists keys (evidence: `src/auth/apiKeys.ts`)
- Model catalog → JSON persistence: persists models (evidence: `src/models/catalog.ts`)
- Model aliases → JSON persistence: persists aliases (evidence: `src/models/aliases.ts`)
- System settings → JSON persistence: persists settings (evidence: `src/settings/settingsStore.ts`)
- Proxy pool → JSON persistence: persists proxy state (evidence: `src/proxy/proxyPool.ts`)
