Architecture Deep Dive

Understanding the MVVM Architecture and Component Interactions

Explore the sophisticated architecture that powers OpenAssistant, built with SwiftUI following modern iOS development patterns and best practices.

MVVM Architecture Pattern

The Model-View-ViewModel pattern provides clear separation of concerns, making the app maintainable, testable, and scalable.

MVVM Data Flow

Model (Data)
↔️
ViewModel (Logic)
↔️
View (UI)

Model: Assistant, Message, Thread, VectorStore structs

ViewModel: Business logic, API calls, state management

View: SwiftUI views, user interface, user interactions

Core Modules Breakdown

🌐

APIService Layer

Handles all OpenAI API interactions

The API service layer handles all external communication with the OpenAI API, built with a base service class and specialized extensions for different endpoints.

Key Responsibilities:

  • HTTP request/response handling
  • Authentication and API key management
  • Error handling and retry logic
  • Request serialization and response deserialization
OpenAIService.swift
OpenAIService-Assistant.swift
OpenAIService-Threads.swift
OpenAIService-Vector.swift
OpenAIInitializer.swift
OpenAIServiceError.swift
Utils.swift
CommonMethods.swift
🏗️

Base ViewModels

Foundation classes for all ViewModels

Base classes provide common functionality and establish patterns that all ViewModels follow, ensuring consistency across the application.

Key Features:

  • Shared OpenAI service access
  • Common error handling patterns
  • API key validation
  • Loading state management
BaseViewModel.swift
BaseAssistantViewModel.swift
CommonMethods.swift
🤖

Comprehensive Assistant Management

Complete assistant lifecycle management

Handles creation, configuration, updating, and deletion of OpenAI Assistants with support for advanced features like tool configuration and vector store association.

Capabilities:

  • Assistant CRUD operations
  • Model selection (GPT-4o, GPT-4.1, O-series)
  • Tool configuration (Code Interpreter, File Search)
  • Vector store association
  • Parameter tuning (temperature, top P, reasoning effort)
AssistantManagerView.swift
AssistantManagerViewModel.swift
AssistantDetailView.swift
AssistantDetailViewModel.swift
AssistantPickerView.swift
AssistantPickerViewModel.swift
💬

Chat Functionality

Interactive conversation interface

Delivers a complete chat experience with message history, thread management, and real-time assistant interactions.

Features:

  • Real-time messaging with OpenAI threads
  • Message history persistence
  • Markdown rendering for assistant responses
  • Thread lifecycle management
  • Run status monitoring and polling
ChatView.swift
ChatViewModel.swift
ChatContentView.swift
MessageListView.swift
InputView.swift
MessageStore.swift
MessageView.swift
ChatHistoryView.swift
🗂️

Vector Store & File Management

Knowledge base and file handling

Manages vector stores for knowledge retrieval and handles file uploads with configurable chunking strategies for optimal performance.

Capabilities:

  • Vector store CRUD operations
  • File upload and management
  • Configurable chunking (size and overlap)
  • Multiple file format support (PDF, TXT, DOCX)
  • File metadata and status tracking
VectorStoreListView.swift
VectorStoreDetailView.swift
VectorStoreManagerViewModel.swift
VectorStoreManagementView.swift

Application Data Flow

Initialization Flow

OpenAssistantApp
ContentView
MainTabView
Environment Objects
AssistantManagerVM
VectorStoreManagerVM
MessageStore

API Communication Flow

User Action
View
ViewModel
OpenAIService
OpenAI API
Response Processing
UI Update

Dependency Hierarchy

App Layer
OpenAssistantApp.swift
ContentView.swift
MainTabView.swift
Feature Views
AssistantManagerView
ChatView
VectorStoreListView
SettingsView
ViewModels
AssistantManagerViewModel
ChatViewModel
VectorStoreManagerViewModel
ContentViewModel
Base Classes
BaseViewModel
BaseAssistantViewModel
Services
OpenAIService
OpenAIInitializer
MessageStore
Data Models
Assistant
Message
Thread
VectorStore
File