# preambleai/prompt-injector architecture

> Architecture diagram of the GitHub repository preambleai/prompt-injector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/preambleai/prompt-injector
- Repository: https://github.com/preambleai/prompt-injector

## Overview

##### Project type and purpose
- This is a full-stack, desktop Electron application (“Prompt Injector”) for AI security testing, combining a React/TypeScript UI with a Node.js/Electron main process, local data storage (SQLite), and integrations to external AI provider APIs.

##### File structure
- Top-level:
- .github/workflows → CI/CD pipelines (automated and manual builds)
- scripts/ → build-and-release helpers
- src/main → Electron main process (main.ts, preload.ts) and Node-side services
- src (root) → React entry points (main.tsx, App.tsx), UI components, pages, and front-end service wrappers
- public/assets/payloads → JSON library of attack payloads
- Configuration files: vite.config.ts, tsconfig*.json, jest.config.js, tailwind.config.js

##### README for additional insights
- Tech stack: Electron 25, React 18 + TypeScript + Tailwind CSS, Node.js with Express-style services, Vite build system, SQLite, external AI APIs (OpenAI, Anthropic, Google Gemini, Ollama).
- Build and release: GitHub Actions workflows trigger scripts/build-all.js and scripts/create-release.js to produce installers for macOS, Windows, Linux.

a. Main components
- Renderer Process (React UI): pages, components, Vite-bundled front end
- Electron Main Process: Node.js host, Express-style internal API (if any), preload.ts (IPC bridge)
- Business-Logic Services (under src/services and src/main/services): attack-engine, model-manager, semantic-guardian, payload-manager, etc.
- Data stores:
- SQLite local database
- Payload JSON file (all-attack-payloads.json)
- External AI Providers: OpenAI, Anthropic, Google, Ollama (HTTPS)
- CI/CD Pipeline: GitHub Actions workflows, build & release scripts

b. Relationships & interactions
- UI ↔ Main via Electron IPC (preload.ts exposes safe APIs)
- Main Process → Business Logic Services (invokes attack runs, payload generation)
- Services → Data stores for read/write (SQLite CRUD, JSON reads)
- Services → External AI Providers over HTTPS for model calls
- GitHub Actions → scripts → electron-builder → installable packages

c. Architectural patterns & principles
- Multi-process layering (Renderer vs. Main)
- Clear separation of concerns: Presentation (React), Application logic (services), Data layer (SQLite/JSON), External integrations (AI APIs)
- Local-first, offline-capable architecture

d. Key technologies to call out
- Electron (Main + Renderer)
- React + TypeScript + Tailwind + Vite
- Node.js, SQLite, file system
- External HTTP clients (fetch or axios) to AI APIs
- GitHub Actions, custom build scripts, electron-builder

