How gluonfield/enchanted works
Main Components
• Frontend (UI): There are separate UI folders for iOS, macOS, and shared UI components. Include chat interfaces, settings panels, conversation history views, and platform-specific views (e.g., MenuBar on macOS, prompt panels, voice components, etc.).
• Application Logic: The central Application entry point (EnchantedApp.swift) and the use of Stores (e.g., AppStore, ConversationStore) indicate a clear separation of state management.
• Services Layer: Several service classes (Clipboard, Haptics, Hotkey, OllamaService, SpeechService, SwiftDataService, etc.) handle business logic (networking to the Ollama server, speech synthesis, text-to-speech, etc.).
• Models/Data: Models for language models, notifications, conversations, and custom SwiftData models represent domain entities.
• Extensions & Helpers: These add additional functionality to standard types and provide utility methods across the app.
• External Dependencies: The app requires a connection to an externally hosted Ollama server (the README outlines how to set up server endpoints). This is your external API dependency.
Relationships and Data Flows
• The UI components interact with the Stores for state management, which drive the chat messages, conversation history, and settings.
• Stores and Models connect with the Services layer. For example, the OllamaService sends/receives API requests to the Ollama server, while SpeechService manages text-to-speech.
• The Helpers and Extensions augment functionality (e.g., accessibility, image handling, formatting) across the UI and backend logic.
• There is data persistence through SwiftData (a folder dedicated to SwiftData models and operations).
Important Architectural Patterns
• Separation of Concerns: Notice clear divisions between the UI layer (presentation), the business logic layer (services/stores), and the data layer (models/SwiftData).
• Cross-Platform Design: The architecture differentiates platform-specific components (in UI/macOS, UI/iOS, etc.) while keeping shared UI code in UI/Shared.
• Modular Design: Each directory represents a module or layer (Services, Models, Extensions, etc.), making the system highly extensible and easier to maintain.
• Dependency Injection and Data Flow: The use of Stores to mediate state, with their reliance on Services, shows the influence of modern SwiftUI best practices.
Relevant Technologies and Frameworks
• Swift and SwiftUI for user interfaces.
• Xcode project structure and tools.
• SwiftData for local data persistence.
• Integration with Ollama server (an open-source, locally hosted ML model server).
• Use of Apple-specific frameworks (for accessibility, text-to-speech, and platform-specific UI elements).
Elements
• Inter-module interactions: indicate that the UI references shared UI components and that platform-specific UIs extend or utilize the shared logic.