|
| 1 | +# Architecture |
| 2 | + |
| 3 | +The SDK is split into multiple layers: |
| 4 | + |
| 5 | +``` |
| 6 | + WASM (external crate matrix-rust-sdk-crypto-wasm) |
| 7 | + / |
| 8 | + / uniffi |
| 9 | + / / |
| 10 | + / bindings (matrix-sdk-ffi) |
| 11 | + crypto | |
| 12 | +bindings | |
| 13 | + | | |
| 14 | + | UI (matrix-sdk-ui) |
| 15 | + | \ |
| 16 | + | \ |
| 17 | + | main (matrix-sdk) |
| 18 | + | / / |
| 19 | +crypto / |
| 20 | + \ / |
| 21 | + store (matrix-sdk-base, + all the store impls) |
| 22 | + | |
| 23 | + common (matrix-sdk-common) |
| 24 | +``` |
| 25 | + |
| 26 | +Where the store implementations are `matrix-sdk-sqlite` and `matrix-sdk-indexeddb` as well as |
| 27 | +`MemoryStore` which is defined in `matrix-sdk-base`. |
| 28 | + |
| 29 | +## `crates/matrix-sdk` |
| 30 | + |
| 31 | +This is the main crate, and one that is expected to be used by most consumers. Notable data types |
| 32 | +include: |
| 33 | + |
| 34 | +- the `Client`, which can run room-independent requests: logging in/out, creating rooms, running |
| 35 | + sync, etc. |
| 36 | +- the `Room`, which represents a room and its state (notably via the observable `RoomInfo`), and |
| 37 | + allows running queries that are room-specific, notably sending events. |
| 38 | + |
| 39 | +## `crates/matrix-sdk-base` |
| 40 | + |
| 41 | +A *sans I/O* crate to represent the base data types persisted in the SDK. No network or storage I/O |
| 42 | +happens in this crate, although it defines traits (`StateStore` and `EventCacheStore`) representing |
| 43 | +storage backends, as well as dummy in-memory implementations of these traits. |
| 44 | + |
| 45 | +## `crates/matrix-sdk-common` |
| 46 | + |
| 47 | +Common helpers used by most of the other crates; almost a leaf in the dependency tree of our own |
| 48 | +crates (the only crate it's using is test helpers). |
| 49 | + |
| 50 | +## `crates/matrix-sdk-crypto` |
| 51 | + |
| 52 | +A *sans I/O* implementation of a state machine that handles end-to-end encryption for Matrix |
| 53 | +clients. It defines a `CryptoStore` trait representing storage backends that will perform the |
| 54 | +actual storage I/O later, as well as a dummy in-memory implementation of this trait. |
| 55 | + |
| 56 | +## `crates/matrix-sdk-indexeddb` |
| 57 | + |
| 58 | +Implementations of `EventCacheStore`, `StateStore` and `CryptoStore` for a |
| 59 | +indexeddb backend (for use in Web browsers, via WebAssembly). |
| 60 | + |
| 61 | +## `crates/matrix-sdk-qrcode` |
| 62 | + |
| 63 | +Implementation of QR codes for interactive verifications, used in the crypto crate. |
| 64 | + |
| 65 | +## `crates/matrix-sdk-sqlite` |
| 66 | + |
| 67 | +Implementations of `EventCacheStore`, `StateStore` and `CryptoStore` for a |
| 68 | +SQLite backend. |
| 69 | + |
| 70 | +## `crates/matrix-sdk-store-encryption` |
| 71 | + |
| 72 | +Low-level primitives for encrypting/decrypting/hashing values. Store implementations that |
| 73 | +implement encryption at rest can use those primitives. |
| 74 | + |
| 75 | +## `crates/matrix-sdk-ui` |
| 76 | + |
| 77 | +Very high-level primitives implementing the best practices and cutting-edge Matrix tech: |
| 78 | + |
| 79 | +- `EncryptionService`: a specialized service running simplified sliding sync (MSC4186) for |
| 80 | + everything related to crypto and E2EE for the current `Client`. |
| 81 | +- `RoomListService`: a specialized service running simplified sliding sync (MSC4186) for |
| 82 | + retrieving the list of current rooms, and exposing its entries. |
| 83 | +- `SyncService`: a wrapper for the two previous services, coordinating their running and shutting |
| 84 | + down. |
| 85 | +- `Timeline`: a high-level view for a `Room`'s timeline of events, grouping related events |
| 86 | + (aggregations) into single timeline items. |
| 87 | + |
| 88 | +## `bindings/matrix-sdk-crypto-ffi/` |
| 89 | + |
| 90 | +FFI bindings for the crypto crate, used in a Web browser context via WebAssembly. These use |
| 91 | +`wasm-bindgen` to generate the bindings. These bindings are used in Element Web and the legacy |
| 92 | +Element apps, as of 2024-11-07. |
| 93 | + |
| 94 | +## `bindings/matrix-sdk-ffi/` |
| 95 | + |
| 96 | +FFI bindings for important concepts in `matrix-sdk-ui` and `matrix-sdk`, generated with |
| 97 | +[UniFFI](https://github.com/mozilla/uniffi-rs) and to be used from other languages like |
| 98 | +Swift/Go/Kotlin. These bindings are used in the ElementX apps, as of 2024-11-07. |
| 99 | + |
| 100 | +## `bindings/matrix-sdk-ffi-macros/` |
| 101 | + |
| 102 | +Macros used in `bindings/matrix-sdk-ffi`. |
| 103 | + |
| 104 | +## `testing/matrix-sdk-test/` |
| 105 | + |
| 106 | +Common test helpers, used by all the other crates. |
| 107 | + |
| 108 | +## `testing/matrix-sdk-test-macros/` |
| 109 | + |
| 110 | +Implementation of the `#[async_test]` test macro. |
| 111 | + |
| 112 | +## `testing/matrix-sdk-integration-testing/` |
| 113 | + |
| 114 | +Fully-fledged integration tests that require spawning a Synapse instance to run. A docker-compose |
| 115 | +setup is provided to ease running the tests, and it is compatible for running with Podman too. |
| 116 | + |
| 117 | +# Inspiration |
| 118 | + |
| 119 | +This document has been inspired by the reading of this [blog post](https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html). |
0 commit comments