How getstream/stream-chat-swift works
Project Type and Purpose
• This is a multi-module iOS SDK repository for Stream Chat, providing:
• A low-level client (LLC) for pure networking and local state (Sources/StreamChat).
• A UIKit UI SDK (Sources/StreamChatUI).
• Demo and example iOS apps (DemoApp, Examples, StreamChatSample, StreamChatUITestsApp).
• Integration scripts, CI/CD workflows, and tests.
High-Level Components
a. External Services
– Stream Chat REST API (HTTPS).
– Stream Chat WebSocket endpoint.
– CDN for attachments.
b. Core SDK Layers
1. APIClient
• HTTP client, WebSocket client, endpoints, encoders/decoders (Sources/StreamChat/APIClient & /WebSocketClient).
2. Controllers & State Layer
• ChatClient facade, Controllers (ChannelController, MessageController, etc.), Combine/SwiftUI bindings (Sources/StreamChat/Controllers & /StateLayer).
3. Repositories & Workers
• Data syncing, offline queue, background upload/download (Sources/StreamChat/Repositories & /Workers).
4. Database
• CoreData models, DTOs, DatabaseContainer, DataStore (Sources/StreamChat/Database).
5. Utilities
• Logging, pagination, markdown parsing, audio, image loading (Sources/StreamChat/Utils).
c. UI SDK (UIKit)
• Reusable chat UI components: channel list, message list, composer, attachments, reactions (Sources/StreamChatUI).
d. Demo & Examples
• DemoApp: an iOS application wiring ChatClient → Controllers → UI components.
• Examples: sample apps (MessengerClone, SlackClone, YouTubeClone, etc.).
Component Relationships and Data Flow
• ChatClient (configuration) → APIClient (HTTP/WS)
↳ WebSocket events → Event Middlewares → Controllers/StateLayer
↳ HTTP requests → Endpoint modules → Repositories → Database
• Controllers expose Combine publishers / SwiftUI bindings
↳ UI SDK components subscribe to controllers/state
• Workers pick up tasks (upload, sync) in the background and update Database/State
• DatabaseContainer persists local state; Controllers observe DB changes
• UI layer renders based on Controller outputs; user actions flow back to ChatClient
Architectural Patterns and Principles
• Layered architecture: Networking → Repository/Workers → Controllers/State → UI
• MVVM-ish or MVC: Controllers act as view-models for UI SDK
• Repository pattern: isolates data sources (network vs. cache)
• Observer pattern: DatabaseObserver for state updates
• Middleware pipeline: process WS events through EventMiddlewares
• Dependency injection via ChatClientConfig and factory methods