# promptshield-io/promptshield architecture

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

- Interactive diagram: https://gitdiagram.com/promptshield-io/promptshield
- Repository: https://github.com/promptshield-io/promptshield

## Overview

PromptShield is a Unicode-threat detection and remediation ecosystem for AI prompts, spanning a reusable scanning engine, command-line/workspace workflows, and editor integrations. The principal workflow scans text or files, filters or reports threats, and offers fixes or sanitization. The website presents the product and an interactive Tiptap demo. Several connections come from imports or calls in sampled source; broader package capabilities are documented in the README, but unsampled implementations are represented only at their supported directory paths.

Main entry points: [`packages/workspace/src/workspace.ts`](https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/workspace.ts) (Workspace Scanning), [`packages/cli/src/main.ts`](https://github.com/promptshield-io/promptshield/blob/main/packages/cli/src/main.ts) (CLI Commands), [`packages/core/src/core.ts`](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/core.ts) (Detection Engine), [`packages/lsp/src/lsp.ts`](https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/lsp.ts) (Language Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_detection["Threat Detection"]
  node_core["Detection Engine<br/>[core.ts]"]
  node_unicode["Unicode Rules<br/>[invisible.ts]"]
  node_injection["Injection Rules"]
  node_smuggling["Smuggling Rules<br/>[smuggling.ts]"]
  node_trojan["Trojan Rules<br/>[trojan.ts]"]
end

subgraph group_workspace["File Workflows"]
  node_cli["CLI Commands<br/>[main.ts]"]
  node_workspace_scan["Workspace Scanning<br/>[workspace.ts]"]
  node_file_resolution["File Resolution<br/>[resolve-files.ts]"]
  node_scan_cache[("Scan Cache<br/>[cache.ts]")]
  node_ignore["Ignore Filtering<br/>[ignore.ts]"]
  node_sanitizer["Sanitization<br/>[fix.ts]"]
end

subgraph group_editors["Editor Integrations"]
  node_lsp["Language Server<br/>[lsp.ts]"]
  node_lsp_scan["Workspace Editor Scans"]
  node_code_actions["Code Actions<br/>[code-actions.ts]"]
  node_vscode["VS Code Extension<br/>[extension.ts]"]
  node_decorations["Threat Decorations"]
  node_tiptap["Tiptap Protection<br/>[plugin.ts]"]
  node_tiptap_hover["Tiptap Fix UI<br/>[hover.ts]"]
end

subgraph group_web["Product Website"]
  node_home["Website Home<br/>[page.tsx]"]
  node_ecosystem["Ecosystem Overview"]
  node_quickstart["Quick Start"]
  node_tiptap_demo["Tiptap Demo"]
  node_try_demo["Try It Out"]
end

node_developer(("Developer"))

node_developer -->|"runs scans"| node_cli
node_developer -->|"installs extension"| node_vscode
node_cli -->|"runs scan"| node_workspace_scan
node_cli -->|"resolves files"| node_file_resolution
node_cli -->|"creates checker"| node_ignore
node_cli -->|"scans text"| node_core
node_cli -->|"writes reports"| node_workspace_scan
node_workspace_scan -->|"scans content"| node_core
node_workspace_scan -->|"filters threats"| node_ignore
node_workspace_scan -->|"applies fixes"| node_sanitizer
node_workspace_scan -->|"resolves files"| node_file_resolution
node_workspace_scan -->|"uses cache"| node_scan_cache
node_lsp -->|"scans documents"| node_core
node_lsp -->|"filters threats"| node_ignore
node_lsp -->|"builds actions"| node_code_actions
node_lsp -->|"dispatches workspace"| node_lsp_scan
node_lsp_scan -->|"scans files"| node_core
node_lsp_scan -.->|"uses workspace engine"| node_workspace_scan
node_code_actions -->|"applies fixes"| node_sanitizer
node_vscode -->|"starts server"| node_lsp
node_vscode -.->|"updates highlights"| node_decorations
node_tiptap -->|"scans editor text"| node_core
node_tiptap_hover -->|"uses plugin key"| node_tiptap
node_tiptap_hover -->|"invokes fixes"| node_tiptap
node_home -->|"renders"| node_ecosystem
node_home -->|"renders"| node_quickstart
node_home -->|"renders"| node_tiptap_demo
node_home -->|"renders"| node_try_demo
node_quickstart -->|"demonstrates scanning"| node_core
node_tiptap_demo -->|"demonstrates integration"| node_tiptap
node_tiptap_demo -->|"demonstrates scanning"| node_core

click node_core "https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/core.ts"
click node_unicode "https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/invisible.ts"
click node_injection "https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/injection-patterns.ts"
click node_smuggling "https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/smuggling.ts"
click node_trojan "https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/trojan.ts"
click node_cli "https://github.com/promptshield-io/promptshield/blob/main/packages/cli/src/main.ts"
click node_workspace_scan "https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/workspace.ts"
click node_file_resolution "https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/resolve-files.ts"
click node_scan_cache "https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/cache.ts"
click node_ignore "https://github.com/promptshield-io/promptshield/blob/main/packages/ignore/src/ignore.ts"
click node_sanitizer "https://github.com/promptshield-io/promptshield/blob/main/packages/sanitizer/src/fix.ts"
click node_lsp "https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/lsp.ts"
click node_lsp_scan "https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/workspace-scanning.ts"
click node_code_actions "https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/code-actions.ts"
click node_vscode "https://github.com/promptshield-io/promptshield/blob/main/packages/vscode/src/extension.ts"
click node_decorations "https://github.com/promptshield-io/promptshield/blob/main/packages/vscode/src/decoration-manager.ts"
click node_tiptap "https://github.com/promptshield-io/promptshield/blob/main/packages/tiptap/src/plugin.ts"
click node_tiptap_hover "https://github.com/promptshield-io/promptshield/blob/main/packages/tiptap/src/hover.ts"
click node_home "https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/app/(home)/page.tsx"
click node_ecosystem "https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/ecosystem-section.tsx"
click node_quickstart "https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/quick-start-section.tsx"
click node_tiptap_demo "https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/tiptap-demo-section.tsx"
click node_try_demo "https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/try-it-out-section.tsx"

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_core,node_unicode,node_injection,node_smuggling,node_trojan toneBlue
class node_cli,node_workspace_scan,node_file_resolution,node_scan_cache,node_ignore,node_sanitizer toneAmber
class node_lsp,node_lsp_scan,node_code_actions,node_vscode,node_decorations,node_tiptap,node_tiptap_hover toneMint
class node_home,node_ecosystem,node_quickstart,node_tiptap_demo,node_try_demo toneRose
class node_developer toneIndigo
```

## Components

### Threat Detection

- [Detection Engine](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/core.ts): `packages/core/src/core.ts`
- [Unicode Rules](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/invisible.ts): `packages/core/src/invisible.ts`
- [Injection Rules](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/injection-patterns.ts): `packages/core/src/injection-patterns.ts`
- [Smuggling Rules](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/smuggling.ts): `packages/core/src/smuggling.ts`
- [Trojan Rules](https://github.com/promptshield-io/promptshield/blob/main/packages/core/src/trojan.ts): `packages/core/src/trojan.ts`

### File Workflows

- [CLI Commands](https://github.com/promptshield-io/promptshield/blob/main/packages/cli/src/main.ts): `packages/cli/src/main.ts`
- [Workspace Scanning](https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/workspace.ts): `packages/workspace/src/workspace.ts`
- [File Resolution](https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/resolve-files.ts): `packages/workspace/src/resolve-files.ts`
- [Scan Cache](https://github.com/promptshield-io/promptshield/blob/main/packages/workspace/src/cache.ts): `packages/workspace/src/cache.ts`
- [Ignore Filtering](https://github.com/promptshield-io/promptshield/blob/main/packages/ignore/src/ignore.ts): `packages/ignore/src/ignore.ts`
- [Sanitization](https://github.com/promptshield-io/promptshield/blob/main/packages/sanitizer/src/fix.ts): `packages/sanitizer/src/fix.ts`

### Editor Integrations

- [Language Server](https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/lsp.ts): `packages/lsp/src/lsp.ts`
- [Workspace Editor Scans](https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/workspace-scanning.ts): `packages/lsp/src/workspace-scanning.ts`
- [Code Actions](https://github.com/promptshield-io/promptshield/blob/main/packages/lsp/src/code-actions.ts): `packages/lsp/src/code-actions.ts`
- [VS Code Extension](https://github.com/promptshield-io/promptshield/blob/main/packages/vscode/src/extension.ts): `packages/vscode/src/extension.ts`
- [Threat Decorations](https://github.com/promptshield-io/promptshield/blob/main/packages/vscode/src/decoration-manager.ts): `packages/vscode/src/decoration-manager.ts`
- [Tiptap Protection](https://github.com/promptshield-io/promptshield/blob/main/packages/tiptap/src/plugin.ts): `packages/tiptap/src/plugin.ts`
- [Tiptap Fix UI](https://github.com/promptshield-io/promptshield/blob/main/packages/tiptap/src/hover.ts): `packages/tiptap/src/hover.ts`

### Product Website

- [Website Home](https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/app/(home)/page.tsx): `apps/web/src/app/(home)/page.tsx`
- [Ecosystem Overview](https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/ecosystem-section.tsx): `apps/web/src/components/ecosystem-section.tsx`
- [Quick Start](https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/quick-start-section.tsx): `apps/web/src/components/quick-start-section.tsx`
- [Tiptap Demo](https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/tiptap-demo-section.tsx): `apps/web/src/components/tiptap-demo-section.tsx`
- [Try It Out](https://github.com/promptshield-io/promptshield/blob/main/apps/web/src/components/try-it-out-section.tsx): `apps/web/src/components/try-it-out-section.tsx`

### Other components

- **Developer**

## Connections

- Developer → CLI Commands: runs scans (evidence: `README.md`)
- Developer → VS Code Extension: installs extension (evidence: `README.md`)
- CLI Commands → Workspace Scanning: runs scan (evidence: `packages/cli/src/main.ts`)
- CLI Commands → File Resolution: resolves files (evidence: `packages/cli/src/main.ts`)
- CLI Commands → Ignore Filtering: creates checker (evidence: `packages/cli/src/main.ts`)
- CLI Commands → Detection Engine: scans text (evidence: `packages/cli/src/main.ts`)
- CLI Commands → Workspace Scanning: writes reports (evidence: `packages/cli/src/main.ts`)
- Workspace Scanning → Detection Engine: scans content (evidence: `packages/workspace/src/workspace.ts`)
- Workspace Scanning → Ignore Filtering: filters threats (evidence: `packages/workspace/src/workspace.ts`)
- Workspace Scanning → Sanitization: applies fixes (evidence: `packages/workspace/src/workspace.ts`)
- Workspace Scanning → File Resolution: resolves files (evidence: `packages/workspace/src/workspace.ts`)
- Workspace Scanning → Scan Cache: uses cache (evidence: `packages/workspace/src/workspace.ts`)
- Language Server → Detection Engine: scans documents (evidence: `packages/lsp/src/lsp.ts`)
- Language Server → Ignore Filtering: filters threats (evidence: `packages/lsp/src/lsp.ts`)
- Language Server → Code Actions: builds actions (evidence: `packages/lsp/src/lsp.ts`)
- Language Server → Workspace Editor Scans: dispatches workspace (evidence: `packages/lsp/src/lsp.ts`)
- Workspace Editor Scans → Detection Engine: scans files (evidence: `packages/lsp/src/workspace-scanning.ts`)
- Workspace Editor Scans → Workspace Scanning: uses workspace engine
- Code Actions → Sanitization: applies fixes (evidence: `packages/lsp/src/code-actions.ts`)
- VS Code Extension → Language Server: starts server
- VS Code Extension → Threat Decorations: updates highlights
- Tiptap Protection → Detection Engine: scans editor text (evidence: `packages/tiptap/src/plugin.ts`)
- Tiptap Fix UI → Tiptap Protection: uses plugin key (evidence: `packages/tiptap/src/hover.ts`)
- Tiptap Fix UI → Tiptap Protection: invokes fixes (evidence: `packages/tiptap/src/hover.ts`)
- Website Home → Ecosystem Overview: renders (evidence: `apps/web/src/app/(home)/page.tsx`)
- Website Home → Quick Start: renders (evidence: `apps/web/src/app/(home)/page.tsx`)
- Website Home → Tiptap Demo: renders (evidence: `apps/web/src/app/(home)/page.tsx`)
- Website Home → Try It Out: renders (evidence: `apps/web/src/app/(home)/page.tsx`)
- Quick Start → Detection Engine: demonstrates scanning (evidence: `apps/web/src/components/quick-start-section.tsx`)
- Tiptap Demo → Tiptap Protection: demonstrates integration (evidence: `apps/web/src/components/tiptap-demo-section.tsx`)
- Tiptap Demo → Detection Engine: demonstrates scanning (evidence: `apps/web/src/components/tiptap-demo-section.tsx`)
