# neuraltrust/trustgate architecture

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

- Interactive diagram: https://gitdiagram.com/neuraltrust/trustgate
- Repository: https://github.com/neuraltrust/trustgate

## Overview

TrustGate is a security-focused gateway for LLM, MCP, and A2A traffic, with a shared administration plane. The principal runtime flow authenticates an application or agent, applies routing and policy decisions, forwards requests to an upstream, and observes the result. Administration configures gateways, registries, consumers, identity, and policies; configuration can be synchronized to data planes. The README documents these plane-level relationships; sampled source confirms selected routing, admin-handler, and telemetry behavior, but not every internal connection shown here.

Main entry points: [`pkg/api/handler/http/proxy/proxy_handler.go`](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/proxy/proxy_handler.go) (Proxy request handling), [`pkg/server/router/admin_router.go`](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/admin_router.go) (Admin API), [`pkg/app/configsnapshot/dispatcher.go`](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/configsnapshot/dispatcher.go) (Config synchronization), [`pkg/server/router/proxy_router.go`](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/proxy_router.go) (Proxy API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_admin["Administration"]
  node_admin_ui["Admin dashboard<br/>[page.tsx]"]
  node_admin_router["Admin API<br/>[admin_router.go]"]
  node_gateway_registry["Gateway and registry management"]
  node_identity_admin["Identity and key management<br/>[llm_key_handler.go]"]
  node_policies["Policy management"]
  node_catalog["Provider and model catalog<br/>[service.go]"]
end

subgraph group_proxy["LLM Proxy"]
  node_proxy_router["Proxy API<br/>[proxy_router.go]"]
  node_proxy_handler["Proxy request handling<br/>[proxy_handler.go]"]
  node_routing["Model routing<br/>[routing.go]"]
  node_proxy_policies["Policy stages<br/>[stages.go]"]
  node_provider_calls["Provider forwarding<br/>[forwarder.go]"]
end

subgraph group_agent_tools["MCP and A2A"]
  node_mcp_router["MCP API<br/>[mcp_router.go]"]
  node_mcp_runtime["MCP tool aggregation<br/>[composer.go]"]
  node_a2a_runtime["A2A agent forwarding<br/>[forwarder.go]"]
end

subgraph group_shared["Shared Services"]
  node_config_sync["Config synchronization<br/>[dispatcher.go]"]
  node_identity_runtime["Request identity<br/>[auth_chain.go]"]
  node_telemetry["Telemetry pipeline<br/>[pipeline.go]"]
end

node_apps(("Applications"))
node_agents(("MCP and A2A clients"))
node_llm_providers["LLM providers"]
node_mcp_servers["MCP and OpenAPI services"]
node_a2a_agents["A2A agents"]
node_postgres[("Postgres")]
node_redis[("Redis")]
node_otel["OTLP collectors"]

node_apps -->|"send requests"| node_proxy_router
node_proxy_router -->|"routes requests"| node_proxy_handler
node_proxy_handler -->|"authenticates"| node_identity_runtime
node_proxy_handler -->|"routes models"| node_routing
node_proxy_handler -->|"applies policies"| node_proxy_policies
node_proxy_handler -->|"forwards requests"| node_provider_calls
node_provider_calls -->|"calls provider"| node_llm_providers
node_agents -->|"send tool calls"| node_mcp_router
node_mcp_router -->|"dispatches MCP"| node_mcp_runtime
node_mcp_runtime -->|"aggregates tools"| node_mcp_servers
node_agents -->|"send A2A calls"| node_a2a_runtime
node_a2a_runtime -->|"forwards tasks"| node_a2a_agents
node_admin_ui -.->|"manage gateway"| node_admin_router
node_admin_router -->|"routes management"| node_gateway_registry
node_admin_router -.->|"routes key operations"| node_identity_admin
node_admin_router -->|"routes policy operations"| node_policies
node_admin_router -.->|"provides catalog"| node_catalog
node_admin_router -.->|"persists configuration"| node_postgres
node_config_sync -.->|"supplies configuration"| node_proxy_router
node_config_sync -.->|"supplies configuration"| node_mcp_router
node_config_sync -.->|"supplies configuration"| node_a2a_runtime
node_proxy_handler -.->|"records activity"| node_telemetry
node_telemetry -->|"exports telemetry"| node_otel
node_proxy_handler -.->|"uses runtime state"| node_redis

click node_admin_ui "https://github.com/NeuralTrust/TrustGate/blob/main/frontend/src/app/dashboard/page.tsx"
click node_admin_router "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/admin_router.go"
click node_gateway_registry "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/registry/preview_agent_card_handler.go"
click node_identity_admin "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/store/llm_key_handler.go"
click node_policies "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/policy/create_policy_handler.go"
click node_catalog "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/catalog/service.go"
click node_config_sync "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/configsnapshot/dispatcher.go"
click node_proxy_router "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/proxy_router.go"
click node_proxy_handler "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/proxy/proxy_handler.go"
click node_identity_runtime "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/middleware/auth_chain.go"
click node_routing "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/proxy/routing.go"
click node_proxy_policies "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/plugins/stages.go"
click node_provider_calls "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/proxy/forwarder.go"
click node_mcp_router "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/mcp_router.go"
click node_mcp_runtime "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/mcp/composer.go"
click node_a2a_runtime "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/a2a/forwarder.go"
click node_telemetry "https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/metrics/pipeline.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_admin_ui,node_admin_router,node_gateway_registry,node_identity_admin,node_policies,node_catalog,node_agents toneBlue
class node_proxy_router,node_proxy_handler,node_routing,node_proxy_policies,node_provider_calls,node_postgres,node_redis toneAmber
class node_mcp_router,node_mcp_runtime,node_a2a_runtime,node_mcp_servers toneMint
class node_config_sync,node_identity_runtime,node_telemetry toneRose
class node_apps,node_llm_providers,node_a2a_agents,node_otel toneIndigo
```

## Components

### Administration

- [Admin dashboard](https://github.com/NeuralTrust/TrustGate/blob/main/frontend/src/app/dashboard/page.tsx): `frontend/src/app/dashboard/page.tsx`
- [Admin API](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/admin_router.go): `pkg/server/router/admin_router.go`
- [Gateway and registry management](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/registry/preview_agent_card_handler.go): `pkg/api/handler/http/registry/preview_agent_card_handler.go`
- [Identity and key management](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/store/llm_key_handler.go): `pkg/api/handler/http/store/llm_key_handler.go`
- [Policy management](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/policy/create_policy_handler.go): `pkg/api/handler/http/policy/create_policy_handler.go`
- [Provider and model catalog](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/catalog/service.go): `pkg/app/catalog/service.go`

### LLM Proxy

- [Proxy API](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/proxy_router.go): `pkg/server/router/proxy_router.go`
- [Proxy request handling](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/handler/http/proxy/proxy_handler.go): `pkg/api/handler/http/proxy/proxy_handler.go`
- [Model routing](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/proxy/routing.go): `pkg/app/proxy/routing.go`
- [Policy stages](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/plugins/stages.go): `pkg/app/plugins/stages.go`
- [Provider forwarding](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/proxy/forwarder.go): `pkg/app/proxy/forwarder.go`

### MCP and A2A

- [MCP API](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/server/router/mcp_router.go): `pkg/server/router/mcp_router.go`
- [MCP tool aggregation](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/mcp/composer.go): `pkg/app/mcp/composer.go`
- [A2A agent forwarding](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/a2a/forwarder.go): `pkg/app/a2a/forwarder.go`

### Shared Services

- [Config synchronization](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/configsnapshot/dispatcher.go): `pkg/app/configsnapshot/dispatcher.go`
- [Request identity](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/api/middleware/auth_chain.go): `pkg/api/middleware/auth_chain.go`
- [Telemetry pipeline](https://github.com/NeuralTrust/TrustGate/blob/main/pkg/app/metrics/pipeline.go): `pkg/app/metrics/pipeline.go`

### Other components

- **Applications**
- **MCP and A2A clients**
- **LLM providers**
- **MCP and OpenAPI services**
- **A2A agents**
- **Postgres**
- **Redis**
- **OTLP collectors**

## Connections

- Applications → Proxy API: send requests
- Proxy API → Proxy request handling: routes requests
- Proxy request handling → Request identity: authenticates
- Proxy request handling → Model routing: routes models
- Proxy request handling → Policy stages: applies policies
- Proxy request handling → Provider forwarding: forwards requests
- Provider forwarding → LLM providers: calls provider
- MCP and A2A clients → MCP API: send tool calls
- MCP API → MCP tool aggregation: dispatches MCP
- MCP tool aggregation → MCP and OpenAPI services: aggregates tools
- MCP and A2A clients → A2A agent forwarding: send A2A calls
- A2A agent forwarding → A2A agents: forwards tasks
- Admin dashboard → Admin API: manage gateway
- Admin API → Gateway and registry management: routes management (evidence: `pkg/server/router/admin_router.go`)
- Admin API → Identity and key management: routes key operations
- Admin API → Policy management: routes policy operations (evidence: `pkg/server/router/admin_router.go`)
- Admin API → Provider and model catalog: provides catalog
- Admin API → Postgres: persists configuration
- Config synchronization → Proxy API: supplies configuration
- Config synchronization → MCP API: supplies configuration
- Config synchronization → A2A agent forwarding: supplies configuration
- Proxy request handling → Telemetry pipeline: records activity
- Telemetry pipeline → OTLP collectors: exports telemetry
- Proxy request handling → Redis: uses runtime state
