- High-Level Overview
- Core Components & Interaction Flow
- Key Architectural Patterns
- Development Infrastructure
- Testing Infrastructure
- Build & Release Management
- Documentation Structure
- Developer Workflow
Hyperchat is a native macOS application that provides a multi-service interface to various AIs. The user can summon a prompt window via a floating button, enter a query, and see the results across multiple services simultaneously in a unified overlay window. The architecture is event-driven, using a combination of NSNotificationCenter for cross-module communication and Combine publishers for direct state updates between related components.
Here is the step-by-step flow of a typical user interaction:
- Job: Manages the application lifecycle. On launch, it creates and connects all the primary controller objects.
- Interaction:
- Initializes FloatingButtonManager, PromptWindowController, and OverlayController.
- Initializes AnalyticsManager for usage tracking (enabled by default, user can disable).
- Acts as a central listener for key notifications, delegating tasks to the appropriate controller.
- Job: Manages the small, persistent floating button that is always on screen.
- Interaction:
- On Click: When the user clicks the floating button, it calls promptWindowController.showWindow(...) to display the input field.
- Job: Manages the popup window where the user types their prompt.
- Interaction:
- On Submit: When the user types a prompt and hits enter, it posts a notification named .showOverlay to the system, packaging the prompt text with it. It then closes itself.
- Job: Manages the main window(s) that host the AI services.
- Interaction:
- Receives Notification: The AppDelegate catches the .showOverlay notification from the PromptWindowController and calls overlayController.showOverlay(with: prompt).
- Creates Window: It creates a new OverlayWindow.
- Creates Controllers: For each service, it creates a BrowserViewController and registers it with the ServiceManager.
- Handoff to Logic: Crucially, it creates a new, dedicated ServiceManager for that window and then calls serviceManager.executePrompt(prompt).
- Job: Core orchestration unit that manages AI services and executes prompts. Refactored to focus solely on service management (reduced from 1600+ to under 900 lines).
- Interaction:
- Service Setup: Uses WebViewFactory to create WKWebViews, manages sequential loading of services
- State Updates: Publishes loading state via Combine (
@Published var areAllServicesLoaded
) and input focus events viafocusInputPublisher
- Executes Prompt: It iterates through its list of active services and tells each one to execute the prompt. The method of execution depends on the service type:
- URLParameterService (Google, Perplexity, etc.): Constructs a URL with the prompt as a query parameter (e.g., google.com/search?q=...) and tells the corresponding WKWebView to load it.
- ClaudeService (and "Reply to All" mode): Navigates to the service's base URL and uses JavaScriptProvider to inject scripts that find the chat input, paste the prompt, and programmatically click the "submit" button.
- Delegate Handoff: After initial load, hands navigation control to BrowserViewController
- Job: Centralized factory for creating and configuring WKWebViews with all necessary settings
- Interaction:
- Creates WebViews: Configures process pools, user agents, content scripts, and message handlers
- Shared Configuration: Ensures consistent WebView setup across all services
- Memory Optimization: Uses shared WKProcessPool for all WebViews
- Job: MVC controller that manages browser logic, navigation, and user interactions
- Interaction:
- Navigation Management: Takes over as WKNavigationDelegate after initial service load
- UI Updates: Manages URL display, back/forward buttons, and loading states
- User Actions: Handles reload, URL entry, and clipboard operations
- Job: Pure view component that layouts browser UI elements
- Interaction:
- Layout Only: Manages visual arrangement of WebView, toolbar, and URL field
- No Logic: Delegates all actions to BrowserViewController
- ButtonState: Observable state model for toolbar buttons
- GradientToolbarButton: SwiftUI component for animated toolbar buttons
- Job: Centralized repository for all JavaScript code used throughout the application
- Interaction:
- Script Generation: Provides static methods that return JavaScript strings for various operations
- Clean Separation: Isolates 300+ lines of JavaScript from ServiceManager into organized, reusable methods
- Key Scripts: Paste automation, Claude-specific interactions, window hibernation pause/resume
- Job: Centralized analytics service using Amplitude for usage tracking and product improvement
- Interaction:
- Event Tracking: Collects usage data on prompt submissions, button clicks, and webview interactions
- Privacy-Focused: No PII collected, only usage patterns and feature adoption metrics
- Source Attribution: Tracks whether prompts come from floating button vs direct window access
- Service Usage: Monitors which AI services users interact with most frequently
- Configuration: Loads API keys from Config.swift (excluded from version control)
- Hybrid Communication Model:
- NSNotificationCenter: Used for cross-module events where loose coupling is beneficial (e.g., .showOverlay, .overlayDidHide)
- Combine Publishers: Used for direct state updates between tightly related components (e.g., ServiceManager to OverlayController loading states)
- Dedicated ServiceManager per Window: Each OverlayWindow gets its own ServiceManager. This is a critical design choice for stability, isolating the web environments from each other and preventing crashes in one window from affecting others.
- Shared WKProcessPool: While each window has its own ServiceManager, all WKWebViews share a single WKProcessPool. This is a key memory optimization that significantly reduces the app's overall footprint.
- Factory Pattern: WebViewFactory centralizes all WKWebView configuration, ensuring consistency and easier maintenance.
- MVC Separation: BrowserViewController (controller) handles browser logic while BrowserView (view) handles pure UI layout.
- Delegate Handoff: ServiceManager manages initial load with sequential queue, then hands navigation control to BrowserViewController for ongoing interaction.
- JavaScript Isolation: All JavaScript code is centralized in JavaScriptProvider, making it easier to maintain and test complex browser automation scripts.
The project includes comprehensive automation and tooling for development, testing, and deployment:
The automation scripts handle the entire development lifecycle:
-
deploy-hyperchat.sh
: Complete deployment pipeline that builds, signs, notarizes, and creates DMG packages for distribution. Handles version bumping, Apple notarization workflow, and Sparkle update generation. -
run-tests.sh
: Comprehensive test runner that executes both unit and UI tests, generates reports, and provides cleanup options. Supports selective test execution and HTML report generation. -
sync-sparkle-keys.sh
: Sparkle update key management that synchronizes EdDSA public keys in Info.plist with private keys to prevent signature mismatches. -
menu-test.sh
: Quick menu functionality testing for debugging menu bar interactions and accessibility settings. -
swift-test.sh
: Swift testing utilities for targeted test execution and debugging workflows. -
cleanup-tests.sh
: Cleans test artifacts and temporary files to maintain a clean development environment.
The project uses Swift Package Manager with key dependencies:
- Sparkle (2.6.0+): Automatic update framework for macOS applications
- AmplitudeSwift (1.0.0+): Analytics and usage tracking
- Test Targets: Separate test targets for unit tests (
HyperchatTests
) and UI tests (HyperchatUITests
)
- Xcode Project: Traditional Xcode project structure with SPM integration
- Build Configurations: Separate debug and release configurations with different entitlements
- Code Signing: Automated signing with Developer ID for direct distribution
- Notarization: Integrated Apple notarization workflow for security compliance
The project maintains comprehensive test coverage with a dual test structure and automated CI workflows:
-
Dual Test Structure: Tests exist in both legacy (
HyperchatTests/
,HyperchatUITests/
) and modern (Tests/HyperchatTests/
,Tests/HyperchatUITests/
) directory structures for backward compatibility and migration flexibility. -
Test Types:
- Unit Tests (
HyperchatTests
): Core business logic testing including service configuration, AI service management, and component integration - UI Tests (
HyperchatUITests
): End-to-end user interaction testing including window management, prompt submission, and cross-service functionality - Menu Tests (
MenuUnitTests
,MenuUITests
): Specialized testing for menu bar interactions and settings
- Unit Tests (
ServiceConfigurationTests
: Validates AI service URL generation, parameter encoding, and configuration managementAIServiceTests
: Tests service activation, ordering, icon management, and default configurationsServiceManagerTests
: Core orchestration testing including service loading, WebView lifecycle, state management, and service reorderingWebViewMocks
: Mock objects that simulate WKWebView behavior without actual web content, enabling fast and reliable unit testingMenuUnitTests
: Tests menu bar integration, settings synchronization, and user preferences
- Local Development:
Scripts/run-tests.sh
provides comprehensive test execution with reporting, cleanup options, and HTML output generation - Continuous Integration: Automated test execution on GitHub Actions for all pull requests and main branch commits
- Selective Testing: Support for running specific test suites, classes, or individual test methods
- Test Artifacts: Automatic generation of test reports, coverage data, and failure diagnostics
- Mock-First Testing: Heavy use of mock objects to isolate business logic from WebKit dependencies
- Accessibility Integration: UI tests leverage accessibility identifiers for reliable element targeting
- Parallel Test Execution: Tests designed to run in parallel without state conflicts
- Coverage Reporting: Integrated code coverage tracking with detailed reports in Xcode and CI
The project uses a sophisticated build and release pipeline designed for both development and production distribution:
-
DerivedData/
: Xcode build artifacts including compiled binaries, module caches, and intermediate build files. Contains Swift module compilation cache for faster incremental builds. -
Export/
: Distribution-ready builds including signed applications and DMG packages. Houses final release artifacts ready for distribution. -
Hyperchat.xcarchive/
: Xcode archive bundles containing signed applications with debug symbols (dSYMs) for crash analysis and debugging.
- Developer ID Signing: Uses specific certificate identity (configured via APPLE_CERTIFICATE_IDENTITY environment variable) for direct distribution outside the Mac App Store
- Entitlements Management: Separate entitlement files for debug (
Hyperchat.entitlements
) and release (Hyperchat.Release.entitlements
) builds - Notarization Pipeline: Automated submission to Apple's notary service with ticket stapling for security compliance
- Version Management: Automatic build number incrementation and version tagging
- Archive Creation: Xcode archive generation with release configuration and optimizations
- Export & Signing: Application export from archive with Developer ID signing
- Notarization: Automated submission to Apple notary service with status monitoring
- DMG Creation: Packaging into distributable disk images with custom layouts
- Sparkle Integration: Generation of update manifests and signature files for automatic updates
- Distribution: Upload to servers and update feed publication
Info.plist
: Application metadata, bundle identifiers, version information, and system capabilitiesConfig.swift.template
: Template for sensitive configuration including API keys and service endpoints- Environment-Specific Builds: Different configurations for development, staging, and production environments
- Asset Management: Icon sets, fonts (Orbitron-Bold.ttf), and other bundled resources
- GitHub Actions Integration: Automated build and release workflows triggered by version tags
- Artifact Generation: Automatic creation of release packages, debug symbols, and distribution manifests
- Quality Gates: Build and test execution before release artifact generation
- Release Notes Integration: Automatic generation from RELEASE_NOTES.html for update notifications
The project maintains comprehensive documentation organized by purpose and audience:
README.md
(this file): Complete system overview covering runtime architecture, development infrastructure, testing, and build processesTesting.md
: Detailed testing guide with execution instructions, test organization, and best practicesREADME_LOGGING.md
: Logging configuration, debug output management, and troubleshooting workflowsHyperchat-product-spec.md
: Product requirements, feature specifications, and design decisions
Practical guides for specific development challenges:
deploy-outside-the-app-store.md
: Complete deployment process for direct distribution, notarization, and DMG creationSPM-Development.md
: Swift Package Manager integration, dependency management, and build configurationSparkle-guide.md
: Automatic update system integration and configurationmacos-window-management.md
: Window management patterns and space awarenessdual-mode-macos-apps.md
: Architecture patterns for LSUIElement applicationsWKWebView-Overlay-Alignment-Debug.md
: WebView debugging and layout troubleshooting- Additional specialized guides for menu debugging, accessory switching, and macOS development patterns
Service-specific automation guides and implementation notes:
browser-automation-guide.md
: General patterns, timing considerations, and JavaScript injection strategiesChatGPT/ChatGPT-notes.md
: OpenAI-specific automation patterns and DOM interaction strategiesClaude/
:claude-notes.md
: Claude.ai automation patterns and React component interactionProseMirror-React-Nextjs-automation-guide.md
: Detailed guide for Claude's ProseMirror editor integrationclaude-raw-source-code.html
: Reference implementation for complex automation scenarios
Google/Google-notes.md
: Google Search automation and result parsingPerplexity/Perplexity-notes.md
: Perplexity-specific automation patterns and content div interactions
Historical context and debugging documentation:
- Debugging Logs:
Debugging-EXC_BAD_ACCESS-WKWebView-Crashes.md
,webview-loading-issues.md
- Architecture Evolution:
LSUIElement-Architecture-Fix-Log.md
,Space-Aware-Floating-Button.md
- Feature Implementation:
AI-services-menu-dropdown-sync.md
,WebViewLogger-Usage.md
- Service Integration: Notes on Sparkle updates, analytics integration, and service-specific challenges
The documentation follows an LLM-First approach where every comment and document is written to provide maximum context for AI-assisted development. This includes:
- Explicit Cross-References: Clear connections between related files and components
- Context-Rich Comments: Detailed explanations of why decisions were made, not just what they do
- Comprehensive Examples: Real implementation examples with detailed explanations
- Historical Context: Documentation of failed approaches and lessons learned
- New Developers: Start with this
README.md
for system overview - Browser Automation: Begin with
Documentation/Websites/browser-automation-guide.md
- Testing: Use
Documentation/Testing.md
for test execution and development - Deployment: Follow
Documentation/Guides/deploy-outside-the-app-store.md
for release processes
Common development tasks and their execution methods:
# Run all tests
./Scripts/run-tests.sh
# Run specific test suite
./Scripts/run-tests.sh --no-cleanup # Keep artifacts for inspection
xcodebuild test -scheme Hyperchat -only-testing:HyperchatTests
# Clean build artifacts
./Scripts/cleanup-tests.sh
# Quick menu functionality test
./Scripts/menu-test.sh
# Run unit tests only
xcodebuild test -scheme Hyperchat -only-testing:HyperchatTests
# Run UI tests only
xcodebuild test -scheme Hyperchat -only-testing:HyperchatUITests
# Generate test coverage report
# Run tests with Cmd+U in Xcode, then check Report Navigator
# Run specific test class
xcodebuild test -scheme Hyperchat -only-testing:HyperchatTests/ServiceConfigurationTests
# Full deployment pipeline (build, sign, notarize, create DMG)
./Scripts/deploy-hyperchat.sh
# Sync Sparkle keys (run automatically during build)
./Scripts/sync-sparkle-keys.sh
# Swift testing utilities
./Scripts/swift-test.sh
# Clean test artifacts and derived data
./Scripts/cleanup-tests.sh
# Build for testing (without running tests)
xcodebuild build-for-testing -scheme Hyperchat -destination 'platform=macOS'
# Run app in debug mode from command line
# (Build in Xcode first, then locate in Export/ directory)
./Export/Hyperchat.app/Contents/MacOS/Hyperchat
- Set up Config.swift: Copy
Config.swift.template
toConfig.swift
and add API keys - Development vs Release: Use appropriate entitlements file for target environment
- Sparkle Setup: Ensure private key exists at
~/.keys/sparkle_ed_private_key.pem
- Build Failures: Check
deploy-debug.log
for detailed build output - Test Failures: Review
TestResults/*.log
files and Xcode test navigator - WebView Issues: Enable WebViewLogger and check console output
- Menu Problems: Use menu debugging scripts and check accessibility settings
- Signing Issues: Verify certificate identity and provisioning profiles
- Clean Builds: Remove
DerivedData/
directory for fresh compilation - Test Performance: Use
--no-cleanup
flag to inspect test artifacts - Memory Issues: Monitor WebView process pool usage in Activity Monitor
- JavaScript Debugging: Use Safari Web Inspector with WebView content
For browser automation work, start with Documentation/Websites/browser-automation-guide.md
and then refer to the service-specific directories for detailed implementation notes.