# borik216/prompt-shield architecture

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

- Interactive diagram: https://gitdiagram.com/borik216/prompt-shield
- Repository: https://github.com/borik216/prompt-shield

## Overview

PromptShield is a TLS-intercepting proxy that detects hosted LLM traffic, checks outgoing prompts for sensitive data, reconstructs provider-specific streamed replies, and records conversation turns for a live dashboard. The main workflow runs through the detector addon: classify and extract a request, scan it with DLP, block locally when needed, then capture the response and append a detection record. Separate capabilities include provider-format research via the recorder and proxy/certificate onboarding via the CLI. Relationships for unsampled modules are included only where the README documents them; optional integrations are marked dashed.

Main entry points: [`detector/addon.py`](https://github.com/borik216/prompt-shield/blob/main/detector/addon.py) (Detector addon), [`cli.py`](https://github.com/borik216/prompt-shield/blob/main/cli.py) (PromptShield CLI), [`dlp/engine.py`](https://github.com/borik216/prompt-shield/blob/main/dlp/engine.py) (DLP rule engine), [`dashboard/main.py`](https://github.com/borik216/prompt-shield/blob/main/dashboard/main.py) (Dashboard HTTP UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_proxy["Proxy detection"]
  node_detector["Detector addon<br/>[addon.py]"]
  node_provider_rules["Provider rules<br/>[config.py]"]
  node_request_extract["Request extraction<br/>[extract.py]"]
  node_stream_rebuild["Stream reconstruction<br/>[sse.py]"]
  node_overlay_helpers["Overlay response helpers<br/>[overlay.py]"]
  node_overlay_script["Browser overlay"]
end

subgraph group_dlp["DLP and blocking"]
  node_dlp_engine["DLP rule engine<br/>[engine.py]"]
  node_presidio["Presidio PII backend"]
  node_local_llm["Local LLM backend"]
  node_block_response["Block response builder<br/>[blocked_page.py]"]
end

subgraph group_records["Records and dashboard"]
  node_detection_log["Detection NDJSON"]
  node_dashboard_api["Dashboard HTTP UI<br/>[main.py]"]
  node_dashboard_data["Record views and stats<br/>[data.py]"]
end

subgraph group_operations["Operations and capture"]
  node_cli["PromptShield CLI<br/>[cli.py]"]
  node_raw_recorder["Raw traffic recorder<br/>[addon.py]"]
  node_ca_tools["Platform and CA helpers<br/>[platform_utils.py]"]
end

node_user(("Browser user"))
node_hosted_llms{{"Hosted LLMs"}}

node_user -->|"sends traffic"| node_detector
node_detector -->|"forwards requests"| node_hosted_llms
node_detector -->|"classifies flows"| node_provider_rules
node_detector -->|"extracts prompts"| node_request_extract
node_detector -->|"scans prompts"| node_dlp_engine
node_detector -->|"reconstructs replies"| node_stream_rebuild
node_detector -->|"renders fallback"| node_block_response
node_detector -->|"builds block response"| node_overlay_helpers
node_detector -->|"injects script"| node_overlay_script
node_overlay_script -->|"shows block notice"| node_user
node_dlp_engine -->|"checks PII"| node_presidio
node_dlp_engine -.->|"optional backend"| node_local_llm
node_detector -->|"appends records"| node_detection_log
node_dashboard_api -->|"requests views"| node_dashboard_data
node_dashboard_data -->|"reads records"| node_detection_log
node_cli -->|"starts proxy"| node_detector
node_cli -->|"starts capture"| node_raw_recorder
node_cli -->|"starts dashboard"| node_dashboard_api
node_cli -->|"installs CA"| node_ca_tools
node_user -->|"views activity"| node_dashboard_api

click node_cli "https://github.com/borik216/prompt-shield/blob/main/cli.py"
click node_detector "https://github.com/borik216/prompt-shield/blob/main/detector/addon.py"
click node_provider_rules "https://github.com/borik216/prompt-shield/blob/main/detector/config.py"
click node_request_extract "https://github.com/borik216/prompt-shield/blob/main/detector/extract.py"
click node_stream_rebuild "https://github.com/borik216/prompt-shield/blob/main/detector/sse.py"
click node_overlay_helpers "https://github.com/borik216/prompt-shield/blob/main/detector/overlay.py"
click node_overlay_script "https://github.com/borik216/prompt-shield/blob/main/detector/static/promptshield_overlay.js"
click node_dlp_engine "https://github.com/borik216/prompt-shield/blob/main/dlp/engine.py"
click node_presidio "https://github.com/borik216/prompt-shield/blob/main/dlp/presidio_backend.py"
click node_local_llm "https://github.com/borik216/prompt-shield/blob/main/dlp/local_llm_backend.py"
click node_block_response "https://github.com/borik216/prompt-shield/blob/main/dlp/blocked_page.py"
click node_dashboard_api "https://github.com/borik216/prompt-shield/blob/main/dashboard/main.py"
click node_dashboard_data "https://github.com/borik216/prompt-shield/blob/main/dashboard/data.py"
click node_raw_recorder "https://github.com/borik216/prompt-shield/blob/main/recorder/addon.py"
click node_ca_tools "https://github.com/borik216/prompt-shield/blob/main/detector/platform_utils.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_detector,node_provider_rules,node_request_extract,node_stream_rebuild,node_overlay_helpers,node_overlay_script,node_user toneBlue
class node_dlp_engine,node_presidio,node_local_llm,node_block_response toneAmber
class node_detection_log,node_dashboard_api,node_dashboard_data toneMint
class node_cli,node_raw_recorder,node_ca_tools toneRose
class node_hosted_llms toneIndigo
```

## Components

### Proxy detection

- [Detector addon](https://github.com/borik216/prompt-shield/blob/main/detector/addon.py): `detector/addon.py`
- [Provider rules](https://github.com/borik216/prompt-shield/blob/main/detector/config.py): `detector/config.py`
- [Request extraction](https://github.com/borik216/prompt-shield/blob/main/detector/extract.py): `detector/extract.py`
- [Stream reconstruction](https://github.com/borik216/prompt-shield/blob/main/detector/sse.py): `detector/sse.py`
- [Overlay response helpers](https://github.com/borik216/prompt-shield/blob/main/detector/overlay.py): `detector/overlay.py`
- [Browser overlay](https://github.com/borik216/prompt-shield/blob/main/detector/static/promptshield_overlay.js): `detector/static/promptshield_overlay.js`

### DLP and blocking

- [DLP rule engine](https://github.com/borik216/prompt-shield/blob/main/dlp/engine.py): `dlp/engine.py`
- [Presidio PII backend](https://github.com/borik216/prompt-shield/blob/main/dlp/presidio_backend.py): `dlp/presidio_backend.py`
- [Local LLM backend](https://github.com/borik216/prompt-shield/blob/main/dlp/local_llm_backend.py): `dlp/local_llm_backend.py`
- [Block response builder](https://github.com/borik216/prompt-shield/blob/main/dlp/blocked_page.py): `dlp/blocked_page.py`

### Records and dashboard

- **Detection NDJSON**
- [Dashboard HTTP UI](https://github.com/borik216/prompt-shield/blob/main/dashboard/main.py): `dashboard/main.py`
- [Record views and stats](https://github.com/borik216/prompt-shield/blob/main/dashboard/data.py): `dashboard/data.py`

### Operations and capture

- [PromptShield CLI](https://github.com/borik216/prompt-shield/blob/main/cli.py): `cli.py`
- [Raw traffic recorder](https://github.com/borik216/prompt-shield/blob/main/recorder/addon.py): `recorder/addon.py`
- [Platform and CA helpers](https://github.com/borik216/prompt-shield/blob/main/detector/platform_utils.py): `detector/platform_utils.py`

### Other components

- **Browser user**
- **Hosted LLMs**

## Connections

- Browser user → Detector addon: sends traffic (evidence: `README.md`)
- Detector addon → Hosted LLMs: forwards requests (evidence: `README.md`)
- Detector addon → Provider rules: classifies flows (evidence: `detector/addon.py`)
- Detector addon → Request extraction: extracts prompts (evidence: `detector/addon.py`)
- Detector addon → DLP rule engine: scans prompts (evidence: `detector/addon.py`)
- Detector addon → Stream reconstruction: reconstructs replies (evidence: `detector/addon.py`)
- Detector addon → Block response builder: renders fallback (evidence: `detector/addon.py`)
- Detector addon → Overlay response helpers: builds block response (evidence: `detector/addon.py`)
- Detector addon → Browser overlay: injects script
- Browser overlay → Browser user: shows block notice (evidence: `README.md`)
- DLP rule engine → Presidio PII backend: checks PII (evidence: `dlp/engine.py`)
- DLP rule engine → Local LLM backend: optional backend
- Detector addon → Detection NDJSON: appends records (evidence: `README.md`)
- Dashboard HTTP UI → Record views and stats: requests views (evidence: `dashboard/main.py`)
- Record views and stats → Detection NDJSON: reads records (evidence: `README.md`)
- PromptShield CLI → Detector addon: starts proxy (evidence: `README.md`)
- PromptShield CLI → Raw traffic recorder: starts capture (evidence: `README.md`)
- PromptShield CLI → Dashboard HTTP UI: starts dashboard (evidence: `README.md`)
- PromptShield CLI → Platform and CA helpers: installs CA (evidence: `cli.py`)
- Browser user → Dashboard HTTP UI: views activity (evidence: `README.md`)
