# surya0732/promptfence architecture

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

- Interactive diagram: https://gitdiagram.com/surya0732/promptfence
- Repository: https://github.com/surya0732/promptfence

## Overview

PromptFence is an AI-security gateway and dashboard for detecting prompt-injection indicators, applying policy, and safely simulating agent actions. Its main flow is client text into the FastAPI gateway, through the selected detector mode and policy engine, then into a decision returned to the client; simulation adds pre-execution tool checks. The README also documents dashboard, telemetry, health, and benchmark capabilities. Benchmark internals are represented from the excerpts; frontend-to-endpoint wiring is documented in the README, while unsampled implementation details are not inferred.

Main entry points: [`app/main.py`](https://github.com/surya0732/promptfence/blob/main/app/main.py) (FastAPI gateway), [`evaluation/run_benchmark.py`](https://github.com/surya0732/promptfence/blob/main/evaluation/run_benchmark.py) (Benchmark runner), [`app/simulation.py`](https://github.com/surya0732/promptfence/blob/main/app/simulation.py) (Simulation orchestrator), [`app/detectors/llm.py`](https://github.com/surya0732/promptfence/blob/main/app/detectors/llm.py) (Local LLM detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Gateway and dashboard"]
  node_gateway["FastAPI gateway<br/>[main.py]"]
  node_dashboard["Web dashboard<br/>[app.js]"]
  node_ui_document["Dashboard markup<br/>[index.html]"]
end

subgraph group_detection["Detection and policy"]
  node_schemas["API schemas<br/>[schemas.py]"]
  node_rule_detector["Phrase detector<br/>[rules.py]"]
  node_llm_detector["Local LLM detector<br/>[llm.py]"]
  node_policy["Policy engine<br/>[engine.py]"]
end

subgraph group_simulation["Agent simulation"]
  node_simulation["Simulation orchestrator<br/>[simulation.py]"]
  node_mock_tools["Mock tool checks<br/>[simulation.py]"]
end

subgraph group_evaluation["Evaluation and telemetry"]
  node_telemetry[("In-process telemetry<br/>[telemetry.py]")]
  node_benchmark_api["Benchmark metrics route<br/>[main.py]"]
  node_dataset["Labeled cases<br/>[dataset.jsonl]"]
  node_benchmark_runner["Benchmark runner<br/>[run_benchmark.py]"]
  node_metrics["Security metrics<br/>[metrics.py]"]
  node_artifacts["Benchmark artifacts"]
end

node_user(("Client / operator"))
node_ollama["Ollama service"]

node_user -->|"uses"| node_dashboard
node_user -->|"submits requests"| node_gateway
node_gateway -->|"serves"| node_ui_document
node_dashboard -->|"calls API"| node_gateway
node_gateway -->|"runs rules"| node_rule_detector
node_gateway -->|"runs LLM"| node_llm_detector
node_gateway -->|"evaluates findings"| node_policy
node_gateway -->|"validates payloads"| node_schemas
node_llm_detector -->|"sends inference"| node_ollama
node_gateway -->|"routes simulation"| node_simulation
node_simulation -->|"runs rules"| node_rule_detector
node_simulation -->|"runs LLM"| node_llm_detector
node_simulation -->|"evaluates findings"| node_policy
node_simulation -->|"gates execution"| node_mock_tools
node_gateway -->|"reads metrics"| node_telemetry
node_simulation -->|"records outcomes"| node_telemetry
node_dashboard -->|"requests metrics"| node_benchmark_api
node_benchmark_api -->|"reads latest run"| node_artifacts
node_benchmark_runner -->|"evaluates cases"| node_dataset
node_benchmark_runner -->|"runs detector modes"| node_rule_detector
node_benchmark_runner -->|"runs detector modes"| node_llm_detector
node_benchmark_runner -->|"scores decisions"| node_policy
node_benchmark_runner -->|"calculates metrics"| node_metrics
node_benchmark_runner -->|"writes reports"| node_artifacts

click node_gateway "https://github.com/surya0732/promptfence/blob/main/app/main.py"
click node_dashboard "https://github.com/surya0732/promptfence/blob/main/app/static/js/app.js"
click node_ui_document "https://github.com/surya0732/promptfence/blob/main/app/static/index.html"
click node_schemas "https://github.com/surya0732/promptfence/blob/main/app/schemas.py"
click node_rule_detector "https://github.com/surya0732/promptfence/blob/main/app/detectors/rules.py"
click node_llm_detector "https://github.com/surya0732/promptfence/blob/main/app/detectors/llm.py"
click node_policy "https://github.com/surya0732/promptfence/blob/main/app/policy/engine.py"
click node_simulation "https://github.com/surya0732/promptfence/blob/main/app/simulation.py"
click node_mock_tools "https://github.com/surya0732/promptfence/blob/main/app/simulation.py"
click node_telemetry "https://github.com/surya0732/promptfence/blob/main/app/telemetry.py"
click node_benchmark_api "https://github.com/surya0732/promptfence/blob/main/app/main.py"
click node_dataset "https://github.com/surya0732/promptfence/blob/main/evaluation/dataset.jsonl"
click node_benchmark_runner "https://github.com/surya0732/promptfence/blob/main/evaluation/run_benchmark.py"
click node_metrics "https://github.com/surya0732/promptfence/blob/main/evaluation/metrics.py"
click node_artifacts "https://github.com/surya0732/promptfence/tree/main/evaluation/results"

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_gateway,node_dashboard,node_ui_document,node_user toneBlue
class node_schemas,node_rule_detector,node_llm_detector,node_policy toneAmber
class node_simulation,node_mock_tools toneMint
class node_telemetry,node_benchmark_api,node_dataset,node_benchmark_runner,node_metrics,node_artifacts toneRose
class node_ollama toneIndigo
```

## Components

### Gateway and dashboard

- [FastAPI gateway](https://github.com/surya0732/promptfence/blob/main/app/main.py): `app/main.py`
- [Web dashboard](https://github.com/surya0732/promptfence/blob/main/app/static/js/app.js): `app/static/js/app.js`
- [Dashboard markup](https://github.com/surya0732/promptfence/blob/main/app/static/index.html): `app/static/index.html`

### Detection and policy

- [API schemas](https://github.com/surya0732/promptfence/blob/main/app/schemas.py): `app/schemas.py`
- [Phrase detector](https://github.com/surya0732/promptfence/blob/main/app/detectors/rules.py): `app/detectors/rules.py`
- [Local LLM detector](https://github.com/surya0732/promptfence/blob/main/app/detectors/llm.py): `app/detectors/llm.py`
- [Policy engine](https://github.com/surya0732/promptfence/blob/main/app/policy/engine.py): `app/policy/engine.py`

### Agent simulation

- [Simulation orchestrator](https://github.com/surya0732/promptfence/blob/main/app/simulation.py): `app/simulation.py`
- [Mock tool checks](https://github.com/surya0732/promptfence/blob/main/app/simulation.py): `app/simulation.py`

### Evaluation and telemetry

- [In-process telemetry](https://github.com/surya0732/promptfence/blob/main/app/telemetry.py): `app/telemetry.py`
- [Benchmark metrics route](https://github.com/surya0732/promptfence/blob/main/app/main.py): `app/main.py`
- [Labeled cases](https://github.com/surya0732/promptfence/blob/main/evaluation/dataset.jsonl): `evaluation/dataset.jsonl`
- [Benchmark runner](https://github.com/surya0732/promptfence/blob/main/evaluation/run_benchmark.py): `evaluation/run_benchmark.py`
- [Security metrics](https://github.com/surya0732/promptfence/blob/main/evaluation/metrics.py): `evaluation/metrics.py`
- [Benchmark artifacts](https://github.com/surya0732/promptfence/tree/main/evaluation/results): `evaluation/results`

### Other components

- **Client / operator**
- **Ollama service**

## Connections

- Client / operator → Web dashboard: uses (evidence: `README.md`)
- Client / operator → FastAPI gateway: submits requests (evidence: `README.md`)
- FastAPI gateway → Dashboard markup: serves (evidence: `app/main.py`)
- Web dashboard → FastAPI gateway: calls API (evidence: `README.md`)
- FastAPI gateway → Phrase detector: runs rules (evidence: `app/main.py`)
- FastAPI gateway → Local LLM detector: runs LLM (evidence: `app/main.py`)
- FastAPI gateway → Policy engine: evaluates findings (evidence: `app/main.py`)
- FastAPI gateway → API schemas: validates payloads (evidence: `app/main.py`)
- Local LLM detector → Ollama service: sends inference (evidence: `app/detectors/llm.py`)
- FastAPI gateway → Simulation orchestrator: routes simulation (evidence: `app/main.py`)
- Simulation orchestrator → Phrase detector: runs rules (evidence: `app/simulation.py`)
- Simulation orchestrator → Local LLM detector: runs LLM (evidence: `app/simulation.py`)
- Simulation orchestrator → Policy engine: evaluates findings (evidence: `app/simulation.py`)
- Simulation orchestrator → Mock tool checks: gates execution (evidence: `README.md`)
- FastAPI gateway → In-process telemetry: reads metrics (evidence: `app/main.py`)
- Simulation orchestrator → In-process telemetry: records outcomes (evidence: `app/simulation.py`)
- Web dashboard → Benchmark metrics route: requests metrics (evidence: `README.md`)
- Benchmark metrics route → Benchmark artifacts: reads latest run (evidence: `app/main.py`)
- Benchmark runner → Labeled cases: evaluates cases (evidence: `README.md`)
- Benchmark runner → Phrase detector: runs detector modes (evidence: `evaluation/run_benchmark.py`)
- Benchmark runner → Local LLM detector: runs detector modes (evidence: `evaluation/run_benchmark.py`)
- Benchmark runner → Policy engine: scores decisions (evidence: `evaluation/run_benchmark.py`)
- Benchmark runner → Security metrics: calculates metrics (evidence: `evaluation/run_benchmark.py`)
- Benchmark runner → Benchmark artifacts: writes reports (evidence: `README.md`)
