How ichigo3766/open-relay works
1. Product and platform boundary
- This is a native iOS/iPadOS SwiftUI client for an Open WebUI server, branded as Open Relay in the README but still named Open UI in Xcode/project files.
- The app is split into a main iOS app target and a separate widgets/shortcuts extension target (OpenUIWidgets).
2. Top-level app structure
- The app entry point lives in Open_UIApp.swift, with navigation centralized in Navigation/AppRouter.swift and Route.swift.
- The architecture is MVVM: feature views are thin SwiftUI screens, view models own state and user actions, and services/clients handle server and device interactions.
3. Core domain layer
- Open UI/Core/Models contains the app’s domain objects: conversations, chat messages, channels, prompts, skills, tools, knowledge items, notes, models, users, server config, shared content, and analytics-related types.
- Open UI/Core/Extensions provides common transformations such as date formatting, timestamp parsing, and emoji shortcode mapping.
4. Networking boundary
- APIClient, NetworkManager, and APIModels form the server API layer for Open WebUI communication.
- Real-time assistant output is streamed via SSE (SSEStream), while SocketIOService supports socket-based server interactions where needed.
- KeychainService stores auth tokens securely, and APIError defines the network failure boundary.
5. State, storage, and session management
- StorageManager, ServerConfigStore, SharedDataService, and StreamingContentStore hold local app state and server/session state.
- ServerConnectionMonitor tracks connectivity, which is important because many features depend on a live server connection.
- The README and file tree indicate Core Data is used for local persistence, backed by the .xcdatamodeld model.
6. Dependency and service composition
- Core/Services/DependencyContainer.swift is the central composition point that wires view models to services.
- The service layer is where most non-UI behavior lives: conversation management, folders, prompts, skills, tools, knowledge, attachments, notifications, accessibility, appearance, and speech/media services.
7. Primary user experience: chat
- The chat subsystem is the core product path: ChatViewModel, ChatListViewModel, FolderListViewModel, and the views under Features/Chat.
- Chat UI is composed from shared building blocks like ChatInputField, ChatMessageBubble, StreamingMarkdownView, ToolCallView, ModelPickerView, PromptPickerView, and attachment pickers.
- The data flow is: user input → chat view model → service/API client → streaming server response → streaming content store → SwiftUI rendering.
8. Assistant capabilities exposed in the chat composer
- The app supports in-composer selection of models, skills, prompts, knowledge bases, tools, and attachments.
- These are backed by dedicated managers such as ModelManager, PromptManager/PromptService, SkillsManager, ToolsManager, KnowledgeManager, and FileAttachmentService.
- This makes the composer a control surface for server-side assistant configuration, not just text entry.
9. Secondary product areas
- Separate feature groups handle Channels, Archived Chats, Shared Chats, Notes, Terminal, and Voice Call experiences.
- Each area follows the same pattern: feature-specific view models own state, while shared services and API layers provide the backend interaction.
- The terminal and voice call flows are especially stateful and likely rely on specialized services rather than generic chat plumbing.
10. Admin and workspace management
- The Features/Admin area is a dedicated server administration surface with views for analytics, connections, documents, images, integrations, interface, web search, code execution, audio, and general settings.
- Features/Workspace exposes server-side assets such as models, prompts, skills, tools, and knowledge for creation/editing from the device.
- This is a distinct boundary from end-user chat: it manages server configuration and content rather than message exchange.
11. Auth and multi-server onboarding
- Authentication is handled by Features/Auth with support for login, signup, SSO, proxy auth, Cloudflare challenge handling, approval flows, and saved server accounts.
- SavedAccount, ServerConfig, and the auth views indicate the app supports multiple Open WebUI servers and switching between them.
- Tokens are stored locally, while the server connection screen and onboarding flow establish the initial session.
12. Device-native speech, audio, and media
- The app has a substantial media layer: AudioRecordingService, SpeechRecognitionService, OnDeviceASRService, ServerSpeechRecognitionService, TextToSpeechService, MLXTextToSpeechService, TTSTextPreprocessor, and CallKitManager.
- This creates a split between device-local AI/audio features and server-backed speech services, with the UI choosing the engine per setting.
- PythonExecutionService and FunctionsManager suggest additional execution/tooling capabilities exposed through chat or admin workflows.
13. Shared UI and presentation system
- Shared/Components contains reusable UI primitives for rich message rendering, markdown, SVG, Mermaid, HTML previews, tool calls, model/prompt/skill/knowledge pickers, and settings controls.
- Shared/Theme defines tokens for colors, typography, animations, and styling, which keeps the many feature screens visually consistent.
- Accessibility and haptics are also treated as first-class cross-cutting concerns via dedicated services.
14. Extension and cross-surface integration
- OpenUIWidgets is a separate target that provides widget/live activity/control/intent surfaces for shortcuts and quick entry points.
- AppIntentsService and the widget target show the app is integrated into the iOS system UI beyond the main app.
- This extension depends on shared app concepts but runs as its own boundary with a much narrower responsibility.
15. How to draw the architecture
- A useful diagram would place SwiftUI feature screens at the top, view models as the orchestration layer beneath, and core services/networking/storage as the backend-facing middle layer.
- Below that sits the external Open WebUI server plus device-local subsystems such as Keychain, Core Data, CallKit, speech/TTS/ASR, and widgets/shortcuts.
- The main data flows are: authentication/session setup, chat streaming, server configuration and content management, and local persistence/sync of user and app state.
Main entry points: DependencyContainer.swift Dependency DI · APIClient.swift API Client · MainChatView.swift Chat · StorageManager.swift Storage
Components 28
App Shell
Launch, routing, and navigation for the iOS client.
- App Entry · Main iOS app lifecycle and root composition.
Open UI/App/Open_UIApp.swift - App Router · Central route and navigation orchestration.
Open UI/Navigation/AppRouter.swift - Routes · Navigation destinations and path definitions.
Open UI/Navigation/Route.swift
Core Platform
Domain models, networking, state, and cross-cutting services.
- Dependency DI · Wires view models to services and shared state.
Open UI/Core/Services/DependencyContainer.swift - API Client · Primary Open WebUI API access layer.
Open UI/Core/Networking/APIClient.swift - Network Manager · Networking coordination and request plumbing.
Open UI/Core/Networking/NetworkManager.swift - SSE Stream · Real-time assistant output via server-sent events.
Open UI/Core/Networking/SSEStream.swift - Socket IO · Socket-based server interactions where needed.
Open UI/Core/Networking/SocketIOService.swift - Keychain · Secure token storage for server sessions.
Open UI/Core/Networking/KeychainService.swift - Storage · Local app state and persistence coordination.
Open UI/Core/Services/StorageManager.swift - Server Config · Saved servers and active server configuration.
Open UI/Core/Services/ServerConfigStore.swift - Stream Store · Streaming content buffer for live rendering.
Open UI/Core/Services/StreamingContentStore.swift - Conversation Mgr · Conversation lifecycle and chat state operations.
Open UI/Core/Services/ConversationManager.swift - Model Mgr · Model selection and server-side model management.
Open UI/Core/Services/ModelManager.swift - Speech Stack · ASR, TTS, dictation, recording, and call support.
Open UI/Core/Services/SpeechRecognitionService.swift
Feature Surfaces
Primary user-facing flows built on shared core services.
- Chat · Primary message composition, streaming, and conversation UI.
Open UI/Features/Chat/Views/MainChatView.swift - Auth · Login, signup, SSO, proxy auth, and onboarding.
Open UI/Features/Auth/Views/LoginView.swift - Admin · Server administration, analytics, integrations, and settings.
Open UI/Features/Admin/Views/AdminAnalyticsView.swift - Workspace · Create and edit server-side assets like models, prompts, tools, and knowledge.
Open UI/Features/Workspace/Views/WorkspaceView.swift - Settings · Client preferences, privacy, appearance, and storage settings.
Open UI/Features/Settings/Views/SettingsView.swift - Notes · Device-side notes browsing and editing.
Open UI/Features/Notes/Views/NotesListView.swift - Voice Call · Stateful call and voice interaction flow.
Open UI/Features/VoiceCall/Views/VoiceCallView.swift
Shared UI
Reusable UI components and design system used across features.
Extension
Widget, shortcut, and live activity surfaces.
- Widgets · Widget, control, live activity, and app intent surfaces.
OpenUIWidgets/OpenUIWidgets.swift - App Intents · System integrations for shortcuts and quick actions.
Open UI/Core/Services/AppIntentsService.swift
Other components
- Open WebUI · Remote server providing chat, workspace, and admin APIs.
- Device Services · Core Data, CallKit, audio, speech, and secure storage on device.
Connections 32
- App Entry → App Router: starts · App launches into centralized navigation.
- App Router → Routes: uses · Router resolves navigation destinations.
- App Entry → Dependency DI: builds · Root composition creates shared dependencies.
- Dependency DI → API Client: provides · Services are wired around the API client.
- Dependency DI → Conversation Mgr: provides · Chat orchestration depends on conversation services.
- Dependency DI → Model Mgr: provides · Workspace flows use model management services.
- Dependency DI → Storage: provides · Local state and persistence are injected.
- Dependency DI → Server Config: provides · Active server/session state is shared.
- Dependency DI → Stream Store: provides · Live streaming buffers are shared.
- Auth → Keychain: stores token · Auth writes and reads secure credentials.
- Auth → Server Config: selects server · Onboarding and server switching update session config.
- Chat → Conversation Mgr: orchestrates · Chat UI delegates chat actions to the conversation layer.
- Chat → Stream Store: renders live · Streaming responses drive incremental rendering.
- Chat → Shared UI: uses · Chat screens are assembled from shared components.
- Chat → Model Mgr: picks model · Composer and selectors manage model choice.
- Chat → Open WebUI: calls · Messages and metadata flow to the server.
- Admin → Open WebUI: administers · Server settings and analytics are remote-backed.
- Workspace → Open WebUI: edits · Workspace assets are created and updated on the server.
- Settings → Storage: persists prefs · Client settings are stored locally.
- Notes → Storage: loads notes · Notes use local persistence and app state.
- Voice Call → Speech Stack: uses · Voice calling relies on ASR/TTS and audio services.
- Voice Call → Device Services: integrates · Calls and media interact with system capabilities.
- Shared UI → Theme: styled by · Reusable components consume shared visual tokens.
- Widgets → App Intents: exposes · System surfaces provide shortcuts and intents.
- Widgets → Open WebUI: syncs · Extension actions reflect server-backed app data.
- API Client → Network Manager: uses · API requests are built on the transport layer.
- API Client → SSE Stream: streams · Real-time chat output is consumed as SSE.
- API Client → Socket IO: fallbacks to · Socket interactions support server features beyond SSE.
- API Client → Keychain: reads token · Requests are authenticated with stored credentials.
- API Client → Open WebUI: talks to · Primary backend boundary.
- Storage → Device Services: backed by · Persistence relies on local iOS storage services.
- Speech Stack → Device Services: uses · Speech and media features rely on platform services.