# quantodh/cp-guardrail architecture

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

- Interactive diagram: https://gitdiagram.com/quantodh/cp-guardrail
- Repository: https://github.com/quantodh/cp-guardrail

## Overview

Lumen AI Gateway Lab demonstrates a banking-style assistant protected by layered gateway, agent, and network controls. The main user flow starts in either portal, passes through LiteLLM for model and guardrail enforcement, and returns a response; agentic requests can also reach MCP tools. The POC adds a test-and-score workflow and a RAG path with ingestion screening and query-time retrieval. The graph also preserves documented model, audit, and observability capabilities. Some subsystem links are based on README descriptions because their implementation was not sampled.

Main entry points: [`litellm/config.yaml`](https://github.com/quantodh/cp-guardrail/blob/main/litellm/config.yaml) (LiteLLM Gateway), [`poc/portal/server.py`](https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/server.py) (POC Portal), [`poc/runner.py`](https://github.com/quantodh/cp-guardrail/blob/main/poc/runner.py) (Test Runner), [`poc/rag/ingest.py`](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/ingest.py) (Document Ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontends["User Workflows"]
  node_demo["Demo Console<br/>[app.py]"]
  node_redteam["Red-Team Runner<br/>[redteam.py]"]
  node_pocportal["POC Portal<br/>[server.py]"]
  node_backdrop["Bank Backdrop<br/>[backdrop.py]"]
end

subgraph group_gateway["Gateway Controls"]
  node_gateway["LiteLLM Gateway<br/>[config.yaml]"]
  node_lakera["Lakera Guard"]
  node_customguards["Custom Guardrails<br/>[lakera_tiered.py]"]
  node_mcpguard["MCP Guardrail<br/>[lakera_mcp.py]"]
  node_models["Chat Models"]
  node_postgres[("Gateway PostgreSQL")]
end

subgraph group_tools["Agent Tools"]
  node_mcpclient["Portal MCP Client<br/>[mcpcli.py]"]
  node_mcpservers["MCP Servers"]
  node_squid["Egress Proxy"]
end

subgraph group_rag["POC RAG"]
  node_ragingest["Document Ingestion<br/>[ingest.py]"]
  node_ragretrieve["Query Retrieval<br/>[retrieve.py]"]
  node_ragembed["Embedding Client<br/>[embed.py]"]
  node_ragstore[("Vector Store<br/>[store.py]")]
  node_ragconfig["RAG Settings<br/>[config.py]"]
  node_ollama["Ollama"]
  node_qdrant[("Qdrant")]
end

subgraph group_evidence["Testing Evidence"]
  node_runner["Test Runner<br/>[runner.py]"]
  node_levels["Level Calibration<br/>[find_levels.py]"]
  node_observability["Audit &amp; Observability"]
end

node_user(("User"))
node_lakera_saas["Lakera Service"]

node_user -->|"uses"| node_demo
node_user -->|"uses"| node_pocportal
node_demo -->|"sends requests"| node_gateway
node_redteam -->|"posts samples"| node_demo
node_pocportal -->|"runs tests"| node_runner
node_pocportal -->|"uses context"| node_backdrop
node_pocportal -->|"calls tools"| node_mcpclient
node_pocportal -->|"ingests documents"| node_ragingest
node_pocportal -->|"queries documents"| node_ragretrieve
node_pocportal -->|"sends requests"| node_gateway
node_gateway -->|"screens content"| node_lakera
node_gateway -->|"applies policies"| node_customguards
node_gateway -->|"screens tool traffic"| node_mcpguard
node_gateway -->|"routes inference"| node_models
node_gateway -->|"stores keys and logs"| node_postgres
node_lakera -->|"requests verdicts"| node_lakera_saas
node_mcpclient -->|"routes guarded calls"| node_gateway
node_mcpclient -->|"calls directly"| node_mcpservers
node_gateway -->|"dispatches tools"| node_mcpservers
node_mcpservers -->|"fetches through"| node_squid
node_ragingest -->|"screens documents"| node_runner
node_ragingest -->|"embeds chunks"| node_ragembed
node_ragingest -->|"indexes chunks"| node_ragstore
node_ragretrieve -->|"embeds query"| node_ragembed
node_ragretrieve -->|"searches vectors"| node_ragstore
node_ragembed -->|"requests embeddings"| node_ollama
node_ragstore -->|"reads and writes"| node_qdrant
node_ragingest -->|"reads settings"| node_ragconfig
node_ragretrieve -->|"reads settings"| node_ragconfig
node_ragembed -->|"reads settings"| node_ragconfig
node_ragstore -->|"reads settings"| node_ragconfig
node_runner -->|"tests enforcement"| node_gateway
node_runner -->|"checks verdicts"| node_lakera_saas
node_levels -->|"measures policy levels"| node_runner
node_runner -->|"records evidence"| node_observability

click node_demo "https://github.com/quantodh/cp-guardrail/blob/main/demo-console/app.py"
click node_redteam "https://github.com/quantodh/cp-guardrail/blob/main/demo-console/redteam.py"
click node_pocportal "https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/server.py"
click node_backdrop "https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/backdrop.py"
click node_gateway "https://github.com/quantodh/cp-guardrail/blob/main/litellm/config.yaml"
click node_customguards "https://github.com/quantodh/cp-guardrail/blob/main/litellm/lakera_tiered.py"
click node_mcpguard "https://github.com/quantodh/cp-guardrail/blob/main/litellm/lakera_mcp.py"
click node_mcpclient "https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/mcpcli.py"
click node_mcpservers "https://github.com/quantodh/cp-guardrail/tree/main/mcp-servers"
click node_squid "https://github.com/quantodh/cp-guardrail/tree/main/egress-proxy"
click node_ragingest "https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/ingest.py"
click node_ragretrieve "https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/retrieve.py"
click node_ragembed "https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/embed.py"
click node_ragstore "https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/store.py"
click node_ragconfig "https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/config.py"
click node_runner "https://github.com/quantodh/cp-guardrail/blob/main/poc/runner.py"
click node_levels "https://github.com/quantodh/cp-guardrail/blob/main/poc/find_levels.py"
click node_observability "https://github.com/quantodh/cp-guardrail/tree/main/poc/observability"

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_demo,node_redteam,node_pocportal,node_backdrop,node_user toneBlue
class node_gateway,node_lakera,node_customguards,node_mcpguard,node_models,node_postgres toneAmber
class node_mcpclient,node_mcpservers,node_squid toneMint
class node_ragingest,node_ragretrieve,node_ragembed,node_ragstore,node_ragconfig,node_ollama,node_qdrant toneRose
class node_runner,node_levels,node_observability,node_lakera_saas toneIndigo
```

## Components

### User Workflows

- [Demo Console](https://github.com/quantodh/cp-guardrail/blob/main/demo-console/app.py): `demo-console/app.py`
- [Red-Team Runner](https://github.com/quantodh/cp-guardrail/blob/main/demo-console/redteam.py): `demo-console/redteam.py`
- [POC Portal](https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/server.py): `poc/portal/server.py`
- [Bank Backdrop](https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/backdrop.py): `poc/portal/backdrop.py`

### Gateway Controls

- [LiteLLM Gateway](https://github.com/quantodh/cp-guardrail/blob/main/litellm/config.yaml): `litellm/config.yaml`
- **Lakera Guard**
- [Custom Guardrails](https://github.com/quantodh/cp-guardrail/blob/main/litellm/lakera_tiered.py): `litellm/lakera_tiered.py`
- [MCP Guardrail](https://github.com/quantodh/cp-guardrail/blob/main/litellm/lakera_mcp.py): `litellm/lakera_mcp.py`
- **Chat Models**
- **Gateway PostgreSQL**

### Agent Tools

- [Portal MCP Client](https://github.com/quantodh/cp-guardrail/blob/main/poc/portal/mcpcli.py): `poc/portal/mcpcli.py`
- [MCP Servers](https://github.com/quantodh/cp-guardrail/tree/main/mcp-servers): `mcp-servers`
- [Egress Proxy](https://github.com/quantodh/cp-guardrail/tree/main/egress-proxy): `egress-proxy`

### POC RAG

- [Document Ingestion](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/ingest.py): `poc/rag/ingest.py`
- [Query Retrieval](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/retrieve.py): `poc/rag/retrieve.py`
- [Embedding Client](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/embed.py): `poc/rag/embed.py`
- [Vector Store](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/store.py): `poc/rag/store.py`
- [RAG Settings](https://github.com/quantodh/cp-guardrail/blob/main/poc/rag/config.py): `poc/rag/config.py`
- **Ollama**
- **Qdrant**

### Testing Evidence

- [Test Runner](https://github.com/quantodh/cp-guardrail/blob/main/poc/runner.py): `poc/runner.py`
- [Level Calibration](https://github.com/quantodh/cp-guardrail/blob/main/poc/find_levels.py): `poc/find_levels.py`
- [Audit & Observability](https://github.com/quantodh/cp-guardrail/tree/main/poc/observability): `poc/observability`

### Other components

- **User**
- **Lakera Service**

## Connections

- User → Demo Console: uses (evidence: `README.md`)
- User → POC Portal: uses (evidence: `README.md`)
- Demo Console → LiteLLM Gateway: sends requests (evidence: `README.md`)
- Red-Team Runner → Demo Console: posts samples (evidence: `demo-console/redteam.py`)
- POC Portal → Test Runner: runs tests (evidence: `poc/portal/server.py`)
- POC Portal → Bank Backdrop: uses context (evidence: `poc/portal/server.py`)
- POC Portal → Portal MCP Client: calls tools (evidence: `poc/portal/server.py`)
- POC Portal → Document Ingestion: ingests documents (evidence: `poc/portal/server.py`)
- POC Portal → Query Retrieval: queries documents (evidence: `poc/portal/server.py`)
- POC Portal → LiteLLM Gateway: sends requests (evidence: `README.md`)
- LiteLLM Gateway → Lakera Guard: screens content (evidence: `README.md`)
- LiteLLM Gateway → Custom Guardrails: applies policies (evidence: `README.md`)
- LiteLLM Gateway → MCP Guardrail: screens tool traffic (evidence: `README.md`)
- LiteLLM Gateway → Chat Models: routes inference (evidence: `README.md`)
- LiteLLM Gateway → Gateway PostgreSQL: stores keys and logs (evidence: `README.md`)
- Lakera Guard → Lakera Service: requests verdicts (evidence: `README.md`)
- Portal MCP Client → LiteLLM Gateway: routes guarded calls (evidence: `poc/portal/mcpcli.py`)
- Portal MCP Client → MCP Servers: calls directly (evidence: `poc/portal/mcpcli.py`)
- LiteLLM Gateway → MCP Servers: dispatches tools (evidence: `README.md`)
- MCP Servers → Egress Proxy: fetches through (evidence: `README.md`)
- Document Ingestion → Test Runner: screens documents (evidence: `poc/rag/ingest.py`)
- Document Ingestion → Embedding Client: embeds chunks (evidence: `poc/rag/ingest.py`)
- Document Ingestion → Vector Store: indexes chunks (evidence: `poc/rag/ingest.py`)
- Query Retrieval → Embedding Client: embeds query (evidence: `poc/rag/retrieve.py`)
- Query Retrieval → Vector Store: searches vectors (evidence: `poc/rag/retrieve.py`)
- Embedding Client → Ollama: requests embeddings (evidence: `poc/rag/embed.py`)
- Vector Store → Qdrant: reads and writes (evidence: `poc/rag/store.py`)
- Document Ingestion → RAG Settings: reads settings (evidence: `poc/rag/ingest.py`)
- Query Retrieval → RAG Settings: reads settings (evidence: `poc/rag/retrieve.py`)
- Embedding Client → RAG Settings: reads settings (evidence: `poc/rag/embed.py`)
- Vector Store → RAG Settings: reads settings (evidence: `poc/rag/store.py`)
- Test Runner → LiteLLM Gateway: tests enforcement (evidence: `poc/runner.py`)
- Test Runner → Lakera Service: checks verdicts (evidence: `poc/runner.py`)
- Level Calibration → Test Runner: measures policy levels (evidence: `poc/find_levels.py`)
- Test Runner → Audit & Observability: records evidence (evidence: `README.md`)