##### Capturing essential elements
- Be thorough but not cluttered: group related modules
- Data flows (user action → test execution → result analysis → storage) are visible

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Renderer Process
    subgraph "Renderer Process"
        UI_Entry["src/main.tsx"]:::ui
        App["src/App.tsx"]:::ui
        Components["src/components/"]:::ui
        Pages["src/pages/"]:::ui
        PublicHTML["public/index.html"]:::ui
    end

    %% Electron Main Process
    subgraph "Electron Main Process"
        MainTS["src/main/main.ts"]:::main
        Preload["src/main/preload.ts"]:::main
    end

    %% Front-end Build Configuration
    subgraph "Front-end Build Config"
        Vite["vite.config.ts"]:::config
        Tailwind["tailwind.config.js"]:::config
        PostCSS["postcss.config.js"]:::config
    end

    %% Business Logic (Renderer-side)
    subgraph "Business Logic (Renderer)"
        AttackEngR["attack-engine.ts"]:::service
        ModelMgrR["model-manager.ts"]:::service
        SemanticR["semantic-guardian.ts"]:::service
        PayloadMgrR["payload-manager.ts"]:::service
        AIIntegration["ai-api-integration.ts"]:::service
        LLMadapter["llm-adapter.ts"]:::service
    end

    %% Business Logic (Main-side)
    subgraph "Business Logic (Main)"
        AttackEngM["src/main/services/attack-engine.ts"]:::service
    end

    %% Data Stores
    subgraph "Data Stores"
        SQLite["SQLite Database"]:::datastore
        PayloadJSON["all-attack-payloads.json"]:::datastore
    end

    %% External AI Providers
    subgraph "External AI Providers"
        OpenAI["OpenAI"]:::external
        Anthropic["Anthropic"]:::external
        Gemini["Google Gemini"]:::external
        Ollama["Ollama"]:::external
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        Workflows[".github/workflows/"]:::cicd
        Scripts["scripts/"]:::cicd
        Installers["Installers"]:::cicd
    end

    %% Connections - UI to Renderer Components
    UI_Entry --> App
    App --> Components
    App --> Pages
    App --> PublicHTML

    %% IPC Bridge
    App -->|"IPC"| Preload
    Preload -->|"IPC"| MainTS

    %% Renderer to Renderer-side Services
    App --> AttackEngR
    App --> ModelMgrR
    App --> SemanticR
    App --> PayloadMgrR
    App --> AIIntegration
    App --> LLMadapter

    %% Invoke Main-side Service from Renderer Service
    AttackEngR -->|"via IPC"| AttackEngM

    %% Main Process to Main-side Services
    MainTS --> AttackEngM

    %% Services to Data Stores
    AttackEngM --> SQLite
    AttackEngM --> PayloadJSON
    PayloadMgrR --> PayloadJSON

    %% Services to External AI Providers
    AttackEngM --> OpenAI
    AttackEngM --> Anthropic
    AttackEngM --> Gemini
    AttackEngM --> Ollama
    AIIntegration --> OpenAI
    AIIntegration --> Anthropic
    AIIntegration --> Gemini
    AIIntegration --> Ollama

    %% CI/CD Workflow
    Workflows --> Scripts
    Scripts --> Installers

    %% Click Events
    click UI_Entry "https://github.com/preambleai/prompt-injector/blob/main/src/main.tsx"
    click App "https://github.com/preambleai/prompt-injector/blob/main/src/App.tsx"
    click Components "https://github.com/preambleai/prompt-injector/tree/main/src/components/"
    click Pages "https://github.com/preambleai/prompt-injector/tree/main/src/pages/"
    click PublicHTML "https://github.com/preambleai/prompt-injector/blob/main/public/index.html"
    click MainTS "https://github.com/preambleai/prompt-injector/blob/main/src/main/main.ts"
    click Preload "https://github.com/preambleai/prompt-injector/blob/main/src/main/preload.ts"
    click Vite "https://github.com/preambleai/prompt-injector/blob/main/vite.config.ts"
    click Tailwind "https://github.com/preambleai/prompt-injector/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/preambleai/prompt-injector/blob/main/postcss.config.js"
    click AttackEngR "https://github.com/preambleai/prompt-injector/blob/main/src/services/attack-engine.ts"
    click ModelMgrR "https://github.com/preambleai/prompt-injector/blob/main/src/services/model-manager.ts"
    click SemanticR "https://github.com/preambleai/prompt-injector/blob/main/src/services/semantic-guardian.ts"
    click PayloadMgrR "https://github.com/preambleai/prompt-injector/blob/main/src/services/payload-manager.ts"
    click AIIntegration "https://github.com/preambleai/prompt-injector/blob/main/src/services/ai-api-integration.ts"
    click LLMadapter "https://github.com/preambleai/prompt-injector/blob/main/src/services/llm-adapter.ts"
    click AttackEngM "https://github.com/preambleai/prompt-injector/blob/main/src/main/services/attack-engine.ts"
    click PayloadJSON "https://github.com/preambleai/prompt-injector/blob/main/public/assets/payloads/all-attack-payloads.json"
    click Workflows "https://github.com/preambleai/prompt-injector/tree/main/.github/workflows/"
    click Scripts "https://github.com/preambleai/prompt-injector/tree/main/scripts/"
    
    %% Styles
    classDef ui fill:#D0E6FF,stroke:#1E70BF,stroke-width:2px
    classDef main fill:#DFF4D8,stroke:#2E8B57,stroke-width:2px
    classDef service fill:#FFF4D0,stroke:#D1A517,stroke-width:2px
    classDef datastore fill:#FFE0B2,stroke:#E68300,stroke-width:2px
    classDef external fill:#E8DAFF,stroke:#7D3C98,stroke-width:2px
    classDef config fill:#F0F0F0,stroke:#A0A0A0,stroke-width:1px
    classDef cicd fill:#E0E0E0,stroke:#4A4A4A,stroke-width:2px
```
