# jonathanbertholet/promptmanager architecture

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

- Interactive diagram: https://gitdiagram.com/jonathanbertholet/promptmanager
- Repository: https://github.com/jonathanbertholet/promptmanager

## Overview

##### Project and Its Purpose
- Project Type: Chrome extension.
- Purpose: Manage and organize prompts for various AI chatbots (e.g., ChatGPT, Claude, Gemini, etc.) with capabilities like saving, editing, searching, and importing/exporting prompts.
- Key Functionality: Providing a lightweight, client-side prompt manager that works across different AI platforms by injecting saved prompts into the appropriate chat input fields.

##### File Structure
- Top-Level Files:
- Manifest File: manifest.json – defines extension metadata, permissions, and script bindings.
- HTML Files: popup.html (main UI for prompt management), settings.html (configuration options), info.html (possibly additional extension info).
- JavaScript Files:
- popup.js – drives the popup UI interactions.
- settings.js – manages settings interactions.
- prompts.js – handles creation, editing, and deletion of prompts.
- content.js – acts as a content script that interacts with supported AI chat pages.
- inputBoxHandler.js – responsible for detecting and injecting prompts into input fields.
- importExport.js – handles JSON import/export functionalities.
- utils.js – contains helper functions used across various modules.
- Also, content.js likely coordinates specifically with the injected code into the target chat sites.
- Additional Files: Documentation files (.gitignore, Contributing.md, changelog.html, README.md) provide context but are external to runtime architecture.

##### System Architecture
- Main Components:
- User Interface (UI) Components:
- Popup UI: popup.html and popup.js that show the prompt selection and management interface.
- Settings UI: settings.html and settings.js for configuration and personalized options.
- Info/Help: info.html serving static information.
- Business Logic:
- Prompt Management: prompts.js handles CRUD operations on prompts.
- Import/Export Functionality: importExport.js allows JSON data operations.
- Utilities: utils.js consolidates common helper functionalities.
- Content Injection and Interaction:
- Content Script: content.js injects the extension’s functionality into supported AI platforms.
- Input Field Handler: inputBoxHandler.js manages the interaction with the chat input fields and places selected prompts into these inputs.
- Configuration Layer:
- Manifest File (manifest.json): declares permissions, scripts, and extension metadata ensuring that appropriate scripts (content and UI) are run in the right contexts.

##### Relationships and Data Flow
- The user launches the extension leading to the Popup UI (via popup.html and popup.js).
- Through this UI, the user can select, search, or edit prompts (handled by prompts.js, possibly calling utility functions from utils.js).
- When a prompt is selected, a data flow occurs from the popup UI to the content script (content.js) and then to the inputBoxHandler.js to insert the prompt into the AI chat’s input area.
- Import/Export actions are initiated from the popup and processed by importExport.js, using JSON as the data format.
- Settings changes made in settings.html are processed via settings.js and may update internal configurations stored locally.
- All data (i.e., prompt storage) is handled locally (using the browser’s local storage), ensuring privacy and offline availability.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Distinguishing UI (HTML/JS for popup/settings) from business logic (prompt management and utility functions) and from content interactions (content.js and inputBoxHandler.js).
- Modular Architecture: Each JavaScript file is dedicated to one area of functionality—making the system easier to manage, maintain, and scale.
- Event-Driven Interactions: Utilizing user events (clicks, keyboard navigation) to trigger prompt actions and inter-script communications.
- Client-Side Storage: Local storage is used in lieu of a server, aligning with privacy guidelines.

- Use clear labels to denote each component.
- From User Interactions (clicks, keystrokes) in Popup and Settings UIs => to the prompt manager and then to content/injection modules.
- Another for business logic,
- And another for integration (content/interaction layers).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::external

    subgraph "UI Layer"
        Popup_UI["Popup UI (popup.html + popup.js)"]:::ui
        Settings_UI["Settings UI (settings.html + settings.js)"]:::ui
        Info_Help["Info/Help (info.html)"]:::ui
    end

    subgraph "Business Logic"
        Prompt_Manager["Prompt Manager (prompts.js)"]:::bl
        Import_Export["Import/Export (importExport.js)"]:::bl
        Utilities["Utilities (utils.js)"]:::bl
    end

    subgraph "Content Interaction"
        Content_Script["Content Script (content.js)"]:::ci
        Input_Box_Handler["Input Box Handler (inputBoxHandler.js)"]:::ci
    end

    subgraph "Configuration"
        Manifest["Manifest (manifest.json)"]:::cfg
        Icons["Icons (icons)"]:::cfg
    end

    Local_Storage[("Local Storage")]:::db

    %% User interactions with UI
    User -->|"launches"| Popup_UI
    User -->|"opens"| Settings_UI
    User -->|"views"| Info_Help

    %% UI to Business Logic interactions
    Popup_UI -->|"selectPrompt"| Prompt_Manager
    Popup_UI -->|"initImportExport"| Import_Export

    %% Business Logic internal dependency
    Prompt_Manager -->|"useUtils"| Utilities

    %% Business Logic to Content Interaction flow
    Prompt_Manager -->|"injectPrompt"| Content_Script
    Content_Script -->|"handleInput"| Input_Box_Handler

    %% Business Logic and Settings updating Local Storage
    Import_Export -->|"updateStorage"| Local_Storage
    Settings_UI -->|"updateSettings"| Local_Storage

    %% Configuration defines component behavior
    Manifest -->|"configures"| Popup_UI
    Manifest -->|"configures"| Settings_UI
    Manifest -->|"configures"| Content_Script
    Manifest -->|"references"| Icons

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef bl fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef ci fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef cfg fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef db fill:#87CEFA,stroke:#000,stroke-width:1px;
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:1px;

    %% Click Events
    click Popup_UI "https://github.com/jonathanbertholet/promptmanager/blob/main/popup.html"
    click Popup_UI "https://github.com/jonathanbertholet/promptmanager/blob/main/popup.js"
    click Settings_UI "https://github.com/jonathanbertholet/promptmanager/blob/main/settings.html"
    click Settings_UI "https://github.com/jonathanbertholet/promptmanager/blob/main/settings.js"
    click Info_Help "https://github.com/jonathanbertholet/promptmanager/blob/main/info.html"
    click Prompt_Manager "https://github.com/jonathanbertholet/promptmanager/blob/main/prompts.js"
    click Import_Export "https://github.com/jonathanbertholet/promptmanager/blob/main/importExport.js"
    click Utilities "https://github.com/jonathanbertholet/promptmanager/blob/main/utils.js"
    click Content_Script "https://github.com/jonathanbertholet/promptmanager/blob/main/content.js"
    click Input_Box_Handler "https://github.com/jonathanbertholet/promptmanager/blob/main/inputBoxHandler.js"
    click Manifest "https://github.com/jonathanbertholet/promptmanager/blob/main/manifest.json"
    click Icons "https://github.com/jonathanbertholet/promptmanager/tree/main/icons"
```
