Messages internals
The crate layout behind Messages, the protocol adapter interface, native bridge hosts and how to add a protocol.
Messages separates protocol-neutral messaging state from the code that talks to each service. This page describes that split for contributors. For using the app, see Messages.
Crates
| Crate or module | Owns |
|---|---|
crates/messages-core | protocol-neutral identities, capabilities, timelines, drafts and durable outbox state transitions |
crates/messages-protocols | the adapter registry, bounded HTTP transport, protocol translations and the local bridge contract |
crates/messages-bridge | local native protocol hosts for WhatsApp and Matrix |
crates/messages-media | device enumeration and capture helpers |
crates/messages-test-server | account-free wire fixtures and integration tests |
src/app | application state, event routing and asynchronous effects |
src/view | navigation, conversation surfaces and settings |
src/persistence | versioned state snapshots with atomic replacement |
src/platform | system keyring access and supervision of managed helpers |
Adapters
Every service is an implementation of the Adapter trait in messages-protocols. Its operations cover syncing, history and paged history, attachments, sending, message actions, starting conversations and threads, login state and authentication, call control, and capabilities.
| Service | Transport |
|---|---|
| Signal | signal-cli JSON-RPC over HTTP, with a resumable server-sent event stream |
| Matrix | client-server API v3 over REST, or a native encrypted SDK host |
| a native host built on whatsapp-rust, behind the local bridge API |
To add a protocol, implement Adapter and register its descriptor and factory in the registry.
Capabilities and identity
- Capabilities are evaluated per account and per room, and checked again at dispatch time, so the UI never offers an action a room cannot perform.
- Every room ID is namespaced by its account, so two accounts of the same service never share rooms.
- Optimistic messages keep a stable transaction ID across retries and server echoes, so a message is never duplicated when the server confirms it.
- Message updates (edits, deletions, reactions) are stored with replay protection, so an old event cannot undo an edit or resurrect a deleted message.
Native bridge hosts
Services whose cryptographic sessions must stay inside an official SDK run as separate local hosts from crates/messages-bridge. Each host serves a versioned local JSON API protected by a token, and keeps its session state in a private directory. The hosts are built as separate binaries, one feature per service:
cargo build --locked --manifest-path crates/messages-bridge/Cargo.toml --target-dir target \
--features whatsapp --bin messages-whatsapp -j 1The same applies to matrix (messages-matrix). Build both helpers into the same target directory as the main app. Signal uses a pinned, checksum-verified signal-cli, installed with ./tools/install-signal-cli.sh.
In managed mode, Messages starts and stops these helpers itself and restores their sessions. Packaged installations can point Messages at the helpers with MESSAGES_HELPER_DIR and at signal-cli with SIGNAL_CLI_PATH. Each managed account has a private session directory under the app's state location; helper access tokens are loaded by the app and never written into the conversation snapshot.
Testing the adapters
messages-test-server serves account-free fixtures for the supported protocol adapters on a local port, so the adapters' real HTTP requests can be exercised without live accounts:
cargo run --locked -j1 -p messages-test-serverThe fixtures test request and response handling, not network cryptography. Live-provider interoperability has to be verified separately with real accounts.
Attachments
Visible and nearby transcript images load on demand in two workers and share a bounded decoded-image cache. Local copies made for Open are kept in a bounded cache. Saving a file always publishes a complete new file and never replaces an existing destination.