# ichigo3766/open-relay architecture

> Architecture diagram of the GitHub repository ichigo3766/open-relay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ichigo3766/open-relay
- Repository: https://github.com/ichigo3766/open-relay

## Overview

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: [`Open UI/Core/Services/DependencyContainer.swift`](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/DependencyContainer.swift) (Dependency DI), [`Open UI/Core/Networking/APIClient.swift`](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/APIClient.swift) (API Client), [`Open UI/Features/Chat/Views/MainChatView.swift`](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Chat/Views/MainChatView.swift) (Chat), [`Open UI/Core/Services/StorageManager.swift`](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/StorageManager.swift) (Storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Shell"]
  node_app_entry["App Entry<br/>swiftui app<br/>[Open_UIApp.swift]"]
  node_app_router["App Router<br/>navigation<br/>[AppRouter.swift]"]
  node_route["Routes<br/>nav model<br/>[Route.swift]"]
end

subgraph group_core["Core Platform"]
  node_dep_container{{"Dependency DI<br/>composition root"}}
  node_api_client["API Client<br/>server api<br/>[APIClient.swift]"]
  node_network_mgr["Network Manager<br/>transport"]
  node_sse_stream["SSE Stream<br/>streaming<br/>[SSEStream.swift]"]
  node_socket_io["Socket IO<br/>realtime"]
  node_keychain[("Keychain<br/>auth storage")]
  node_storage[("Storage<br/>local persistence")]
  node_server_store[("Server Config<br/>session store")]
  node_stream_store["Stream Store<br/>ui state"]
  node_conv_mgr["Conversation Mgr<br/>chat service"]
  node_model_mgr["Model Mgr<br/>workspace service<br/>[ModelManager.swift]"]
  node_speech_stack["Speech Stack<br/>audio service"]
end

subgraph group_features["Feature Surfaces"]
  node_chat_feature["Chat<br/>feature<br/>[MainChatView.swift]"]
  node_auth_feature["Auth<br/>feature<br/>[LoginView.swift]"]
  node_admin_feature["Admin<br/>feature"]
  node_workspace_feature["Workspace<br/>feature"]
  node_settings_feature["Settings<br/>feature<br/>[SettingsView.swift]"]
  node_notes_feature["Notes<br/>feature"]
  node_voice_feature["Voice Call<br/>feature"]
end

subgraph group_shared["Shared UI"]
  node_shared_ui["Shared UI<br/>design system"]
  node_theme["Theme<br/>styling system"]
end

subgraph group_ext["Extension"]
  node_widgets_ext["Widgets<br/>extension"]
  node_app_intents["App Intents<br/>integration"]
end

node_openwebui[("Open WebUI<br/>external server")]
node_device_services[("Device Services<br/>ios system")]

node_app_entry -->|"starts"| node_app_router
node_app_router -->|"uses"| node_route
node_app_entry -->|"builds"| node_dep_container
node_dep_container -->|"provides"| node_api_client
node_dep_container -->|"provides"| node_conv_mgr
node_dep_container -->|"provides"| node_model_mgr
node_dep_container -->|"provides"| node_storage
node_dep_container -->|"provides"| node_server_store
node_dep_container -->|"provides"| node_stream_store
node_auth_feature -->|"stores token"| node_keychain
node_auth_feature -->|"selects server"| node_server_store
node_chat_feature -->|"orchestrates"| node_conv_mgr
node_chat_feature -->|"renders live"| node_stream_store
node_chat_feature -->|"uses"| node_shared_ui
node_chat_feature -->|"picks model"| node_model_mgr
node_chat_feature -->|"calls"| node_openwebui
node_admin_feature -->|"administers"| node_openwebui
node_workspace_feature -->|"edits"| node_openwebui
node_settings_feature -->|"persists prefs"| node_storage
node_notes_feature -->|"loads notes"| node_storage
node_voice_feature -->|"uses"| node_speech_stack
node_voice_feature -->|"integrates"| node_device_services
node_shared_ui -->|"styled by"| node_theme
node_widgets_ext -->|"exposes"| node_app_intents
node_widgets_ext -->|"syncs"| node_openwebui
node_api_client -->|"uses"| node_network_mgr
node_api_client -->|"streams"| node_sse_stream
node_api_client -->|"fallbacks to"| node_socket_io
node_api_client -->|"reads token"| node_keychain
node_api_client -->|"talks to"| node_openwebui
node_storage -->|"backed by"| node_device_services
node_speech_stack -->|"uses"| node_device_services

click node_app_entry "https://github.com/ichigo3766/open-relay/blob/main/Open UI/App/Open_UIApp.swift"
click node_app_router "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Navigation/AppRouter.swift"
click node_route "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Navigation/Route.swift"
click node_dep_container "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/DependencyContainer.swift"
click node_api_client "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Networking/APIClient.swift"
click node_network_mgr "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Networking/NetworkManager.swift"
click node_sse_stream "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Networking/SSEStream.swift"
click node_socket_io "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Networking/SocketIOService.swift"
click node_keychain "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Networking/KeychainService.swift"
click node_storage "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/StorageManager.swift"
click node_server_store "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/ServerConfigStore.swift"
click node_stream_store "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/StreamingContentStore.swift"
click node_conv_mgr "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/ConversationManager.swift"
click node_model_mgr "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/ModelManager.swift"
click node_speech_stack "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/SpeechRecognitionService.swift"
click node_chat_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Chat/Views/MainChatView.swift"
click node_auth_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Auth/Views/LoginView.swift"
click node_admin_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Admin/Views/AdminAnalyticsView.swift"
click node_workspace_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Workspace/Views/WorkspaceView.swift"
click node_settings_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Settings/Views/SettingsView.swift"
click node_notes_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/Notes/Views/NotesListView.swift"
click node_voice_feature "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Features/VoiceCall/Views/VoiceCallView.swift"
click node_shared_ui "https://github.com/ichigo3766/open-relay/tree/main/Open UI/Shared/Components"
click node_theme "https://github.com/ichigo3766/open-relay/tree/main/Open UI/Shared/Theme"
click node_widgets_ext "https://github.com/ichigo3766/open-relay/blob/main/OpenUIWidgets/OpenUIWidgets.swift"
click node_app_intents "https://github.com/ichigo3766/open-relay/blob/main/Open UI/Core/Services/AppIntentsService.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_entry,node_app_router,node_route toneBlue
class node_dep_container,node_api_client,node_network_mgr,node_sse_stream,node_socket_io,node_keychain,node_storage,node_server_store,node_stream_store,node_conv_mgr,node_model_mgr,node_speech_stack toneAmber
class node_chat_feature,node_auth_feature,node_admin_feature,node_workspace_feature,node_settings_feature,node_notes_feature,node_voice_feature toneMint
class node_shared_ui,node_theme toneRose
class node_widgets_ext,node_app_intents toneIndigo
class node_openwebui,node_device_services toneNeutral
```

## Components

### App Shell

Launch, routing, and navigation for the iOS client.

- [App Entry](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/App/Open_UIApp.swift): swiftui app · Main iOS app lifecycle and root composition. · `Open UI/App/Open_UIApp.swift`
- [App Router](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Navigation/AppRouter.swift): navigation · Central route and navigation orchestration. · `Open UI/Navigation/AppRouter.swift`
- [Routes](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Navigation/Route.swift): nav model · Navigation destinations and path definitions. · `Open UI/Navigation/Route.swift`

### Core Platform

Domain models, networking, state, and cross-cutting services.

- [Dependency DI](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/DependencyContainer.swift): composition root · Wires view models to services and shared state. · `Open UI/Core/Services/DependencyContainer.swift`
- [API Client](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/APIClient.swift): server api · Primary Open WebUI API access layer. · `Open UI/Core/Networking/APIClient.swift`
- [Network Manager](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/NetworkManager.swift): transport · Networking coordination and request plumbing. · `Open UI/Core/Networking/NetworkManager.swift`
- [SSE Stream](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/SSEStream.swift): streaming · Real-time assistant output via server-sent events. · `Open UI/Core/Networking/SSEStream.swift`
- [Socket IO](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/SocketIOService.swift): realtime · Socket-based server interactions where needed. · `Open UI/Core/Networking/SocketIOService.swift`
- [Keychain](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Networking/KeychainService.swift): auth storage · Secure token storage for server sessions. · `Open UI/Core/Networking/KeychainService.swift`
- [Storage](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/StorageManager.swift): local persistence · Local app state and persistence coordination. · `Open UI/Core/Services/StorageManager.swift`
- [Server Config](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/ServerConfigStore.swift): session store · Saved servers and active server configuration. · `Open UI/Core/Services/ServerConfigStore.swift`
- [Stream Store](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/StreamingContentStore.swift): ui state · Streaming content buffer for live rendering. · `Open UI/Core/Services/StreamingContentStore.swift`
- [Conversation Mgr](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/ConversationManager.swift): chat service · Conversation lifecycle and chat state operations. · `Open UI/Core/Services/ConversationManager.swift`
- [Model Mgr](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/ModelManager.swift): workspace service · Model selection and server-side model management. · `Open UI/Core/Services/ModelManager.swift`
- [Speech Stack](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/SpeechRecognitionService.swift): audio service · 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](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Chat/Views/MainChatView.swift): feature · Primary message composition, streaming, and conversation UI. · `Open UI/Features/Chat/Views/MainChatView.swift`
- [Auth](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Auth/Views/LoginView.swift): feature · Login, signup, SSO, proxy auth, and onboarding. · `Open UI/Features/Auth/Views/LoginView.swift`
- [Admin](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Admin/Views/AdminAnalyticsView.swift): feature · Server administration, analytics, integrations, and settings. · `Open UI/Features/Admin/Views/AdminAnalyticsView.swift`
- [Workspace](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Workspace/Views/WorkspaceView.swift): feature · Create and edit server-side assets like models, prompts, tools, and knowledge. · `Open UI/Features/Workspace/Views/WorkspaceView.swift`
- [Settings](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Settings/Views/SettingsView.swift): feature · Client preferences, privacy, appearance, and storage settings. · `Open UI/Features/Settings/Views/SettingsView.swift`
- [Notes](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/Notes/Views/NotesListView.swift): feature · Device-side notes browsing and editing. · `Open UI/Features/Notes/Views/NotesListView.swift`
- [Voice Call](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Features/VoiceCall/Views/VoiceCallView.swift): feature · Stateful call and voice interaction flow. · `Open UI/Features/VoiceCall/Views/VoiceCallView.swift`

### Shared UI

Reusable UI components and design system used across features.

- [Shared UI](https://github.com/ichigo3766/open-relay/tree/HEAD/Open%20UI/Shared/Components): design system · Reusable components for chat, rich content, and controls. · `Open UI/Shared/Components`
- [Theme](https://github.com/ichigo3766/open-relay/tree/HEAD/Open%20UI/Shared/Theme): styling system · Colors, typography, animation, and view styling tokens. · `Open UI/Shared/Theme`

### Extension

Widget, shortcut, and live activity surfaces.

- [Widgets](https://github.com/ichigo3766/open-relay/blob/main/OpenUIWidgets/OpenUIWidgets.swift): extension · Widget, control, live activity, and app intent surfaces. · `OpenUIWidgets/OpenUIWidgets.swift`
- [App Intents](https://github.com/ichigo3766/open-relay/blob/HEAD/Open%20UI/Core/Services/AppIntentsService.swift): integration · System integrations for shortcuts and quick actions. · `Open UI/Core/Services/AppIntentsService.swift`

### Other components

- **Open WebUI**: external server · Remote server providing chat, workspace, and admin APIs.
- **Device Services**: ios system · Core Data, CallKit, audio, speech, and secure storage on device.

## Connections

- 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.
