How talgaon4/promptimzer works
Project type and purpose
• This is a Chrome extension (“Promptimizer”) that provides AI‐based prompt optimization for chat interfaces (ChatGPT, Claude, Gemini).
• It consists of a service worker (background.js), a content script (content_script.js), a popup UI, an options/settings page, and a local “prompts” template library.
File structure
• Top‐level files:
• manifest.json – extension metadata and permission declarations
• background.js – service worker handling API calls, classification, optimization logic, storage
• content_script.js – injects “Optimize Prompt” button into supported chat pages and relays user actions to background
• popup.html/js – quick‐access UI to input a prompt and get optimization
• options.html/js/css – settings page for entering API key and max tokens
• styles.css, options.css – shared and page‐specific styling
• prompts/*.txt – template files for different prompt categories
• No backend server: all logic runs client‐side, with remote calls only to OpenAI API.
README for additional insights
• Two‐step process: classification → optimization
• Privacy focus: API key and data are stored locally using Chrome storage
• Rate limiting and token‐limit controls
Diagramming the architecture
a. Main components
• Chrome Browser Extension Host
• Background Service Worker (background.js)
• Content Script (content_script.js)
• Popup UI (popup.html/js)
• Options/Settings Page (options.html/js/css)
• Local Storage (Chrome Storage API)
• OpenAI API (external service)
• Prompt Templates (prompts/*.txt)
b. Relationships and interactions
1. User clicks “Optimize Prompt” in injected UI (content script) or popup
2. Content script or popup sends a message to background.js via chrome.runtime.sendMessage
3. Background.js:
– Loads classification template (classifier.txt) from prompts/
– Classifies input prompt
– Loads category‐specific template (e.g. complex.txt)
– Calls OpenAI API with user’s API key and combined prompt+template
– Receives optimized text
– Sends response back to content script or popup
4. UI component updates the text field or clipboard
5. Options page reads/writes API key and token limit to Chrome Storage
c. Architectural patterns and principles
• Event‐driven by Chrome Extension messaging
• Single Responsibility: UI logic ↔ background logic ↔ storage
• Privacy by design: local storage only, no external servers
• Pluggable templates: file‐based strategy for extensibility
d. Key technologies and libraries
• JavaScript for all logic
• Chrome Extensions APIs: runtime, storage, tabs, permissions
• HTML/CSS for popup and options pages
• OpenAI REST API for prompt optimization