# affinidi/affinidi-labs-tgw-get-started architecture

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

- Interactive diagram: https://gitdiagram.com/affinidi/affinidi-labs-tgw-get-started
- Repository: https://github.com/affinidi/affinidi-labs-tgw-get-started

## Overview

#### Purpose and Scope
This is an evaluation/learning repository for Affinidi Agent Gateway (the Rust-hosted product itself is external). It supplies runnable protocol endpoints, clients, identity/delegation demos, observability setup, and cross-organization labs. The gateway is the control boundary: it inspects A2A/MCP traffic, applies configured routing, identity, authentication and policies, then forwards to local or cloud agents.

#### Baseline A2A Flow
The local A2A echo agent and interactive client establish the simplest agent-to-agent path. The server exposes an agent card, health endpoint, and messaging endpoint; a client can call it directly or through a gateway A2A surface.
- `a2a/a2a_server.py`
- `a2a/a2a_client.py`
- `a2a/run.sh`

#### Baseline MCP Flow
The MCP sample is a JSON-RPC tool server with calculator and mock weather capabilities. Its client initializes the MCP session, discovers tools, and invokes them. Gateway configuration replaces the direct server URL with a governed MCP route, making the gateway responsible for ingress controls and upstream forwarding.
- `mcp/mcp_server.py`
- `mcp/mcp_client.py`
- `mcp/enable-auth.md`

#### Cloud Agent and REST Adapters
A separate A2A agent definition can be tested locally and deployed to Google Cloud Vertex AI Agent Engine; its client continues to use Vertex management APIs while A2A messaging can traverse the gateway. A REST server also acts as an MCP proxy, demonstrating protocol/API integration rather than a standalone agent.
- `a2a-vertex-agent/agent.py`
- `a2a-vertex-agent/deploy.py`
- `rest-api/api_server.py`

#### Agent Identity and Trust
The multi-agent identity lab publishes Personal and Finance A2A agents with identity-extension declarations. When an Agent Gateway surface enables identity, it issues `did:webvh`-based signed verifiable presentations and injects them into agent-card and message responses. Cross-org examples model two gateway configurations connected through trust/policy controls, with Rego policies defining admission, routing, acknowledgment, and user-scope behavior.
- `a2a-agent-identity/agents.py`
- `a2a-agent-identity/identity-extension.json`
- `use-cases/secure-agent-communication/gateway-config/policies/`

#### OAuth Delegation Chat Surface
`auth0-mcp-surface` is a full browser-facing reference surface: static Astro frontend calls a FastAPI backend, which serves the built UI and mediates MCP requests. Google OAuth supplies caller context; Agent Gateway validates that context and delegates Auth0 credentials to the protected upstream MCP service, including consent-oriented flows. Docker Compose supports a single-container deployment, while development can use separate frontend/backend processes.
- `auth0-mcp-surface/backend/main.py`
- `auth0-mcp-surface/frontend/src/pages/chat.astro`
- `auth0-mcp-surface/docker-compose.yml`

#### Cross-Organization Portal Scenario
The secure-agent-communication lab has Python agents plus a Next.js portal for interactive direct and gateway-mediated A2A communication. Portal API routes handle Microsoft/Entra authentication, outgoing chat, and incoming messages. Gateway JSON surfaces and Rego policies are externalized so organizations can independently configure trust and transit rules.
- `use-cases/secure-agent-communication/agent/agent.py`
- `use-cases/secure-agent-communication/portal/src/app/api/chat/route.ts`
- `use-cases/secure-agent-communication/gateway-config/`

#### Operations and External Boundaries
Python 3.10+ is the main sample runtime; TypeScript runs Astro and Next.js UIs; Docker runs observability and chat-surface deployments. Public reachability is supplied by ngrok or GitHub Codespaces port forwarding for local upstreams. Prometheus directly scrapes the external gateway metrics endpoint, while Grafana provisions dashboards from that data. Other material external services are Affinidi Developer Portal/Agent Gateway, Google Cloud Vertex AI and Gemini, Google OAuth, Auth0 OAuth, Microsoft Entra, and Copilot Studio Direct Line.
- `gateway-prometheus-integration/docker-compose.yml`
- `gateway-prometheus-integration/prometheus.yml.template`
- `use-cases/copilot-studio-agent-communication/gateway-config/`

