Project Structure
The main source code is organized in theDefaultTamer/ directory:
Core Components
Models
Data structures representing core concepts:Models Directory
Also includes:
AppError.swift- Error typesGitHubRelease.swift- Update checking
Services
Business logic and core functionality:AppState.swift
Central state management for the entire app:AppState.swift:13-31
Key Responsibilities
Key Responsibilities
- Manages app-wide settings and rules
- Coordinates between different managers
- Handles URL routing requests
- Publishes state changes to views
- Thread-safe rule management via dispatch queue
URL Handling Flow
URL Handling Flow
- Receives URL from
AppDelegate - Detects source application
- Routes through
Router.route() - Executes resulting action
- Logs activity if diagnostics enabled
Router.swift
Pure routing decision engine:Router.swift:17-58
BrowserManager.swift
Discovers and manages installed browsers:Other Services
PersistenceManager.swift- UserDefaults storageDiagnosticsManager.swift- Activity loggingSourceAppDetector.swift- Source app detectionActivityDatabase.swift- SQLite loggingUpdateManager.swift- Sparkle updates
Views
SwiftUI views for the user interface:MenuBarPopover.swift
Menu bar dropdown showing app status, preferences, and rules access
FirstRunView.swift
Onboarding window shown on first launch
PreferencesWindow.swift
Settings and configuration interface
RulesWindow.swift
Rule management interface with drag-to-reorder
BrowserChooser.swift
Manual browser selection dialog (shown when holding Option)
RecentRoutesView.swift
Activity log viewer (when diagnostics enabled)
Utilities
Helper functions and extensions:Logging & Debugging
Logging & Debugging
UnifiedLogger.swift- Centralized loggingDebugLog.swift- Debug output helpersLogging.swift- Log utilities
URL Processing
URL Processing
URLSanitizer.swift- Strips sensitive data from URLsURLHelpers.swift- URL parsing and validationRegexValidator.swift- Regex pattern validation
App Integration
App Integration
LaunchAtLogin.swift- Launch at login managementApplicationScanner.swift- Finds installed appsAppResolver.swift- Resolves bundle IDs to apps
UI Utilities
UI Utilities
ToastManager.swift- Toast notificationsErrorNotification.swift- Error alertsColor+Extensions.swift- Color helpersConstants.swift- UI constants
Data Management
Data Management
RuleImportExport.swift- Rule backup/restoreErrorHandler.swift- Error handling
Application Entry Points
DefaultTamerApp.swift
Main SwiftUI app structure:The app uses
NSApplicationDelegateAdaptor to integrate AppKit functionality while maintaining a SwiftUI structure.AppDelegate.swift
AppKit delegate for system integration:AppDelegate.swift:25-114
Data Flow
Here’s how a URL flows through the application:Design Patterns
ObservableObject Pattern
AppState uses SwiftUI’s ObservableObject protocol:
Manager Pattern
Separate managers handle specific concerns:BrowserManager- Browser discovery and launchingPersistenceManager- Data storageDiagnosticsManager- Activity loggingUpdateManager- Software updates
Pure Functions
Router.route() is a pure function with no side effects:
- Takes all needed data as parameters
- Returns a decision (RouteAction)
- Does not modify state or perform I/O
Next Steps
Building
Learn how to build and run the app
Contributing
Read the contribution guidelines