How monal-im/monal works
1. Product shape and deployment targets
- Monal is a cross-platform XMPP client with multiple app variants: stable, beta, alpha, plus a Quicksy flavor and a macOS/iOS share-sheet extension.
- The main app target is an Apple-platform GUI application built in Xcode, with shared source across iOS and macOS and separate entitlements/plists for each variant.
2. Top-level application boundary
- The runtime boundary is the app process itself, centered around MonalAppDelegate, main.m, and the Xcode workspace/project.
- The app is stateful and long-lived: it maintains XMPP connectivity, local persistence, notifications, background processing, and chat/contact UI across app launches.
3. XMPP networking and protocol core
- The protocol layer lives in MLXMPPConnection, MLStream, MLXMPPManager, MLXMPPServer, XMPPStanza, XMPPMessage, XMPPPresence, and XMPPIQ.
- This layer is responsible for connecting to XMPP servers, sending/receiving stanzas, tracking account/session state, and routing incoming protocol events into higher-level processors.
4. Message, presence, and IQ processing pipeline
- Incoming protocol traffic is separated into specialized processors such as MLMessageProcessor, MLPresenceProcessor, MLIQProcessor, MLMucProcessor, and MLPubSubProcessor.
- This suggests a clear event pipeline: network stream → stanza parsing → type-specific processor → database/state updates → UI/notification updates.
5. Local persistence and account/chat state
- The persistence boundary is handled by DataLayer, MLSQLite, and migration helpers in DataLayerMigrations.
- The app stores chats, contacts, messages, file-transfer state, OMEMO keys, and related account metadata locally; MLSignalStore and OmemoState indicate encrypted key/state storage for end-to-end encryption.
6. Chat and contact user experience
- UI is built from a mix of Objective-C, Swift, SwiftUI, and XIB/storyboard components under Monal/Classes.
- Major surfaces include chat views (ChatView, chatViewController, MLChatCell variants), contact views (ContactsView, ContactDetails, ContactPicker), account management (AccountListController, MLAccountPickerViewController), settings, search, and onboarding/login flows.
7. Rich messaging and media handling
- The app has dedicated subsystems for attachments and rich content: file transfer classes, image manager, media gallery/viewer, link cells, map cells, reactions, and emoji/HTML parsing.
- Media and content rendering is split across UI cells and helpers, with conversion/parsing support for encrypted payloads, HTML/XHTML-like formatting, and previews.
8. Calls and real-time media
- Voice/video calling is represented by MLCall, MLVoIPProcessor, and WebRTCClient, with platform-specific call UI.
- This is a separate real-time subsystem from text chat: it likely consumes XMPP signaling and maps it into WebRTC/media call state, while UI and sounds provide the user-facing layer.
9. Encryption and identity/security
- Security-related code includes OMEMO, AES-GCM, SCRAM authentication, password migration, encrypted payload helpers, and identity/account verification utilities.
- The app also contains QR-code login/scanning and OMEMO QR views, showing that secure key exchange and account onboarding are first-class features.
10. Notifications and background delivery
- Push/notification handling is split between the main app and a dedicated NotificationService extension.
- The service extension likely processes incoming APNs payloads and enriches/sanitizes notifications before display, while MLNotificationManager and MLNotificationQueue bridge app state to local notification presentation.
11. Extension and secondary app surfaces
- The shareSheet-iOS target and its controller classes provide a separate entry point for sharing content into Monal.
- There are also platform/variant-specific resources and entitlements for Quicksy and alpha/beta releases, indicating the same core codebase is packaged into multiple distributable products.
12. Rust-based parsing and bridging layer
- The rust/ workspace provides parser and utility crates for XML, HTML, SDP/Jingle, panic handling, and a Rust-to-Swift bridge.
- This is an explicit language boundary: performance- or correctness-sensitive parsing/translation logic is offloaded to Rust, then exposed back to the Swift/ObjC app through the bridge layer.
13. Auxiliary tooling and operational support
- UDPLogServer is a separate Python service for receiving logs, and the scripts/ directory contains build, versioning, localization, export, and release automation.
- These tools are part of the release/ops boundary rather than runtime app logic, but they matter for understanding how builds, translations, and diagnostics are produced and distributed.
14. CI/CD and release channels
- GitHub Actions workflows drive build, test, semver/title checks, translation updates, dependency updates, and release publishing for stable/beta/alpha tracks.
- The repository is organized around App Store/TestFlight/homebrew distribution and translation management via Weblate, so the architecture includes a strong delivery pipeline in addition to the client runtime itself.
Main entry points: DataLayer.m Data layer · XMPPStanza.m Stanza model · MonalAppDelegate.m App delegate · MLMessageProcessor.m Message proc
Components 27
App runtime
Primary Apple app targets and shared client process.
- App delegate · Main process lifecycle and app-wide coordination.
Monal/Classes/MonalAppDelegate.m - Main entry · Process bootstrap for the main app.
Monal/main.m
Protocol core
XMPP connection, stanza model, and event processors.
- XMPP manager · Coordinates accounts, connections, and protocol routing.
Monal/Classes/MLXMPPManager.m - XMPP connection · Maintains transport/session state to XMPP servers.
Monal/Classes/MLXMPPConnection.m - XML stream · Low-level stream handling and stanza ingress/egress.
Monal/Classes/MLStream.m - Stanza model · Core stanza/message/presence/IQ data structures.
Monal/Classes/XMPPStanza.m - Message proc · Handles chat messages and message-specific events.
Monal/Classes/MLMessageProcessor.m - Presence proc · Handles presence, availability, and roster activity.
Monal/Classes/MLPresenceProcessor.m - IQ proc · Handles request/response IQ traffic.
Monal/Classes/MLIQProcessor.m - Group services · Manages MUC and pubsub related protocol flows.
Monal/Classes/MLMucProcessor.m
State & security
Local persistence, identity, encryption, and notifications.
- Data layer · App database access and stored chat/account state.
Monal/Classes/DataLayer.m - SQLite store · SQLite wrapper used by the client state layer.
Monal/Classes/MLSQLite.m - Migrations · Database migration and upgrade helpers.
Monal/Classes/DataLayerMigrations.m - Signal store · Encrypted key/state storage for OMEMO and related secrets.
Monal/Classes/MLSignalStore.m - OMEMO state · Tracks end-to-end encryption keys and session state.
Monal/Classes/OmemoState.m - Notifications · App-side notification scheduling and delivery coordination.
Monal/Classes/MLNotificationManager.m
User experience
Chat, contacts, accounts, onboarding, and media surfaces.
- Chat UI · Chat views, cells, input, and conversation rendering.
Monal/Classes/chatViewController.m - Contacts & accounts · Contacts, account selection, and account management screens.
Monal/Classes/ContactsView.swift - Setup & settings · Settings, onboarding, password changes, and login flows.
Monal/Classes/WelcomeLogIn.swift - Media & calls · Attachments, gallery, WebRTC calls, reactions, and rich content.
Monal/Classes/WebRTCClient.swift
Extensions
Secondary app entry points and services.
- Share sheet · iOS share extension entry point and selection UI.
Monal/shareSheet-iOS/ShareViewController.m - Push service · Notification service extension for APNs enrichment and filtering.
Monal/NotificationService/NotificationService.m
Rust workspace
Parsing and bridge crates used from the Apple codebase.
- Rust bridge · Swift-facing bridge into Rust parsing and support code.
rust/monal-rust-swift-bridge/src/lib.rs - Rust parsers · XML, HTML, and SDP/Jingle parsing crates.
rust/monal-xml-parser/src/lib.rs
Build & release
Automation, release channels, and operational tooling.
- CI & release · Build, test, signing, publishing, and translation workflows.
.github/workflows/stable.build-push.yml - Scripts · Build, versioning, localization, and release helper scripts.
scripts/build.sh - UDP log server · Standalone Python log receiver used for diagnostics.
UDPLogServer/server.py
Connections 29
- Main entry → App delegate: launches · Process entry hands control to the application delegate.
- App delegate → XMPP manager: coordinates · App lifecycle drives account and connection management.
- App delegate → Notifications: owns · Global app flow feeds notification presentation.
- XMPP manager → XMPP connection: opens · Manager creates and supervises network sessions.
- XMPP connection → XML stream: streams · Transport feeds raw XML stream parsing.
- XML stream → Stanza model: parses · Stream events become stanza objects.
- Stanza model → Message proc: routes to · Message stanzas are handled by the message processor.
- Stanza model → Presence proc: routes to · Presence stanzas are handled by the presence processor.
- Stanza model → IQ proc: routes to · IQ stanzas are handled by the IQ processor.
- Stanza model → Group services: routes to · Group and pubsub traffic goes to specialized processors.
- Message proc → Data layer: updates · Message processing persists chat and message state.
- Presence proc → Data layer: updates · Presence handling updates roster and account state.
- IQ proc → Data layer: updates · IQ responses update local protocol state.
- Group services → Data layer: updates · Group service events persist into the database.
- Data layer → SQLite store: stores in · Primary persistence is backed by SQLite.
- Data layer → Migrations: migrates · Schema changes are applied through migration helpers.
- Data layer → Signal store: secures · Sensitive account and key material is stored separately.
- Signal store → OMEMO state: maintains · OMEMO state uses secure key storage.
- Message proc → Chat UI: feeds · Incoming and outgoing chat events update the conversation UI.
- Presence proc → Contacts & accounts: feeds · Roster and availability changes update contacts and accounts.
- Notifications → Push service: extends · App-side notifications are complemented by the service extension.
- Chat UI → Media & calls: uses · Conversation UI integrates attachments, rich media, and calls.
- Contacts & accounts → Setup & settings: navigates to · Account and contact management connects to setup and settings.
- Chat UI → Rust bridge: parses via · Rich text and parsing features use the Rust bridge.
- Media & calls → Rust bridge: signals via · Real-time media logic crosses into Rust-backed helpers where needed.
- Rust bridge → Rust parsers: calls · The bridge exposes parser and utility crates to the app.
- CI & release → Scripts: drives · Automation invokes build and release scripts.
- CI & release → Push service: packages · Workflows build the main app and extensions.
- Scripts → UDP log server: supports · Operational tooling includes log collection and diagnostics.