Main entry points: [`auth0-mcp-surface/backend/main.py`](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/backend/main.py) (OAuth chat backend), [`mcp/mcp_server.py`](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_server.py) (MCP tool server), [`a2a/a2a_client.py`](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a/a2a_client.py) (A2A interactive client), [`mcp/mcp_client.py`](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_client.py) (MCP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_baseline["Protocol samples"]
  node_a2a_client["A2A interactive client<br/>Python client<br/>[a2a_client.py]"]
  node_a2a_echo["A2A echo agent<br/>Python A2A server<br/>[a2a_server.py]"]
  node_mcp_client["MCP client<br/>Python client<br/>[mcp_client.py]"]
  node_mcp_server["MCP tool server<br/>JSON-RPC MCP server<br/>[mcp_server.py]"]
end

subgraph group_cloud["Cloud and adapters"]
  node_vertex_agent["Vertex A2A agent<br/>Python agent definition<br/>[agent.py]"]
  node_vertex_deploy["Vertex deployment<br/>Python deployer<br/>[deploy.py]"]
  node_vertex_ai{{"Vertex AI Agent Engine<br/>Google Cloud service"}}
  node_rest_proxy["REST-to-MCP proxy<br/>Python REST server<br/>[api_server.py]"]
end

subgraph group_identity["Identity and cross-org"]
  node_identity_agents["Personal and Finance agents<br/>Python A2A agents<br/>[agents.py]"]
  node_identity_extension["Identity extension<br/>A2A declaration"]
  node_cross_org_agents["Cross-org agents<br/>Python A2A agents<br/>[agent.py]"]
  node_cross_org_portal["Cross-org portal API<br/>Next.js API route<br/>[route.ts]"]
  node_gateway_surfaces["Cross-org gateway surfaces<br/>Gateway configuration"]
  node_rego_policies["Trust and routing policies<br/>Rego policies"]
end

subgraph group_delegation["OAuth delegation surface"]
  node_chat_frontend["OAuth chat frontend<br/>Astro browser UI<br/>[chat.astro]"]
  node_chat_backend["OAuth chat backend<br/>FastAPI backend<br/>[main.py]"]
  node_auth0_surface_deploy["Chat surface deployment<br/>Docker Compose<br/>[docker-compose.yml]"]
  node_oauth_providers{{"Google OAuth and Auth0<br/>External identity providers"}}
end

subgraph group_operations["Operations"]
  node_observability["Prometheus and Grafana<br/>Docker observability stack<br/>[docker-compose.yml]"]
  node_prometheus_config["Prometheus scrape config<br/>Configuration template"]
  node_copilot_surfaces["Copilot gateway surfaces<br/>Gateway configuration"]
end

node_gateway{{"Affinidi Agent Gateway<br/>External control plane"}}

node_a2a_client -->|"direct A2A"| node_a2a_echo
node_a2a_client -->|"governed A2A"| node_gateway
node_gateway -->|"forwards A2A"| node_a2a_echo
node_mcp_client -->|"direct MCP"| node_mcp_server
node_mcp_client -->|"governed MCP"| node_gateway
node_gateway -->|"forwards MCP"| node_mcp_server
node_vertex_deploy -->|"deploys"| node_vertex_ai
node_vertex_ai -->|"hosts"| node_vertex_agent
node_gateway -->|"routes A2A messaging"| node_vertex_ai
node_rest_proxy -->|"proxies MCP"| node_mcp_server
node_identity_agents -.->|"declares"| node_identity_extension
node_gateway -->|"issues identity presentations"| node_identity_agents
node_cross_org_portal -->|"gateway-mediated chat"| node_gateway
node_gateway_surfaces -.->|"configures surfaces"| node_gateway
node_rego_policies -.->|"governs"| node_gateway_surfaces
node_gateway -->|"routes cross-org A2A"| node_cross_org_agents
node_chat_frontend -->|"browser requests"| node_chat_backend
node_chat_backend -->|"obtains caller context"| node_oauth_providers
node_chat_backend -->|"mediates MCP"| node_gateway
node_gateway -->|"validates and delegates OAuth"| node_oauth_providers
node_auth0_surface_deploy -.->|"deploys"| node_chat_backend
node_prometheus_config -.->|"configures scrape"| node_observability
node_observability -->|"scrapes metrics"| node_gateway
node_copilot_surfaces -.->|"configures Direct Line routes"| node_gateway

click node_a2a_client "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a/a2a_client.py"
click node_a2a_echo "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a/a2a_server.py"
click node_mcp_client "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_client.py"
click node_mcp_server "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_server.py"
click node_vertex_agent "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-vertex-agent/agent.py"
click node_vertex_deploy "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-vertex-agent/deploy.py"
click node_rest_proxy "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/rest-api/api_server.py"
click node_identity_agents "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-agent-identity/agents.py"
click node_identity_extension "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-agent-identity/identity-extension.json"
click node_cross_org_agents "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/use-cases/secure-agent-communication/agent/agent.py"
click node_cross_org_portal "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/use-cases/secure-agent-communication/portal/src/app/api/chat/route.ts"
click node_chat_frontend "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/frontend/src/pages/chat.astro"
click node_chat_backend "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/backend/main.py"
click node_auth0_surface_deploy "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/docker-compose.yml"
click node_observability "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/gateway-prometheus-integration/docker-compose.yml"
click node_prometheus_config "https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/gateway-prometheus-integration/prometheus.yml.template"

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_a2a_client,node_a2a_echo,node_mcp_client,node_mcp_server toneBlue
class node_vertex_agent,node_vertex_deploy,node_vertex_ai,node_rest_proxy toneAmber
class node_identity_agents,node_identity_extension,node_cross_org_agents,node_cross_org_portal,node_gateway_surfaces,node_rego_policies toneMint
class node_chat_frontend,node_chat_backend,node_auth0_surface_deploy,node_oauth_providers toneRose
class node_observability,node_prometheus_config,node_copilot_surfaces toneIndigo
class node_gateway toneNeutral
```

## Components

### Protocol samples

- [A2A interactive client](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a/a2a_client.py): Python client · `a2a/a2a_client.py`
- [A2A echo agent](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a/a2a_server.py): Python A2A server · Serves agent card, health, and messaging. · `a2a/a2a_server.py`
- [MCP client](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_client.py): Python client · Initializes sessions, discovers tools, and invokes them. · `mcp/mcp_client.py`
- [MCP tool server](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/mcp/mcp_server.py): JSON-RPC MCP server · Provides calculator and mock weather tools. · `mcp/mcp_server.py`

### Cloud and adapters

- [Vertex A2A agent](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-vertex-agent/agent.py): Python agent definition · `a2a-vertex-agent/agent.py`
- [Vertex deployment](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-vertex-agent/deploy.py): Python deployer · `a2a-vertex-agent/deploy.py`
- **Vertex AI Agent Engine**: Google Cloud service
- [REST-to-MCP proxy](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/rest-api/api_server.py): Python REST server · Demonstrates protocol/API integration. · `rest-api/api_server.py`

### Identity and cross-org

- [Personal and Finance agents](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-agent-identity/agents.py): Python A2A agents · Publish identity-extension declarations. · `a2a-agent-identity/agents.py`
- [Identity extension](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/a2a-agent-identity/identity-extension.json): A2A declaration · `a2a-agent-identity/identity-extension.json`
- [Cross-org agents](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/use-cases/secure-agent-communication/agent/agent.py): Python A2A agents · `use-cases/secure-agent-communication/agent/agent.py`
- [Cross-org portal API](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/use-cases/secure-agent-communication/portal/src/app/api/chat/route.ts): Next.js API route · Handles Entra-authenticated chat and incoming messages. · `use-cases/secure-agent-communication/portal/src/app/api/chat/route.ts`
- **Cross-org gateway surfaces**: Gateway configuration · Organizations configure independent trust and transit surfaces.
- **Trust and routing policies**: Rego policies · Controls admission, routing, acknowledgments, and user scope.

### OAuth delegation surface

- [OAuth chat frontend](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/frontend/src/pages/chat.astro): Astro browser UI · `auth0-mcp-surface/frontend/src/pages/chat.astro`
- [OAuth chat backend](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/backend/main.py): FastAPI backend · Serves the UI and mediates MCP requests. · `auth0-mcp-surface/backend/main.py`
- [Chat surface deployment](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/auth0-mcp-surface/docker-compose.yml): Docker Compose · Supports single-container deployment. · `auth0-mcp-surface/docker-compose.yml`
- **Google OAuth and Auth0**: External identity providers · Google supplies caller context; Auth0 credentials are delegated upstream.

### Operations

- [Prometheus and Grafana](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/gateway-prometheus-integration/docker-compose.yml): Docker observability stack · Prometheus scrapes gateway metrics and Grafana visualizes them. · `gateway-prometheus-integration/docker-compose.yml`
- [Prometheus scrape config](https://github.com/affinidi/affinidi-labs-tgw-get-started/blob/main/gateway-prometheus-integration/prometheus.yml.template): Configuration template · `gateway-prometheus-integration/prometheus.yml.template`
- **Copilot gateway surfaces**: Gateway configuration

### Other components

- **Affinidi Agent Gateway**: External control plane · Enforces routing, auth, identity, and policy before forwarding traffic.

## Connections

- A2A interactive client → A2A echo agent: direct A2A
- A2A interactive client → Affinidi Agent Gateway: governed A2A
- Affinidi Agent Gateway → A2A echo agent: forwards A2A
- MCP client → MCP tool server: direct MCP
- MCP client → Affinidi Agent Gateway: governed MCP
- Affinidi Agent Gateway → MCP tool server: forwards MCP
- Vertex deployment → Vertex AI Agent Engine: deploys
- Vertex AI Agent Engine → Vertex A2A agent: hosts
- Affinidi Agent Gateway → Vertex AI Agent Engine: routes A2A messaging
- REST-to-MCP proxy → MCP tool server: proxies MCP
- Personal and Finance agents → Identity extension: declares
- Affinidi Agent Gateway → Personal and Finance agents: issues identity presentations
- Cross-org portal API → Affinidi Agent Gateway: gateway-mediated chat
- Cross-org gateway surfaces → Affinidi Agent Gateway: configures surfaces
- Trust and routing policies → Cross-org gateway surfaces: governs
- Affinidi Agent Gateway → Cross-org agents: routes cross-org A2A
- OAuth chat frontend → OAuth chat backend: browser requests
- OAuth chat backend → Google OAuth and Auth0: obtains caller context
- OAuth chat backend → Affinidi Agent Gateway: mediates MCP
- Affinidi Agent Gateway → Google OAuth and Auth0: validates and delegates OAuth
- Chat surface deployment → OAuth chat backend: deploys
- Prometheus scrape config → Prometheus and Grafana: configures scrape
- Prometheus and Grafana → Affinidi Agent Gateway: scrapes metrics
- Copilot gateway surfaces → Affinidi Agent Gateway: configures Direct Line routes
