# barmispeechlab/ai-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/barmispeechlab/ai-gateway
- Repository: https://github.com/barmispeechlab/ai-gateway

## Overview

This repository is an AI gateway separating the service backend from AI analysis servers. Its principal workflow consumes audio jobs from RabbitMQ, validates job messages, invokes audio analysis, publishes typed results, and deletes processed files. A separate HTTP health-proxy path is also exposed. The graph includes the documented mock AI server, but its runtime connection to the gateway is not established by the sampled source. Evidence is limited to the README and indexed source excerpts.

Main entry points: [`app/main.py`](https://github.com/barmispeechlab/ai-gateway/blob/main/app/main.py) (App Orchestrator), [`app/api/v1/clients/ai_client.py`](https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/clients/ai_client.py) (AI Client), [`app/messaging/consumer.py`](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/consumer.py) (Job Consumers), [`app/messaging/producer.py`](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/producer.py) (Result Producer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_routes["API Routes<br/>[routes.py]"]
  node_health["Gateway Health<br/>[health.py]"]
end

subgraph group_jobs["Job Processing"]
  node_main["App Orchestrator<br/>[main.py]"]
  node_ai_client["AI Client<br/>[ai_client.py]"]
  node_file_service["Audio File Service<br/>[file_service.py]"]
  node_config["Runtime Settings<br/>[config.py]"]
end

subgraph group_messaging["RabbitMQ Messaging"]
  node_consumer["Job Consumers<br/>[consumer.py]"]
  node_schemas["Job Schemas<br/>[schemas.py]"]
  node_rabbit_conn["RabbitMQ Connection<br/>[rabbitmq.py]"]
  node_producer["Result Producer<br/>[producer.py]"]
end

subgraph group_ai["AI Services"]
  node_ai_server["AI Analysis Server"]
  node_mock_ai["Mock AI Server<br/>[mock_ai_server.py]"]
end

node_backend(("Service Backend"))
node_http_user(("Health Caller"))
node_broker["RabbitMQ Broker"]

node_backend -->|"submits jobs"| node_broker
node_broker -->|"delivers jobs"| node_consumer
node_consumer -->|"validates with"| node_schemas
node_consumer -->|"uses connection"| node_rabbit_conn
node_main -->|"starts consumers"| node_consumer
node_consumer -->|"invokes callbacks"| node_main
node_main -->|"requests analysis"| node_ai_client
node_ai_client -->|"reads audio"| node_file_service
node_main -->|"deletes audio"| node_file_service
node_ai_client -->|"posts audio"| node_ai_server
node_main -->|"publishes results"| node_producer
node_producer -->|"uses connection"| node_rabbit_conn
node_producer -->|"publishes results"| node_broker
node_broker -->|"routes results"| node_backend
node_http_user -->|"requests health"| node_routes
node_routes -->|"mounts endpoint"| node_health
node_routes -->|"proxies health"| node_ai_client
node_ai_client -->|"checks health"| node_ai_server
node_main -->|"registers router"| node_routes
node_consumer -->|"reads settings"| node_config
node_producer -->|"reads settings"| node_config
node_ai_client -->|"reads settings"| node_config
node_health -->|"reads settings"| node_config

click node_routes "https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/routes.py"
click node_health "https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/health.py"
click node_main "https://github.com/barmispeechlab/ai-gateway/blob/main/app/main.py"
click node_consumer "https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/consumer.py"
click node_schemas "https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/schemas.py"
click node_rabbit_conn "https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/rabbitmq.py"
click node_ai_client "https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/clients/ai_client.py"
click node_file_service "https://github.com/barmispeechlab/ai-gateway/blob/main/app/services/file_service.py"
click node_producer "https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/producer.py"
click node_mock_ai "https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/mock_ai_server.py"
click node_config "https://github.com/barmispeechlab/ai-gateway/blob/main/app/core/config.py"

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_routes,node_health toneBlue
class node_main,node_ai_client,node_file_service,node_config toneAmber
class node_consumer,node_schemas,node_rabbit_conn,node_producer toneMint
class node_ai_server,node_mock_ai toneRose
class node_backend,node_http_user,node_broker toneIndigo
```

## Components

### HTTP API

- [API Routes](https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/routes.py): `app/api/v1/routes.py`
- [Gateway Health](https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/health.py): `app/api/v1/health.py`

### Job Processing

- [App Orchestrator](https://github.com/barmispeechlab/ai-gateway/blob/main/app/main.py): `app/main.py`
- [AI Client](https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/v1/clients/ai_client.py): `app/api/v1/clients/ai_client.py`
- [Audio File Service](https://github.com/barmispeechlab/ai-gateway/blob/main/app/services/file_service.py): `app/services/file_service.py`
- [Runtime Settings](https://github.com/barmispeechlab/ai-gateway/blob/main/app/core/config.py): `app/core/config.py`

### RabbitMQ Messaging

- [Job Consumers](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/consumer.py): `app/messaging/consumer.py`
- [Job Schemas](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/schemas.py): `app/messaging/schemas.py`
- [RabbitMQ Connection](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/rabbitmq.py): `app/messaging/rabbitmq.py`
- [Result Producer](https://github.com/barmispeechlab/ai-gateway/blob/main/app/messaging/producer.py): `app/messaging/producer.py`

### AI Services

- **AI Analysis Server**
- [Mock AI Server](https://github.com/barmispeechlab/ai-gateway/blob/main/app/api/mock_ai_server.py): `app/api/mock_ai_server.py`

### Other components

- **Service Backend**
- **Health Caller**
- **RabbitMQ Broker**

## Connections

- Service Backend → RabbitMQ Broker: submits jobs
- RabbitMQ Broker → Job Consumers: delivers jobs (evidence: `app/messaging/consumer.py`)
- Job Consumers → Job Schemas: validates with (evidence: `app/messaging/consumer.py`)
- Job Consumers → RabbitMQ Connection: uses connection (evidence: `app/messaging/consumer.py`)
- App Orchestrator → Job Consumers: starts consumers (evidence: `app/main.py`)
- Job Consumers → App Orchestrator: invokes callbacks (evidence: `app/main.py`)
- App Orchestrator → AI Client: requests analysis (evidence: `app/main.py`)
- AI Client → Audio File Service: reads audio (evidence: `app/api/v1/clients/ai_client.py`)
- App Orchestrator → Audio File Service: deletes audio (evidence: `app/main.py`)
- AI Client → AI Analysis Server: posts audio (evidence: `app/api/v1/clients/ai_client.py`)
- App Orchestrator → Result Producer: publishes results (evidence: `app/main.py`)
- Result Producer → RabbitMQ Connection: uses connection (evidence: `app/messaging/producer.py`)
- Result Producer → RabbitMQ Broker: publishes results (evidence: `app/messaging/producer.py`)
- RabbitMQ Broker → Service Backend: routes results
- Health Caller → API Routes: requests health (evidence: `app/api/v1/routes.py`)
- API Routes → Gateway Health: mounts endpoint (evidence: `app/api/v1/routes.py`)
- API Routes → AI Client: proxies health (evidence: `app/api/v1/routes.py`)
- AI Client → AI Analysis Server: checks health (evidence: `app/api/v1/clients/ai_client.py`)
- App Orchestrator → API Routes: registers router (evidence: `app/main.py`)
- Job Consumers → Runtime Settings: reads settings (evidence: `app/messaging/consumer.py`)
- Result Producer → Runtime Settings: reads settings (evidence: `app/messaging/producer.py`)
- AI Client → Runtime Settings: reads settings (evidence: `app/api/v1/clients/ai_client.py`)
- Gateway Health → Runtime Settings: reads settings (evidence: `app/api/v1/health.py`)
