# monal-im/monal architecture

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

- Interactive diagram: https://gitdiagram.com/monal-im/monal
- Repository: https://github.com/monal-im/monal

## Overview

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: [`Monal/Classes/DataLayer.m`](https://github.com/monal-im/monal/blob/develop/Monal/Classes/DataLayer.m) (Data layer), [`Monal/Classes/XMPPStanza.m`](https://github.com/monal-im/monal/blob/develop/Monal/Classes/XMPPStanza.m) (Stanza model), [`Monal/Classes/MonalAppDelegate.m`](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MonalAppDelegate.m) (App delegate), [`Monal/Classes/MLMessageProcessor.m`](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLMessageProcessor.m) (Message proc)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["App runtime"]
  node_app_delegate["App delegate<br/>app runtime<br/>[MonalAppDelegate.m]"]
  node_main_entry(("Main entry<br/>app runtime<br/>[main.m]"))
end

subgraph group_grp_proto["Protocol core"]
  node_xmpp_manager["XMPP manager<br/>protocol orchestrator<br/>[MLXMPPManager.m]"]
  node_xmpp_connection["XMPP connection<br/>network session<br/>[MLXMPPConnection.m]"]
  node_xmpp_stream["XML stream<br/>stream parser<br/>[MLStream.m]"]
  node_stanza_model["Stanza model<br/>xmpp model<br/>[XMPPStanza.m]"]
  node_message_proc["Message proc<br/>protocol processor"]
  node_presence_proc["Presence proc<br/>protocol processor"]
  node_iq_proc["IQ proc<br/>protocol processor<br/>[MLIQProcessor.m]"]
  node_muc_pubsub_proc["Group services<br/>protocol processor<br/>[MLMucProcessor.m]"]
end

subgraph group_grp_state["State & security"]
  node_data_layer[("Data layer<br/>persistence layer<br/>[DataLayer.m]")]
  node_sqlite_store[("SQLite store<br/>storage backend<br/>[MLSQLite.m]")]
  node_migrations["Migrations<br/>schema evolution"]
  node_signal_store[("Signal store<br/>secure storage<br/>[MLSignalStore.m]")]
  node_omemo_state["OMEMO state<br/>encryption state<br/>[OmemoState.m]"]
  node_notification_mgr["Notifications<br/>notification bridge"]
end

subgraph group_grp_ui["User experience"]
  node_chat_ui["Chat UI<br/>conversation surfaces"]
  node_contacts_accounts["Contacts & accounts<br/>navigation surfaces<br/>[ContactsView.swift]"]
  node_settings_onboarding["Setup & settings<br/>configuration UI<br/>[WelcomeLogIn.swift]"]
  node_media_calls["Media & calls<br/>rich media<br/>[WebRTCClient.swift]"]
end

subgraph group_grp_ext["Extensions"]
  node_share_sheet["Share sheet<br/>extension"]
  node_notification_service["Push service<br/>extension service"]
end

subgraph group_grp_rust["Rust workspace"]
  node_rust_bridge["Rust bridge<br/>ffi bridge<br/>[lib.rs]"]
  node_rust_parsers["Rust parsers<br/>parser workspace<br/>[lib.rs]"]
end

subgraph group_grp_ops["Build & release"]
  node_ci_release["CI & release<br/>automation"]
  node_scripts_tools["Scripts<br/>release tooling<br/>[build.sh]"]
  node_udp_log_server["UDP log server<br/>ops tool<br/>[server.py]"]
end

node_main_entry -->|"launches"| node_app_delegate
node_app_delegate -->|"coordinates"| node_xmpp_manager
node_app_delegate -->|"owns"| node_notification_mgr
node_xmpp_manager -->|"opens"| node_xmpp_connection
node_xmpp_connection -->|"streams"| node_xmpp_stream
node_xmpp_stream -->|"parses"| node_stanza_model
node_stanza_model -->|"routes to"| node_message_proc
node_stanza_model -->|"routes to"| node_presence_proc
node_stanza_model -->|"routes to"| node_iq_proc
node_stanza_model -->|"routes to"| node_muc_pubsub_proc
node_message_proc -->|"updates"| node_data_layer
node_presence_proc -->|"updates"| node_data_layer
node_iq_proc -->|"updates"| node_data_layer
node_muc_pubsub_proc -->|"updates"| node_data_layer
node_data_layer -->|"stores in"| node_sqlite_store
node_data_layer -->|"migrates"| node_migrations
node_data_layer -->|"secures"| node_signal_store
node_signal_store -->|"maintains"| node_omemo_state
node_message_proc -->|"feeds"| node_chat_ui
node_presence_proc -->|"feeds"| node_contacts_accounts
node_notification_mgr -->|"extends"| node_notification_service
node_chat_ui -->|"uses"| node_media_calls
node_contacts_accounts -->|"navigates to"| node_settings_onboarding
node_chat_ui -->|"parses via"| node_rust_bridge
node_media_calls -->|"signals via"| node_rust_bridge
node_rust_bridge -->|"calls"| node_rust_parsers
node_ci_release -->|"drives"| node_scripts_tools
node_ci_release -->|"packages"| node_notification_service
node_scripts_tools -->|"supports"| node_udp_log_server

click node_app_delegate "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MonalAppDelegate.m"
click node_main_entry "https://github.com/monal-im/monal/blob/develop/Monal/main.m"
click node_xmpp_manager "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLXMPPManager.m"
click node_xmpp_connection "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLXMPPConnection.m"
click node_xmpp_stream "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLStream.m"
click node_stanza_model "https://github.com/monal-im/monal/blob/develop/Monal/Classes/XMPPStanza.m"
click node_message_proc "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLMessageProcessor.m"
click node_presence_proc "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLPresenceProcessor.m"
click node_iq_proc "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLIQProcessor.m"
click node_muc_pubsub_proc "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLMucProcessor.m"
click node_data_layer "https://github.com/monal-im/monal/blob/develop/Monal/Classes/DataLayer.m"
click node_sqlite_store "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLSQLite.m"
click node_migrations "https://github.com/monal-im/monal/blob/develop/Monal/Classes/DataLayerMigrations.m"
click node_signal_store "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLSignalStore.m"
click node_omemo_state "https://github.com/monal-im/monal/blob/develop/Monal/Classes/OmemoState.m"
click node_notification_mgr "https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLNotificationManager.m"
click node_chat_ui "https://github.com/monal-im/monal/blob/develop/Monal/Classes/chatViewController.m"
click node_contacts_accounts "https://github.com/monal-im/monal/blob/develop/Monal/Classes/ContactsView.swift"
click node_settings_onboarding "https://github.com/monal-im/monal/blob/develop/Monal/Classes/WelcomeLogIn.swift"
click node_media_calls "https://github.com/monal-im/monal/blob/develop/Monal/Classes/WebRTCClient.swift"
click node_share_sheet "https://github.com/monal-im/monal/blob/develop/Monal/shareSheet-iOS/ShareViewController.m"
click node_notification_service "https://github.com/monal-im/monal/blob/develop/Monal/NotificationService/NotificationService.m"
click node_rust_bridge "https://github.com/monal-im/monal/blob/develop/rust/monal-rust-swift-bridge/src/lib.rs"
click node_rust_parsers "https://github.com/monal-im/monal/blob/develop/rust/monal-xml-parser/src/lib.rs"
click node_ci_release "https://github.com/monal-im/monal/blob/develop/.github/workflows/stable.build-push.yml"
click node_scripts_tools "https://github.com/monal-im/monal/blob/develop/scripts/build.sh"
click node_udp_log_server "https://github.com/monal-im/monal/blob/develop/UDPLogServer/server.py"

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_delegate,node_main_entry,node_ci_release,node_scripts_tools,node_udp_log_server toneBlue
class node_xmpp_manager,node_xmpp_connection,node_xmpp_stream,node_stanza_model,node_message_proc,node_presence_proc,node_iq_proc,node_muc_pubsub_proc toneAmber
class node_data_layer,node_sqlite_store,node_migrations,node_signal_store,node_omemo_state,node_notification_mgr toneMint
class node_chat_ui,node_contacts_accounts,node_settings_onboarding,node_media_calls toneRose
class node_share_sheet,node_notification_service toneIndigo
class node_rust_bridge,node_rust_parsers toneTeal
```

## Components

### App runtime

Primary Apple app targets and shared client process.

- [App delegate](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MonalAppDelegate.m): app runtime · Main process lifecycle and app-wide coordination. · `Monal/Classes/MonalAppDelegate.m`
- [Main entry](https://github.com/monal-im/monal/blob/develop/Monal/main.m): app runtime · Process bootstrap for the main app. · `Monal/main.m`

### Protocol core

XMPP connection, stanza model, and event processors.

- [XMPP manager](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLXMPPManager.m): protocol orchestrator · Coordinates accounts, connections, and protocol routing. · `Monal/Classes/MLXMPPManager.m`
- [XMPP connection](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLXMPPConnection.m): network session · Maintains transport/session state to XMPP servers. · `Monal/Classes/MLXMPPConnection.m`
- [XML stream](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLStream.m): stream parser · Low-level stream handling and stanza ingress/egress. · `Monal/Classes/MLStream.m`
- [Stanza model](https://github.com/monal-im/monal/blob/develop/Monal/Classes/XMPPStanza.m): xmpp model · Core stanza/message/presence/IQ data structures. · `Monal/Classes/XMPPStanza.m`
- [Message proc](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLMessageProcessor.m): protocol processor · Handles chat messages and message-specific events. · `Monal/Classes/MLMessageProcessor.m`
- [Presence proc](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLPresenceProcessor.m): protocol processor · Handles presence, availability, and roster activity. · `Monal/Classes/MLPresenceProcessor.m`
- [IQ proc](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLIQProcessor.m): protocol processor · Handles request/response IQ traffic. · `Monal/Classes/MLIQProcessor.m`
- [Group services](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLMucProcessor.m): protocol processor · Manages MUC and pubsub related protocol flows. · `Monal/Classes/MLMucProcessor.m`

### State & security

Local persistence, identity, encryption, and notifications.

- [Data layer](https://github.com/monal-im/monal/blob/develop/Monal/Classes/DataLayer.m): persistence layer · App database access and stored chat/account state. · `Monal/Classes/DataLayer.m`
- [SQLite store](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLSQLite.m): storage backend · SQLite wrapper used by the client state layer. · `Monal/Classes/MLSQLite.m`
- [Migrations](https://github.com/monal-im/monal/blob/develop/Monal/Classes/DataLayerMigrations.m): schema evolution · Database migration and upgrade helpers. · `Monal/Classes/DataLayerMigrations.m`
- [Signal store](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLSignalStore.m): secure storage · Encrypted key/state storage for OMEMO and related secrets. · `Monal/Classes/MLSignalStore.m`
- [OMEMO state](https://github.com/monal-im/monal/blob/develop/Monal/Classes/OmemoState.m): encryption state · Tracks end-to-end encryption keys and session state. · `Monal/Classes/OmemoState.m`
- [Notifications](https://github.com/monal-im/monal/blob/develop/Monal/Classes/MLNotificationManager.m): notification bridge · App-side notification scheduling and delivery coordination. · `Monal/Classes/MLNotificationManager.m`

### User experience

Chat, contacts, accounts, onboarding, and media surfaces.

- [Chat UI](https://github.com/monal-im/monal/blob/develop/Monal/Classes/chatViewController.m): conversation surfaces · Chat views, cells, input, and conversation rendering. · `Monal/Classes/chatViewController.m`
- [Contacts & accounts](https://github.com/monal-im/monal/blob/develop/Monal/Classes/ContactsView.swift): navigation surfaces · Contacts, account selection, and account management screens. · `Monal/Classes/ContactsView.swift`
- [Setup & settings](https://github.com/monal-im/monal/blob/develop/Monal/Classes/WelcomeLogIn.swift): configuration UI · Settings, onboarding, password changes, and login flows. · `Monal/Classes/WelcomeLogIn.swift`
- [Media & calls](https://github.com/monal-im/monal/blob/develop/Monal/Classes/WebRTCClient.swift): rich media · Attachments, gallery, WebRTC calls, reactions, and rich content. · `Monal/Classes/WebRTCClient.swift`

### Extensions

Secondary app entry points and services.

- [Share sheet](https://github.com/monal-im/monal/blob/develop/Monal/shareSheet-iOS/ShareViewController.m): extension · iOS share extension entry point and selection UI. · `Monal/shareSheet-iOS/ShareViewController.m`
- [Push service](https://github.com/monal-im/monal/blob/develop/Monal/NotificationService/NotificationService.m): extension 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](https://github.com/monal-im/monal/blob/develop/rust/monal-rust-swift-bridge/src/lib.rs): ffi bridge · Swift-facing bridge into Rust parsing and support code. · `rust/monal-rust-swift-bridge/src/lib.rs`
- [Rust parsers](https://github.com/monal-im/monal/blob/develop/rust/monal-xml-parser/src/lib.rs): parser workspace · XML, HTML, and SDP/Jingle parsing crates. · `rust/monal-xml-parser/src/lib.rs`

### Build & release

Automation, release channels, and operational tooling.

- [CI & release](https://github.com/monal-im/monal/blob/develop/.github/workflows/stable.build-push.yml): automation · Build, test, signing, publishing, and translation workflows. · `.github/workflows/stable.build-push.yml`
- [Scripts](https://github.com/monal-im/monal/blob/develop/scripts/build.sh): release tooling · Build, versioning, localization, and release helper scripts. · `scripts/build.sh`
- [UDP log server](https://github.com/monal-im/monal/blob/develop/UDPLogServer/server.py): ops tool · Standalone Python log receiver used for diagnostics. · `UDPLogServer/server.py`

## Connections

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