# anshikayad16/promptshield-ai-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/anshikayad16/promptshield-ai-analyzer
- Repository: https://github.com/anshikayad16/promptshield-ai-analyzer

## Overview

ShieldAI Analyzer combines a browser extension and Flask service to scan prompts before submission, classify risk, and allow or block the interaction. Its dashboard also supports account access and review of recent logs and aggregate safe/blocked counts. The main workflow is shown in detail from the extension’s content script through the service, detection pipeline, and SQLite log store. The README documents broader platform coverage and local processing; unsampled templates and extension assets are represented by their existing directories, with uncertain implementation links omitted.

Main entry points: [`app.py`](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py) (Flask routes), [`model.py`](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py) (Detection pipeline), [`extension/content.js`](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/content.js) (Prompt interception), [`database.py`](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/database.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Browser extension"]
  node_content_capture["Prompt interception<br/>[content.js]"]
  node_background_dispatch["Request dispatch<br/>[background.js]"]
  node_popup_scan["Popup scanning<br/>[popup.js]"]
end

subgraph group_service["Web service"]
  node_web_scan["Dashboard scanning<br/>[app.js]"]
  node_flask_api["Flask routes<br/>[app.py]"]
  node_accounts["Account access<br/>[app.py]"]
  node_dashboard["Logs dashboard<br/>[app.py]"]
  node_web_views["Web views"]
end

subgraph group_detection["Threat detection"]
  node_detection_pipeline["Detection pipeline<br/>[model.py]"]
  node_signature_rules["Signature checks<br/>[model.py]"]
  node_heuristic_rules["Heuristic checks<br/>[model.py]"]
  node_ml_classifier["ML classifier<br/>[model.py]"]
  node_training_data["Training datasets<br/>[data.csv]"]
  node_injection_data["Injection dataset"]
end

subgraph group_data["Persistence and analytics"]
  node_sqlite_store[("SQLite store<br/>[database.db]")]
  node_db_access["Database access<br/>[database.py]"]
end

node_browser_user(("Browser user"))
node_ai_platform(("AI platform"))

node_browser_user -->|"enters prompt"| node_content_capture
node_content_capture -->|"requests scan"| node_background_dispatch
node_background_dispatch -->|"posts prompt"| node_flask_api
node_flask_api -->|"analyzes prompt"| node_detection_pipeline
node_detection_pipeline -->|"checks first"| node_signature_rules
node_detection_pipeline -->|"checks next"| node_heuristic_rules
node_detection_pipeline -->|"checks last"| node_ml_classifier
node_ml_classifier -->|"trains from"| node_training_data
node_ml_classifier -->|"trains from"| node_injection_data
node_flask_api -->|"stores decision"| node_db_access
node_db_access -->|"reads and writes"| node_sqlite_store
node_flask_api -.->|"returns decision"| node_content_capture
node_content_capture -->|"replays if safe"| node_ai_platform
node_browser_user -->|"submits prompt"| node_popup_scan
node_popup_scan -->|"posts prompt"| node_flask_api
node_browser_user -->|"submits prompt"| node_web_scan
node_web_scan -->|"posts prompt"| node_flask_api
node_browser_user -->|"registers or logs in"| node_accounts
node_accounts -->|"queries users"| node_db_access
node_browser_user -->|"views analytics"| node_dashboard
node_dashboard -->|"queries logs"| node_db_access
node_flask_api -->|"renders pages"| node_web_views

click node_content_capture "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/content.js"
click node_background_dispatch "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/background.js"
click node_popup_scan "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/popup.js"
click node_web_scan "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/static/app.js"
click node_flask_api "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py"
click node_accounts "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py"
click node_dashboard "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py"
click node_web_views "https://github.com/anshikayad16/promptshield-ai-analyzer/tree/main/templates"
click node_detection_pipeline "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py"
click node_signature_rules "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py"
click node_heuristic_rules "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py"
click node_ml_classifier "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py"
click node_training_data "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/data.csv"
click node_injection_data "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/prompt_injection_dataset.csv"
click node_sqlite_store "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/database.db"
click node_db_access "https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/database.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_content_capture,node_background_dispatch,node_popup_scan,node_browser_user toneBlue
class node_web_scan,node_flask_api,node_accounts,node_dashboard,node_web_views toneAmber
class node_detection_pipeline,node_signature_rules,node_heuristic_rules,node_ml_classifier,node_training_data,node_injection_data toneMint
class node_sqlite_store,node_db_access toneRose
class node_ai_platform toneIndigo
```

## Components

### Browser extension

- [Prompt interception](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/content.js): `extension/content.js`
- [Request dispatch](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/background.js): `extension/background.js`
- [Popup scanning](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/extension/popup.js): `extension/popup.js`

### Web service

- [Dashboard scanning](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/static/app.js): `static/app.js`
- [Flask routes](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py): `app.py`
- [Account access](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py): `app.py`
- [Logs dashboard](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/app.py): `app.py`
- [Web views](https://github.com/anshikayad16/promptshield-ai-analyzer/tree/main/templates): `templates`

### Threat detection

- [Detection pipeline](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py): `model.py`
- [Signature checks](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py): `model.py`
- [Heuristic checks](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py): `model.py`
- [ML classifier](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/model.py): `model.py`
- [Training datasets](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/data.csv): `data.csv`
- [Injection dataset](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/prompt_injection_dataset.csv): `prompt_injection_dataset.csv`

### Persistence and analytics

- [SQLite store](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/database.db): `database.db`
- [Database access](https://github.com/anshikayad16/promptshield-ai-analyzer/blob/main/database.py): `database.py`

### Other components

- **Browser user**
- **AI platform**

## Connections

- Browser user → Prompt interception: enters prompt (evidence: `extension/content.js`)
- Prompt interception → Request dispatch: requests scan (evidence: `extension/content.js`)
- Request dispatch → Flask routes: posts prompt (evidence: `extension/background.js`)
- Flask routes → Detection pipeline: analyzes prompt (evidence: `app.py`)
- Detection pipeline → Signature checks: checks first (evidence: `model.py`)
- Detection pipeline → Heuristic checks: checks next (evidence: `model.py`)
- Detection pipeline → ML classifier: checks last (evidence: `model.py`)
- ML classifier → Training datasets: trains from (evidence: `model.py`)
- ML classifier → Injection dataset: trains from (evidence: `model.py`)
- Flask routes → Database access: stores decision (evidence: `app.py`)
- Database access → SQLite store: reads and writes (evidence: `database.py`)
- Flask routes → Prompt interception: returns decision (evidence: `README.md`)
- Prompt interception → AI platform: replays if safe (evidence: `extension/content.js`)
- Browser user → Popup scanning: submits prompt (evidence: `extension/popup.js`)
- Popup scanning → Flask routes: posts prompt (evidence: `extension/popup.js`)
- Browser user → Dashboard scanning: submits prompt (evidence: `static/app.js`)
- Dashboard scanning → Flask routes: posts prompt (evidence: `static/app.js`)
- Browser user → Account access: registers or logs in (evidence: `app.py`)
- Account access → Database access: queries users (evidence: `app.py`)
- Browser user → Logs dashboard: views analytics (evidence: `app.py`)
- Logs dashboard → Database access: queries logs (evidence: `app.py`)
- Flask routes → Web views: renders pages (evidence: `app.py`)
