How prateekkeshari/peek-ai works
Project type and purpose
• Peek is an Electron-based MacOS “menu bar” application that provides a unified UI for chatting with multiple AI chatbots (ChatGPT, Bard, Perplexity) plus a social Threads feed. It is a desktop app, not a web service or microservice suite.
File structure
• Top‐level Electron entry scripts:
• .electron-main.js (or main.js) – the Electron main process bootstrapper
• screenshot.js – handles screenshot capture and clipboard logic
• preload.js – exposes safe IPC and Node APIs to the renderer
• UI directory (UI/): contains all HTML, CSS, and JS for the renderer windows—index.html (main chat), dialog.html (modal dialogs), onboarding.html (first-run UX), with their corresponding CSS/JS.
• Configuration and metadata: package.json, preferences.json, .gitignore, GitHub Actions workflow, dev-app-update.yml (auto-update settings).
Key insights from the README
• Electron auto-updater integration
• Menu bar (tray) application with global keyboard shortcuts
• IPC bridging between UI and native features (screenshot, auto-update, preferences)
• External HTTP calls to AI chatbot services and Threads
Main components
a. Electron Main Process
• Window Management (open/close toggle for main UI via ⌘+J)
• Auto-Updater (dev-app-update.yml + electron-updater integration)
• Screenshot Service (screenshot.js)
• Preferences Management (read/write preferences.json)
• IPC channels to/from Renderer (via preload.js)
b. Renderer Processes (UI)
• Main Chat Window (UI/index.html + UI/scripts.js)
• Dialogs & Onboarding (UI/dialog.* + UI/onboarding.*)
• CSS styling (UI/styles.css, UI/dialog.css)
• Preload Script Sandbox (preload.js exposing limited Node/IPC)
c. External Services
• OpenAI ChatGPT API
• Google Bard API
• Perplexity AI API
• Threads Social Feed API
d. Local Persistence
• preferences.json for user settings
• Screenshot files saved to disk or clipboard
Relationships & data flow
2. Renderer initiates a chat message → Sends via IPC (preload) → Main Process performs HTTP request to selected chatbot API → Returns response via IPC → Renderer updates UI.
3. User presses screenshot shortcut → Main Process captures screen (screenshot.js) → Saves/clipboard → Optionally notifies Renderer.
4. Auto‐update check on launch/interval → Main Process fetches update metadata → If update available, notifies Renderer or shows menu item.
5. User changes settings in UI → Renderer sends IPC to Main → Main writes to preferences.json.
Architectural patterns & design principles
• Electron Multi‐Process Model (separate Main and Renderer)
• IPC Layer via Preload to isolate Node APIs from untrusted UI code
• Single‐Page Renderer windows (HTML/JS/CSS) driven by event handlers
• Modularization of native features (screenshot, menu, auto‐update) into self‐contained scripts
• Use of configuration files for CI/CD, updates, and preferences