# niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection architecture

> Architecture diagram of the GitHub repository niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection
- Repository: https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection

## Overview

RustGuard is an asynchronous LLM security gateway. Client chat requests enter the server proxy, pass authentication and governance checks, undergo prompt inspection, and are forwarded to an upstream model; responses are redacted or inspected as SSE streams before returning to the client. The server also exposes health and metrics, records audit events, and supports optional HNSW-based RAG with a separate ingestion utility. The README documents several pipeline connections not visible in the sampled proxy excerpt; those edges cite the README, and unsampled implementation details are not inferred.

Main entry points: [`gateway-server/src/proxy.rs`](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/proxy.rs) (HTTP Proxy), [`gateway-core/src/streaming.rs`](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/streaming.rs) (SSE Inspection), [`gateway-core/src/injection.rs`](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/injection.rs) (Injection Scanner), [`gateway-core/src/normalizer.rs`](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/normalizer.rs) (Text Normalizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Gateway Server"]
  node_proxy["HTTP Proxy<br/>[proxy.rs]"]
  node_auth["Bearer Authentication<br/>[config.rs]"]
  node_governance["Governance and SSRF<br/>[config.rs]"]
  node_errors["HTTP Error Mapping<br/>[error.rs]"]
end

subgraph group_security["Security Inspection"]
  node_normalizer["Text Normalizer<br/>[normalizer.rs]"]
  node_injection["Injection Scanner<br/>[injection.rs]"]
  node_pii["PII Redaction<br/>[pii.rs]"]
  node_streaming["SSE Inspection<br/>[streaming.rs]"]
end

subgraph group_rag["RAG Retrieval"]
  node_rag_engine["HNSW RAG Engine<br/>[rag.rs]"]
  node_ingest["Document Ingestion<br/>[ingest.rs]"]
end

subgraph group_observability["Telemetry and Audit"]
  node_audit["Audit Records<br/>[audit.rs]"]
  node_metrics["Atomic Metrics<br/>[metrics.rs]"]
end

node_client(("Client Application"))
node_upstream["LLM Provider"]

node_client -->|"sends chat request"| node_proxy
node_proxy -->|"enforces token"| node_auth
node_proxy -->|"checks policy"| node_governance
node_proxy -->|"normalizes prompt"| node_normalizer
node_injection -->|"normalizes input"| node_normalizer
node_proxy -->|"scans prompt"| node_injection
node_proxy -->|"retrieves context"| node_rag_engine
node_ingest -.->|"populates index"| node_rag_engine
node_proxy -->|"forwards request"| node_upstream
node_upstream -->|"returns response"| node_proxy
node_proxy -->|"redacts response"| node_pii
node_proxy -->|"inspects SSE"| node_streaming
node_streaming -->|"scans chunks"| node_injection
node_streaming -->|"checks secrets"| node_pii
node_proxy -->|"returns result"| node_client
node_proxy -->|"emits audit record"| node_audit
node_proxy -->|"updates counters"| node_metrics
node_proxy -->|"returns gateway errors"| node_errors
node_proxy -->|"serves metrics"| node_metrics

click node_proxy "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/proxy.rs"
click node_auth "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/config.rs"
click node_governance "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/config.rs"
click node_errors "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/error.rs"
click node_normalizer "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/normalizer.rs"
click node_injection "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/injection.rs"
click node_pii "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/pii.rs"
click node_streaming "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/streaming.rs"
click node_rag_engine "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/rag.rs"
click node_ingest "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/bin/ingest.rs"
click node_audit "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/audit.rs"
click node_metrics "https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/metrics.rs"

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_proxy,node_auth,node_governance,node_errors,node_client toneBlue
class node_normalizer,node_injection,node_pii,node_streaming toneAmber
class node_rag_engine,node_ingest toneMint
class node_audit,node_metrics toneRose
class node_upstream toneIndigo
```

## Components

### Gateway Server

- [HTTP Proxy](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/proxy.rs): `gateway-server/src/proxy.rs`
- [Bearer Authentication](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/config.rs): `gateway-server/src/config.rs`
- [Governance and SSRF](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/config.rs): `gateway-server/src/config.rs`
- [HTTP Error Mapping](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/error.rs): `gateway-server/src/error.rs`

### Security Inspection

- [Text Normalizer](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/normalizer.rs): `gateway-core/src/normalizer.rs`
- [Injection Scanner](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/injection.rs): `gateway-core/src/injection.rs`
- [PII Redaction](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/pii.rs): `gateway-core/src/pii.rs`
- [SSE Inspection](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/streaming.rs): `gateway-core/src/streaming.rs`

### RAG Retrieval

- [HNSW RAG Engine](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/rag.rs): `gateway-server/src/rag.rs`
- [Document Ingestion](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/bin/ingest.rs): `gateway-server/src/bin/ingest.rs`

### Telemetry and Audit

- [Audit Records](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-server/src/audit.rs): `gateway-server/src/audit.rs`
- [Atomic Metrics](https://github.com/niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection/blob/main/gateway-core/src/metrics.rs): `gateway-core/src/metrics.rs`

### Other components

- **Client Application**
- **LLM Provider**

## Connections

- Client Application → HTTP Proxy: sends chat request (evidence: `README.md`)
- HTTP Proxy → Bearer Authentication: enforces token (evidence: `gateway-server/src/proxy.rs`)
- HTTP Proxy → Governance and SSRF: checks policy (evidence: `README.md`)
- HTTP Proxy → Text Normalizer: normalizes prompt (evidence: `README.md`)
- Injection Scanner → Text Normalizer: normalizes input (evidence: `gateway-core/src/injection.rs`)
- HTTP Proxy → Injection Scanner: scans prompt (evidence: `README.md`)
- HTTP Proxy → HNSW RAG Engine: retrieves context (evidence: `gateway-server/src/proxy.rs`)
- Document Ingestion → HNSW RAG Engine: populates index
- HTTP Proxy → LLM Provider: forwards request (evidence: `README.md`)
- LLM Provider → HTTP Proxy: returns response (evidence: `README.md`)
- HTTP Proxy → PII Redaction: redacts response (evidence: `README.md`)
- HTTP Proxy → SSE Inspection: inspects SSE (evidence: `README.md`)
- SSE Inspection → Injection Scanner: scans chunks (evidence: `gateway-core/src/streaming.rs`)
- SSE Inspection → PII Redaction: checks secrets (evidence: `gateway-core/src/streaming.rs`)
- HTTP Proxy → Client Application: returns result (evidence: `README.md`)
- HTTP Proxy → Audit Records: emits audit record (evidence: `gateway-server/src/proxy.rs`)
- HTTP Proxy → Atomic Metrics: updates counters (evidence: `gateway-server/src/proxy.rs`)
- HTTP Proxy → HTTP Error Mapping: returns gateway errors (evidence: `gateway-server/src/proxy.rs`)
- HTTP Proxy → Atomic Metrics: serves metrics (evidence: `gateway-server/src/proxy.rs`)
