# alexazhou/gt_ai_gateway architecture

> Architecture diagram of the GitHub repository alexazhou/gt_ai_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/alexazhou/gt_ai_gateway
- Repository: https://github.com/alexazhou/gt_ai_gateway

## Overview

GT AI Gateway is an LLM proxy and administration product. A client sends a model request through the gateway, where authentication, tenant scope, and rules are applied; the request is routed to an upstream, optionally converted or rewritten, then returned and recorded. The admin UI configures users, vendors, models, and operational features. The README documents the major capabilities; some subsystem links below rely on that documentation or SOURCE INDEX references rather than inspected implementation excerpts.

Main entry points: [`src/service/senderService.ts`](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/senderService.ts) (Upstream sender), [`src/middleware/llmApiMiddleware.ts`](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/llmApiMiddleware.ts) (LLM API middleware), [`src/routes.ts`](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/routes.ts) (API routes), [`frontend/src/App.vue`](https://github.com/alexazhou/gt_ai_gateway/blob/master/frontend/src/App.vue) (Web admin UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Admin interface"]
  node_webui["Web admin UI<br/>[App.vue]"]
  node_frontend_api["API client<br/>[request.ts]"]
end

subgraph group_gateway["Gateway runtime"]
  node_api_routes["API routes<br/>[routes.ts]"]
  node_llm_gate["LLM API middleware"]
  node_auth["Authentication<br/>[authMiddleware.ts]"]
  node_llm_request["LLM request service"]
  node_sender["Upstream sender<br/>[senderService.ts]"]
  node_routing["Routing strategies"]
end

subgraph group_management["Management and policy"]
  node_tenant_scope["Tenant scope"]
  node_model_admin["Model management<br/>[modelController.ts]"]
  node_vendor_admin["Vendor management"]
  node_user_policy["Users and rules<br/>[userService.ts]"]
  node_tenant_admin["Tenant management<br/>[tenantService.ts]"]
  node_stats["Stats and dashboard<br/>[statsController.ts]"]
end

subgraph group_records["Records and persistence"]
  node_record_service["Request records<br/>[recordService.ts]"]
  node_activity["Request activity"]
  node_payload_store["Payload storage"]
  node_orm[("ORM and database<br/>[ormService.ts]")]
end

subgraph group_integrations["Protocol and clients"]
  node_protocol["Protocol conversion"]
  node_rewriters["Request rewriters"]
  node_client_config["Client configuration<br/>[core.ts]"]
end

node_admin(("Admin user"))
node_client(("LLM client"))
node_upstream(("Model provider"))

node_admin -->|"uses"| node_webui
node_webui -.->|"requests"| node_frontend_api
node_frontend_api -.->|"calls API"| node_api_routes
node_client -->|"sends request"| node_api_routes
node_api_routes -.->|"routes LLM calls"| node_llm_gate
node_api_routes -->|"registers routes"| node_auth
node_llm_gate -->|"authenticates"| node_auth
node_llm_gate -->|"resolves scope"| node_tenant_scope
node_llm_gate -->|"dispatches"| node_llm_request
node_llm_gate -->|"records request"| node_record_service
node_llm_gate -->|"checks rules"| node_user_policy
node_llm_request -.->|"sends request"| node_sender
node_sender -->|"selects upstream"| node_routing
node_sender -->|"converts protocol"| node_protocol
node_sender -->|"applies rewrites"| node_rewriters
node_sender -->|"forwards request"| node_upstream
node_upstream -->|"returns response"| node_sender
node_sender -->|"records result"| node_record_service
node_sender -->|"logs stages"| node_activity
node_model_admin -->|"registered by"| node_api_routes
node_vendor_admin -->|"registered by"| node_api_routes
node_model_admin -->|"configures models"| node_sender
node_user_policy -->|"scopes users"| node_tenant_admin
node_webui -->|"configures clients"| node_client_config
node_record_service -->|"stores payloads"| node_payload_store
node_record_service -->|"persists records"| node_orm
node_activity -.->|"stores activity"| node_orm
node_payload_store -->|"stores database payloads"| node_orm
node_payload_store -.->|"uses object storage"| node_upstream
node_stats -.->|"feeds dashboard"| node_webui
node_stats -.->|"queries metrics"| node_orm

click node_webui "https://github.com/alexazhou/gt_ai_gateway/blob/master/frontend/src/App.vue"
click node_frontend_api "https://github.com/alexazhou/gt_ai_gateway/blob/master/frontend/src/utils/request.ts"
click node_api_routes "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/routes.ts"
click node_llm_gate "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/llmApiMiddleware.ts"
click node_auth "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/authMiddleware.ts"
click node_tenant_scope "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/tenantScopeMiddleware.ts"
click node_llm_request "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/llmRequestService.ts"
click node_sender "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/senderService.ts"
click node_routing "https://github.com/alexazhou/gt_ai_gateway/tree/master/src/service/routingService"
click node_protocol "https://github.com/alexazhou/gt_ai_gateway/tree/master/src/util/protocolConverter"
click node_rewriters "https://github.com/alexazhou/gt_ai_gateway/tree/master/src/plugin"
click node_model_admin "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/modelController.ts"
click node_vendor_admin "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/vendorController.ts"
click node_user_policy "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/userService.ts"
click node_tenant_admin "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/tenantService.ts"
click node_client_config "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/clientConfigService/core.ts"
click node_record_service "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/recordService.ts"
click node_activity "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/requestActivityService.ts"
click node_payload_store "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/objectStorageService.ts"
click node_orm "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/ormService.ts"
click node_stats "https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/statsController.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_webui,node_frontend_api,node_admin,node_client toneBlue
class node_api_routes,node_llm_gate,node_auth,node_llm_request,node_sender,node_routing toneAmber
class node_tenant_scope,node_model_admin,node_vendor_admin,node_user_policy,node_tenant_admin,node_stats toneMint
class node_record_service,node_activity,node_payload_store,node_orm toneRose
class node_protocol,node_rewriters,node_client_config,node_upstream toneIndigo
```

## Components

### Admin interface

- [Web admin UI](https://github.com/alexazhou/gt_ai_gateway/blob/master/frontend/src/App.vue): `frontend/src/App.vue`
- [API client](https://github.com/alexazhou/gt_ai_gateway/blob/master/frontend/src/utils/request.ts): `frontend/src/utils/request.ts`

### Gateway runtime

- [API routes](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/routes.ts): `src/routes.ts`
- [LLM API middleware](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/llmApiMiddleware.ts): `src/middleware/llmApiMiddleware.ts`
- [Authentication](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/authMiddleware.ts): `src/middleware/authMiddleware.ts`
- [LLM request service](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/llmRequestService.ts): `src/service/llmRequestService.ts`
- [Upstream sender](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/senderService.ts): `src/service/senderService.ts`
- [Routing strategies](https://github.com/alexazhou/gt_ai_gateway/tree/master/src/service/routingService): `src/service/routingService`

### Management and policy

- [Tenant scope](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/middleware/tenantScopeMiddleware.ts): `src/middleware/tenantScopeMiddleware.ts`
- [Model management](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/modelController.ts): `src/controller/modelController.ts`
- [Vendor management](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/vendorController.ts): `src/controller/vendorController.ts`
- [Users and rules](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/userService.ts): `src/service/userService.ts`
- [Tenant management](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/tenantService.ts): `src/service/tenantService.ts`
- [Stats and dashboard](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/controller/statsController.ts): `src/controller/statsController.ts`

### Records and persistence

- [Request records](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/recordService.ts): `src/service/recordService.ts`
- [Request activity](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/requestActivityService.ts): `src/service/requestActivityService.ts`
- [Payload storage](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/objectStorageService.ts): `src/service/objectStorageService.ts`
- [ORM and database](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/ormService.ts): `src/service/ormService.ts`

### Protocol and clients

- [Protocol conversion](https://github.com/alexazhou/gt_ai_gateway/tree/master/src/util/protocolConverter): `src/util/protocolConverter`
- [Request rewriters](https://github.com/alexazhou/gt_ai_gateway/tree/master/src/plugin): `src/plugin`
- [Client configuration](https://github.com/alexazhou/gt_ai_gateway/blob/master/src/service/clientConfigService/core.ts): `src/service/clientConfigService/core.ts`

### Other components

- **Admin user**
- **LLM client**
- **Model provider**

## Connections

- Admin user → Web admin UI: uses (evidence: `README.md`)
- Web admin UI → API client: requests
- API client → API routes: calls API
- LLM client → API routes: sends request (evidence: `README.md`)
- API routes → LLM API middleware: routes LLM calls (evidence: `src/routes.ts`)
- API routes → Authentication: registers routes (evidence: `src/routes.ts`)
- LLM API middleware → Authentication: authenticates (evidence: `src/middleware/llmApiMiddleware.ts`)
- LLM API middleware → Tenant scope: resolves scope (evidence: `src/middleware/llmApiMiddleware.ts`)
- LLM API middleware → LLM request service: dispatches (evidence: `src/middleware/llmApiMiddleware.ts`)
- LLM API middleware → Request records: records request (evidence: `src/middleware/llmApiMiddleware.ts`)
- LLM API middleware → Users and rules: checks rules (evidence: `src/middleware/llmApiMiddleware.ts`)
- LLM request service → Upstream sender: sends request
- Upstream sender → Routing strategies: selects upstream (evidence: `src/service/senderService.ts`)
- Upstream sender → Protocol conversion: converts protocol (evidence: `src/service/senderService.ts`)
- Upstream sender → Request rewriters: applies rewrites (evidence: `README.md`)
- Upstream sender → Model provider: forwards request (evidence: `README.md`)
- Model provider → Upstream sender: returns response (evidence: `README.md`)
- Upstream sender → Request records: records result (evidence: `src/service/senderService.ts`)
- Upstream sender → Request activity: logs stages (evidence: `src/service/senderService.ts`)
- Model management → API routes: registered by (evidence: `src/routes.ts`)
- Vendor management → API routes: registered by (evidence: `src/routes.ts`)
- Model management → Upstream sender: configures models (evidence: `src/controller/modelController.ts`)
- Users and rules → Tenant management: scopes users (evidence: `src/service/tenantService.ts`)
- Web admin UI → Client configuration: configures clients (evidence: `README.md`)
- Request records → Payload storage: stores payloads (evidence: `src/service/recordService.ts`)
- Request records → ORM and database: persists records (evidence: `src/service/recordService.ts`)
- Request activity → ORM and database: stores activity
- Payload storage → ORM and database: stores database payloads (evidence: `src/service/objectStorageService.ts`)
- Payload storage → Model provider: uses object storage
- Stats and dashboard → Web admin UI: feeds dashboard
- Stats and dashboard → ORM and database: queries metrics
