# theschoolofai/glc_v2 architecture

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

- Interactive diagram: https://gitdiagram.com/theschoolofai/glc_v2
- Repository: https://github.com/theschoolofai/glc_v2

## Overview

GLC is an LLM and channel gateway. Its primary workflow is an API client request entering the FastAPI app, reaching chat inference and provider selection, then returning a response; channel adapters separately exchange typed messages and replies through the channel endpoints. The repository also exposes transcription and speech, policy and security controls, usage tracking, and multiple channel integrations. Some subsystem wiring is unsampled, so the graph omits uncertain links rather than inferring calls.

Main entry points: [`glc/main.py`](https://github.com/theschoolofai/glc_v2/blob/main/glc/main.py) (FastAPI App), [`glc/routes/chat.py`](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/chat.py) (Chat Routes), [`glc/routes/channels.py`](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/channels.py) (Channel Routes), [`glc/channels/catalogue/twilio_sms/webhook.py`](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/twilio_sms/webhook.py) (Twilio Webhook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway API"]
  node_app["FastAPI App<br/>[main.py]"]
  node_chat["Chat Routes<br/>[chat.py]"]
  node_channel_routes["Channel Routes<br/>[channels.py]"]
  node_control_routes["Control Routes<br/>[control.py]"]
  node_voice_routes["Voice Routes<br/>[speak.py]"]
  node_transcribe_route["Transcription Route<br/>[transcribe.py]"]
end

subgraph group_inference["LLM Inference"]
  node_providers["LLM Providers<br/>[providers.py]"]
  node_routing["Provider Routing<br/>[routing.py]"]
  node_embedders["Embedders<br/>[embedders.py]"]
  node_pricing["Pricing<br/>[pricing.py]"]
end

subgraph group_channels["Messaging Channels"]
  node_registry["Channel Registry<br/>[registry.py]"]
  node_envelope["Message Envelopes<br/>[envelope.py]"]
  node_adapters["Channel Adapters"]
  node_twilio_sms["Twilio SMS Adapter<br/>[adapter.py]"]
  node_twilio_webhook["Twilio Webhook<br/>[webhook.py]"]
  node_gmail["Gmail Adapter<br/>[adapter.py]"]
end

subgraph group_controls["Security and State"]
  node_db[("Usage Database<br/>[db.py]")]
  node_audit[("Audit Store<br/>[store.py]")]
  node_cache["Cache<br/>[cache.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_policy["Policy Engine<br/>[engine.py]"]
  node_pairing[("Pairing Store<br/>[pairing.py]")]
  node_security["Request Security<br/>[allowlists.py]"]
end

subgraph group_voice["Voice"]
  node_stt["Speech Recognition<br/>[router.py]"]
  node_stt_base["STT Provider API<br/>[base.py]"]
  node_tts["Speech Synthesis<br/>[router.py]"]
end

node_client(("API Client"))

node_client -->|"requests"| node_app
node_app -->|"mounts route"| node_chat
node_app -->|"mounts route"| node_channel_routes
node_app -->|"mounts route"| node_control_routes
node_app -->|"mounts route"| node_voice_routes
node_app -->|"mounts route"| node_transcribe_route
node_chat -->|"selects provider"| node_routing
node_chat -->|"invokes inference"| node_providers
node_chat -->|"logs calls"| node_db
node_chat -->|"uses embeddings"| node_embedders
node_chat -->|"uses pricing"| node_pricing
node_chat -->|"guards image fetches"| node_security
node_channel_routes -->|"instantiates adapters"| node_registry
node_channel_routes -->|"exchanges messages"| node_envelope
node_channel_routes -->|"checks trust"| node_pairing
node_channel_routes -->|"checks access"| node_security
node_registry -.->|"loads adapters"| node_adapters
node_twilio_webhook -->|"validates inbound"| node_twilio_sms
node_twilio_webhook -->|"parses message"| node_envelope
node_twilio_webhook -->|"bridges by WebSocket"| node_channel_routes
node_gmail -.->|"creates messages"| node_envelope
node_app -->|"loads configuration"| node_config
node_app -->|"loads policy"| node_policy
node_app -->|"initializes audit"| node_audit
node_app -->|"initializes cache"| node_cache
node_transcribe_route -.->|"uses transcription"| node_stt
node_stt -->|"routes providers"| node_stt_base
node_voice_routes -.->|"uses synthesis"| node_tts

click node_app "https://github.com/theschoolofai/glc_v2/blob/main/glc/main.py"
click node_chat "https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/chat.py"
click node_channel_routes "https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/channels.py"
click node_control_routes "https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/control.py"
click node_providers "https://github.com/theschoolofai/glc_v2/blob/main/glc/providers.py"
click node_routing "https://github.com/theschoolofai/glc_v2/blob/main/glc/routing.py"
click node_embedders "https://github.com/theschoolofai/glc_v2/blob/main/glc/embedders.py"
click node_pricing "https://github.com/theschoolofai/glc_v2/blob/main/glc/pricing.py"
click node_db "https://github.com/theschoolofai/glc_v2/blob/main/glc/db.py"
click node_audit "https://github.com/theschoolofai/glc_v2/blob/main/glc/audit/store.py"
click node_cache "https://github.com/theschoolofai/glc_v2/blob/main/glc/cache.py"
click node_config "https://github.com/theschoolofai/glc_v2/blob/main/glc/config.py"
click node_policy "https://github.com/theschoolofai/glc_v2/blob/main/glc/policy/engine.py"
click node_pairing "https://github.com/theschoolofai/glc_v2/blob/main/glc/security/pairing.py"
click node_security "https://github.com/theschoolofai/glc_v2/blob/main/glc/security/allowlists.py"
click node_registry "https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/registry.py"
click node_envelope "https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/envelope.py"
click node_adapters "https://github.com/theschoolofai/glc_v2/tree/main/glc/channels/catalogue"
click node_twilio_sms "https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/twilio_sms/adapter.py"
click node_twilio_webhook "https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/twilio_sms/webhook.py"
click node_gmail "https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/gmail/adapter.py"
click node_stt "https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/stt/router.py"
click node_stt_base "https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/stt/base.py"
click node_tts "https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/tts/router.py"
click node_voice_routes "https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/speak.py"
click node_transcribe_route "https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/transcribe.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_app,node_chat,node_channel_routes,node_control_routes,node_voice_routes,node_transcribe_route,node_client toneBlue
class node_providers,node_routing,node_embedders,node_pricing toneAmber
class node_registry,node_envelope,node_adapters,node_twilio_sms,node_twilio_webhook,node_gmail toneMint
class node_db,node_audit,node_cache,node_config,node_policy,node_pairing,node_security toneRose
class node_stt,node_stt_base,node_tts toneIndigo
```

## Components

### Gateway API

- [FastAPI App](https://github.com/theschoolofai/glc_v2/blob/main/glc/main.py): `glc/main.py`
- [Chat Routes](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/chat.py): `glc/routes/chat.py`
- [Channel Routes](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/channels.py): `glc/routes/channels.py`
- [Control Routes](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/control.py): `glc/routes/control.py`
- [Voice Routes](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/speak.py): `glc/routes/speak.py`
- [Transcription Route](https://github.com/theschoolofai/glc_v2/blob/main/glc/routes/transcribe.py): `glc/routes/transcribe.py`

### LLM Inference

- [LLM Providers](https://github.com/theschoolofai/glc_v2/blob/main/glc/providers.py): `glc/providers.py`
- [Provider Routing](https://github.com/theschoolofai/glc_v2/blob/main/glc/routing.py): `glc/routing.py`
- [Embedders](https://github.com/theschoolofai/glc_v2/blob/main/glc/embedders.py): `glc/embedders.py`
- [Pricing](https://github.com/theschoolofai/glc_v2/blob/main/glc/pricing.py): `glc/pricing.py`

### Messaging Channels

- [Channel Registry](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/registry.py): `glc/channels/registry.py`
- [Message Envelopes](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/envelope.py): `glc/channels/envelope.py`
- [Channel Adapters](https://github.com/theschoolofai/glc_v2/tree/main/glc/channels/catalogue): `glc/channels/catalogue`
- [Twilio SMS Adapter](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/twilio_sms/adapter.py): `glc/channels/catalogue/twilio_sms/adapter.py`
- [Twilio Webhook](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/twilio_sms/webhook.py): `glc/channels/catalogue/twilio_sms/webhook.py`
- [Gmail Adapter](https://github.com/theschoolofai/glc_v2/blob/main/glc/channels/catalogue/gmail/adapter.py): `glc/channels/catalogue/gmail/adapter.py`

### Security and State

- [Usage Database](https://github.com/theschoolofai/glc_v2/blob/main/glc/db.py): `glc/db.py`
- [Audit Store](https://github.com/theschoolofai/glc_v2/blob/main/glc/audit/store.py): `glc/audit/store.py`
- [Cache](https://github.com/theschoolofai/glc_v2/blob/main/glc/cache.py): `glc/cache.py`
- [Configuration](https://github.com/theschoolofai/glc_v2/blob/main/glc/config.py): `glc/config.py`
- [Policy Engine](https://github.com/theschoolofai/glc_v2/blob/main/glc/policy/engine.py): `glc/policy/engine.py`
- [Pairing Store](https://github.com/theschoolofai/glc_v2/blob/main/glc/security/pairing.py): `glc/security/pairing.py`
- [Request Security](https://github.com/theschoolofai/glc_v2/blob/main/glc/security/allowlists.py): `glc/security/allowlists.py`

### Voice

- [Speech Recognition](https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/stt/router.py): `glc/voice/stt/router.py`
- [STT Provider API](https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/stt/base.py): `glc/voice/stt/base.py`
- [Speech Synthesis](https://github.com/theschoolofai/glc_v2/blob/main/glc/voice/tts/router.py): `glc/voice/tts/router.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI App: requests (evidence: `README.md`)
- FastAPI App → Chat Routes: mounts route (evidence: `glc/main.py`)
- FastAPI App → Channel Routes: mounts route (evidence: `glc/main.py`)
- FastAPI App → Control Routes: mounts route (evidence: `glc/main.py`)
- FastAPI App → Voice Routes: mounts route (evidence: `glc/main.py`)
- FastAPI App → Transcription Route: mounts route (evidence: `glc/main.py`)
- Chat Routes → Provider Routing: selects provider (evidence: `glc/routes/chat.py`)
- Chat Routes → LLM Providers: invokes inference (evidence: `glc/routes/chat.py`)
- Chat Routes → Usage Database: logs calls (evidence: `glc/routes/chat.py`)
- Chat Routes → Embedders: uses embeddings (evidence: `glc/routes/chat.py`)
- Chat Routes → Pricing: uses pricing (evidence: `glc/routes/chat.py`)
- Chat Routes → Request Security: guards image fetches (evidence: `glc/routes/chat.py`)
- Channel Routes → Channel Registry: instantiates adapters (evidence: `glc/routes/channels.py`)
- Channel Routes → Message Envelopes: exchanges messages (evidence: `glc/routes/channels.py`)
- Channel Routes → Pairing Store: checks trust (evidence: `glc/routes/channels.py`)
- Channel Routes → Request Security: checks access (evidence: `glc/routes/channels.py`)
- Channel Registry → Channel Adapters: loads adapters (evidence: `glc/channels/catalogue/whatsapp/demo_webhook_server.py`)
- Twilio Webhook → Twilio SMS Adapter: validates inbound (evidence: `glc/channels/catalogue/twilio_sms/webhook.py`)
- Twilio Webhook → Message Envelopes: parses message (evidence: `glc/channels/catalogue/twilio_sms/webhook.py`)
- Twilio Webhook → Channel Routes: bridges by WebSocket
- Gmail Adapter → Message Envelopes: creates messages
- FastAPI App → Configuration: loads configuration (evidence: `glc/main.py`)
- FastAPI App → Policy Engine: loads policy (evidence: `glc/main.py`)
- FastAPI App → Audit Store: initializes audit (evidence: `glc/main.py`)
- FastAPI App → Cache: initializes cache (evidence: `glc/main.py`)
- Transcription Route → Speech Recognition: uses transcription
- Speech Recognition → STT Provider API: routes providers (evidence: `glc/voice/stt/router.py`)
- Voice Routes → Speech Synthesis: uses synthesis
