# taladari/rag-firewall architecture

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

- Interactive diagram: https://gitdiagram.com/taladari/rag-firewall
- Repository: https://github.com/taladari/rag-firewall

## Overview

RAG Integrity Firewall is a client-side retrieval-time security layer: it evaluates retrieved documents, blocks denied content, and reranks the rest before they reach an LLM. It also sanitizes knowledge-graph retrievals and offers indexing/query CLI capabilities. The graph preserves the documented scanner, policy, provenance, audit, and integration branches. Some subsystems are represented from README or SOURCE INDEX references rather than sampled implementation excerpts, so unsupported internal links are omitted.

Main entry points: [`rag_firewall/firewall.py`](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/firewall.py) (Firewall), [`rag_firewall/graph/wrapper.py`](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/wrapper.py) (Graph Firewall), [`rag_firewall/integrations/graph/networkx_adapter.py`](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/graph/networkx_adapter.py) (NetworkX Adapter), [`rag_firewall/integrations/langchain.py`](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/langchain.py) (LangChain Adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_retrieval["Document Retrieval"]
  node_base_retriever["Base Retriever"]
  node_langchain["LangChain Adapter<br/>[langchain.py]"]
  node_llamaindex["LlamaIndex Adapter<br/>[llamaindex.py]"]
end

subgraph group_enforcement["Firewall Enforcement"]
  node_firewall["Firewall<br/>[firewall.py]"]
  node_policy["Policy Engine<br/>[engine.py]"]
  node_firewall_cli["Firewall CLI<br/>[cli.py]"]
end

subgraph group_scanners["Risk Scanners"]
  node_regex["Injection Scanner<br/>[regex_scanner.py]"]
  node_pii["PII Scanner<br/>[pii_scanner.py]"]
  node_secrets["Secrets Scanner<br/>[secrets_scanner.py]"]
  node_encoding["Encoding Scanner"]
  node_url["URL Scanner<br/>[url_scanner.py]"]
  node_conflict["Conflict Scanner"]
end

subgraph group_graph["Graph Retrieval"]
  node_graph_adapter["NetworkX Adapter"]
  node_graph_types["Graph Data Types<br/>[types.py]"]
  node_graph_wrapper["Graph Firewall<br/>[wrapper.py]"]
  node_graph_base["Graph Adapter Base<br/>[base.py]"]
  node_serializer["Text Serializer<br/>[wrapper.py]"]
end

subgraph group_support["Trust and Audit"]
  node_hasher["Document Hasher<br/>[hasher.py]"]
  node_provenance[("Provenance Store<br/>[store.py]")]
  node_audit[("Audit Log<br/>[audit.py]")]
end

node_user(("RAG Application"))

node_user -->|"queries through"| node_langchain
node_user -->|"queries through"| node_llamaindex
node_base_retriever -->|"retrieves for"| node_langchain
node_base_retriever -.->|"retrieves for"| node_llamaindex
node_langchain -->|"evaluates documents"| node_firewall
node_llamaindex -.->|"evaluates documents"| node_firewall
node_firewall -->|"evaluates policies"| node_policy
node_firewall -->|"scans with"| node_regex
node_firewall -->|"scans with"| node_pii
node_firewall -->|"scans with"| node_secrets
node_firewall -->|"scans with"| node_encoding
node_firewall -->|"scans with"| node_url
node_firewall -->|"scans with"| node_conflict
node_firewall -->|"logs decisions"| node_audit
node_user -->|"runs index or query"| node_firewall_cli
node_user -->|"requests graph retrieval"| node_graph_adapter
node_graph_adapter -->|"produces subgraphs"| node_graph_types
node_graph_adapter -->|"implements adapter"| node_graph_base
node_user -->|"submits subgraph"| node_graph_wrapper
node_graph_wrapper -->|"evaluates artifacts"| node_firewall
node_graph_wrapper -->|"hashes artifacts"| node_hasher
node_graph_wrapper -->|"logs decisions"| node_audit
node_graph_wrapper -->|"serializes sanitized graph"| node_serializer
node_graph_wrapper -->|"uses graph types"| node_graph_types

click node_langchain "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/langchain.py"
click node_llamaindex "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/llamaindex.py"
click node_firewall "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/firewall.py"
click node_policy "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/policies/engine.py"
click node_regex "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/regex_scanner.py"
click node_pii "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/pii_scanner.py"
click node_secrets "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/secrets_scanner.py"
click node_encoding "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/encoding_scanner.py"
click node_url "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/url_scanner.py"
click node_conflict "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/conflict_scanner.py"
click node_firewall_cli "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/cli.py"
click node_graph_adapter "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/graph/networkx_adapter.py"
click node_graph_types "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/types.py"
click node_graph_wrapper "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/wrapper.py"
click node_graph_base "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/graph/base.py"
click node_serializer "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/wrapper.py"
click node_hasher "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/provenance/hasher.py"
click node_provenance "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/provenance/store.py"
click node_audit "https://github.com/taladari/rag-firewall/blob/main/rag_firewall/audit.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_base_retriever,node_langchain,node_llamaindex toneBlue
class node_firewall,node_policy,node_firewall_cli toneAmber
class node_regex,node_pii,node_secrets,node_encoding,node_url,node_conflict toneMint
class node_graph_adapter,node_graph_types,node_graph_wrapper,node_graph_base,node_serializer toneRose
class node_hasher,node_provenance,node_audit,node_user toneIndigo
```

## Components

### Document Retrieval

- **Base Retriever**
- [LangChain Adapter](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/langchain.py): `rag_firewall/integrations/langchain.py`
- [LlamaIndex Adapter](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/llamaindex.py): `rag_firewall/integrations/llamaindex.py`

### Firewall Enforcement

- [Firewall](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/firewall.py): `rag_firewall/firewall.py`
- [Policy Engine](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/policies/engine.py): `rag_firewall/policies/engine.py`
- [Firewall CLI](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/cli.py): `rag_firewall/cli.py`

### Risk Scanners

- [Injection Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/regex_scanner.py): `rag_firewall/scanners/regex_scanner.py`
- [PII Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/pii_scanner.py): `rag_firewall/scanners/pii_scanner.py`
- [Secrets Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/secrets_scanner.py): `rag_firewall/scanners/secrets_scanner.py`
- [Encoding Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/encoding_scanner.py): `rag_firewall/scanners/encoding_scanner.py`
- [URL Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/url_scanner.py): `rag_firewall/scanners/url_scanner.py`
- [Conflict Scanner](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/scanners/conflict_scanner.py): `rag_firewall/scanners/conflict_scanner.py`

### Graph Retrieval

- [NetworkX Adapter](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/graph/networkx_adapter.py): `rag_firewall/integrations/graph/networkx_adapter.py`
- [Graph Data Types](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/types.py): `rag_firewall/graph/types.py`
- [Graph Firewall](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/wrapper.py): `rag_firewall/graph/wrapper.py`
- [Graph Adapter Base](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/integrations/graph/base.py): `rag_firewall/integrations/graph/base.py`
- [Text Serializer](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/graph/wrapper.py): `rag_firewall/graph/wrapper.py`

### Trust and Audit

- [Document Hasher](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/provenance/hasher.py): `rag_firewall/provenance/hasher.py`
- [Provenance Store](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/provenance/store.py): `rag_firewall/provenance/store.py`
- [Audit Log](https://github.com/taladari/rag-firewall/blob/main/rag_firewall/audit.py): `rag_firewall/audit.py`

### Other components

- **RAG Application**

## Connections

- RAG Application → LangChain Adapter: queries through (evidence: `README.md`)
- RAG Application → LlamaIndex Adapter: queries through (evidence: `README.md`)
- Base Retriever → LangChain Adapter: retrieves for (evidence: `rag_firewall/integrations/langchain.py`)
- Base Retriever → LlamaIndex Adapter: retrieves for
- LangChain Adapter → Firewall: evaluates documents (evidence: `rag_firewall/integrations/langchain.py`)
- LlamaIndex Adapter → Firewall: evaluates documents (evidence: `rag_firewall/integrations/llamaindex.py`)
- Firewall → Policy Engine: evaluates policies (evidence: `rag_firewall/firewall.py`)
- Firewall → Injection Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → PII Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → Secrets Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → Encoding Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → URL Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → Conflict Scanner: scans with (evidence: `rag_firewall/firewall.py`)
- Firewall → Audit Log: logs decisions (evidence: `rag_firewall/firewall.py`)
- RAG Application → Firewall CLI: runs index or query (evidence: `README.md`)
- RAG Application → NetworkX Adapter: requests graph retrieval (evidence: `README.md`)
- NetworkX Adapter → Graph Data Types: produces subgraphs (evidence: `rag_firewall/integrations/graph/networkx_adapter.py`)
- NetworkX Adapter → Graph Adapter Base: implements adapter (evidence: `rag_firewall/integrations/graph/networkx_adapter.py`)
- RAG Application → Graph Firewall: submits subgraph (evidence: `README.md`)
- Graph Firewall → Firewall: evaluates artifacts (evidence: `rag_firewall/graph/wrapper.py`)
- Graph Firewall → Document Hasher: hashes artifacts (evidence: `rag_firewall/graph/wrapper.py`)
- Graph Firewall → Audit Log: logs decisions (evidence: `rag_firewall/graph/wrapper.py`)
- Graph Firewall → Text Serializer: serializes sanitized graph (evidence: `rag_firewall/graph/wrapper.py`)
- Graph Firewall → Graph Data Types: uses graph types (evidence: `rag_firewall/graph/wrapper.py`)
