<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hapood wang</title>
    <description>The latest articles on DEV Community by hapood wang (@hapood_wang_e5dd77f0de7a8).</description>
    <link>https://dev.to/hapood_wang_e5dd77f0de7a8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1950020%2Fc47cef74-e8f3-4ff9-bbde-fa49ed4d0651.jpg</url>
      <title>DEV Community: hapood wang</title>
      <link>https://dev.to/hapood_wang_e5dd77f0de7a8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hapood_wang_e5dd77f0de7a8"/>
    <language>en</language>
    <item>
      <title>SOMS: Building Federated Chat for Self-Hosted Servers</title>
      <dc:creator>hapood wang</dc:creator>
      <pubDate>Thu, 12 Nov 2026 03:01:23 +0000</pubDate>
      <link>https://dev.to/hapood_wang_e5dd77f0de7a8/soms-an-open-source-federated-chat-platform-built-with-rust-nestjs-and-tauri-57i3</link>
      <guid>https://dev.to/hapood_wang_e5dd77f0de7a8/soms-an-open-source-federated-chat-platform-built-with-rust-nestjs-and-tauri-57i3</guid>
      <description>&lt;p&gt;&lt;strong&gt;SOMS (Simple Open Messaging Service)&lt;/strong&gt; is an MIT-licensed, self-hosted chat platform with cross-server messaging, group conversations, rich media, and one-to-one WebRTC audio/video calls. Its backend uses NestJS, Fastify, and PostgreSQL; native clients use Tauri and a shared Rust runtime.&lt;/p&gt;

&lt;p&gt;The design centers on a practical self-hosting problem: &lt;strong&gt;independent servers go offline&lt;/strong&gt;. A personal server might restart, lose connectivity, or move behind a different network address.&lt;/p&gt;

&lt;p&gt;How can peers catch up without making successful delivery of every notification a correctness requirement?&lt;/p&gt;

&lt;p&gt;SOMS addresses that with &lt;strong&gt;advisory notifications, pull-based synchronization, and durable deletion facts&lt;/strong&gt;. This article explains those choices, along with the PostgreSQL task system and native-client architecture.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Status:&lt;/strong&gt; SOMS &lt;code&gt;0.1.0-alpha.2&lt;/code&gt; and SOMFP &lt;code&gt;v1.0.0-draft.2&lt;/code&gt; are technical previews. Stable operation and upgrade compatibility are not guaranteed before beta. APIs, federation contracts, and storage formats may change incompatibly. Use isolated deployments with disposable data, not production or critical communications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Want to see the interface first? &lt;strong&gt;&lt;a href="https://hapood.github.io/simple-open-messaging-service/" rel="noopener noreferrer"&gt;Open the SOMS Playground&lt;/a&gt;&lt;/strong&gt;. It runs a simulation in browser memory without an account or backend. It is a UI demo, not a live federation or call-interoperability test.&lt;/p&gt;

&lt;h2&gt;
  
  
  What SOMS includes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Messaging:&lt;/strong&gt; direct and group conversations, rich text, replies, mentions, and link previews.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Media:&lt;/strong&gt; images, video, and voice messages, with SHA-256 verification for federated resource transfers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Federation:&lt;/strong&gt; authenticated server-to-server HTTP APIs, cursor-based catch-up, and separate deletion queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calls and realtime updates:&lt;/strong&gt; one-to-one WebRTC voice/video calling, cross-server signaling, and Server-Sent Events for client updates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Administration:&lt;/strong&gt; role-based access control, quotas, content reports, and moderation tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clients:&lt;/strong&gt; an Angular web/PWA interface and native clients using Tauri, Rust, and platform adapters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SOMS servers federate using &lt;strong&gt;SOMFP (Simple Open Messaging Federation Protocol)&lt;/strong&gt;, a separate protocol from Matrix and XMPP. It connects independently operated domains without a global coordinator or shared database. Individual resources still have defined authorities, such as the origin server of a group.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Push to notify, pull to synchronize
&lt;/h2&gt;

&lt;p&gt;A push-based system can be reliable, but it needs explicit rules for offline delivery, retry limits, and reconciliation. SOMFP instead keeps notification delivery out of the authoritative synchronization path.&lt;/p&gt;

&lt;p&gt;A signed &lt;code&gt;POST /somfp/v1/feed-heads&lt;/code&gt; tells a peer that newer feed bounds are available. The hint is advisory: receiving it does not mean the receiver has synchronized, and missing it must not lose the underlying state. Consumers need catch-up and reconciliation independently of hint delivery.&lt;/p&gt;

&lt;p&gt;SOMFP separates &lt;strong&gt;change discovery from content retrieval&lt;/strong&gt;, rather than putting every kind of change into one append-only event log:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;State Feed — &lt;code&gt;GET /somfp/v1/state-feed&lt;/code&gt;:&lt;/strong&gt; a per-peer, compacted feed of relationship facts and content-head projections. A thread content head advertises message and tombstone bounds, not the message bodies themselves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Message Query — &lt;code&gt;GET /somfp/v1/messages&lt;/code&gt;:&lt;/strong&gt; retrieves messages for a thread using message-sequence coordinates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tombstone Query — &lt;code&gt;GET /somfp/v1/message-tombstones&lt;/code&gt;:&lt;/strong&gt; retrieves deletion facts using an independent thread-local &lt;code&gt;deletionSeq&lt;/code&gt; cursor.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simplified exchange looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8g9dk7p46s4uxv3xfi3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8g9dk7p46s4uxv3xfi3p.png" alt="SOMFP synchronization: advisory hints followed by state, message, and deletion queries with independent cursors." width="800" height="1020"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hints announce changes. Pull queries retrieve authoritative state and content.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a conceptual flow, not a requirement to drain all messages before deletions. Each query has its own coordinates and authorization rules. Message sequences, deletion sequences, and State Feed IDs are not interchangeable, and monotonic does not mean contiguous.&lt;/p&gt;

&lt;p&gt;The benefit is &lt;strong&gt;recoverable progress&lt;/strong&gt;: a consumer can continue from persisted cursors rather than depend on replaying every wakeup notification. Recovery depends on durable storage, retained authoritative data, and valid authorization.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Deletions are durable facts
&lt;/h2&gt;

&lt;p&gt;Deleting only the publisher's message row would leave an offline replica without a reliable way to discover the deletion. SOMFP therefore exposes authoritative tombstones separately from messages.&lt;/p&gt;

&lt;p&gt;The protocol defines this structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;MessageTombstone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;deletionSeq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ThreadSequence&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ThreadAddress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;messageSeq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ThreadSequence&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'USER_RETRACTION'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'MODERATION_REMOVAL'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;deletedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;EpochMilliseconds&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;deletionSeq&lt;/code&gt; orders deletion facts. &lt;code&gt;messageSeq&lt;/code&gt; identifies the target in the publisher's message-coordinate space. Neither is a globally interchangeable message identifier. For example, a group origin republishes an accepted deletion using its own target-message coordinate rather than blindly forwarding the previous hop's sequence.&lt;/p&gt;

&lt;p&gt;Authoritative tombstones are retained permanently by the protocol. A conforming consumer authenticates the publisher, validates its authority over the target, and applies the deletion according to the synchronization rules. Local moderation of a replica does not automatically grant authority to delete that content on every server.&lt;/p&gt;

&lt;p&gt;Separate deletion cursors make offline catch-up explicit. They do &lt;strong&gt;not&lt;/strong&gt; imply that every deletion is delivered in a single total order with subsequent messages, nor can they force an uncooperative server to erase backups, exports, or independently retained copies.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Trust starts with HTTPS; continuity comes from pinned keys
&lt;/h2&gt;

&lt;p&gt;Public discovery metadata is served at &lt;strong&gt;&lt;code&gt;GET /somfp/discovery&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Initial peer trust comes from hostname-validated HTTPS. After recognition, a peer pins a root public key and authenticates requests using &lt;strong&gt;Ed25519 HTTP Message Signatures in the RFC 9421 wire format&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The key roles are distinct:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Root keys&lt;/strong&gt; anchor a peer's identity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signing-key certificates&lt;/strong&gt; authorize HTTP signing keys under a root.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP request signatures&lt;/strong&gt; bind the request method, path, query, authority, date, and content digest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A newly fetched discovery document does not silently replace a pinned root. Ordinary signing-key rotation remains under that root; root changes use the protocol's explicit recognition and rotation process, subject to local adoption policy.&lt;/p&gt;

&lt;p&gt;Ordinary JSON responses are protected by hostname-validated TLS, not by an independent signature on every returned event. Request authentication, response transport integrity, and resource-digest verification serve different purposes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security boundary:&lt;/strong&gt; these mechanisms authenticate federation traffic and protect it in transit. They are not end-to-end message encryption between chat participants.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. PostgreSQL instead of an external message broker
&lt;/h2&gt;

&lt;p&gt;The backend combines NestJS and Fastify with PostgreSQL and Drizzle. A Caddy edge can provide TLS termination, reverse proxying, and static assets. Direct backend HTTP/2 is available when backend TLS is configured; a TLS-terminating proxy can use HTTP/1.1 on the upstream connection.&lt;/p&gt;

&lt;p&gt;Background work uses a PostgreSQL-backed durable task system rather than requiring Redis or RabbitMQ:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Persistent task state:&lt;/strong&gt; queued work and execution progress live in the database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retry and recovery:&lt;/strong&gt; the dispatcher can revisit unfinished work after a process restart, subject to each task's retry and checkpoint semantics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain-owned behavior:&lt;/strong&gt; generic scheduling lives in &lt;code&gt;src/durable-task/&lt;/code&gt;; task handlers and business rules remain with their owning domains.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Database locking is part of that design. Non-key read-modify-write operations prefer &lt;code&gt;FOR NO KEY UPDATE&lt;/code&gt; to avoid unnecessary conflicts with foreign-key checks, alongside consistent lock ordering to manage contention.&lt;/p&gt;

&lt;p&gt;The trade-off is operational: fewer services simplify deployment, while task traffic and application traffic share PostgreSQL. Database health, workload, backups, and recovery remain central to running an instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Shared Rust policy, native platform capabilities
&lt;/h2&gt;

&lt;p&gt;The Angular interface runs in browser and native environments. &lt;strong&gt;Native clients share a Rust runtime; the browser uses its own runtime.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For native clients, Rust is the shared owner of business rules and cross-platform runtime orchestration. Platform adapters expose OS capabilities:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fogc3hmvhn3gt3hdqnhd9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fogc3hmvhn3gt3hdqnhd9.png" alt="Native Android and desktop adapters report facts to a shared Rust runtime and execute its commands. Browser and PWA run as a separate host." width="800" height="970"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Share native policy in Rust; keep OS capabilities in platform adapters.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The boundary is intentionally strict:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Adapters report facts.&lt;/strong&gt; Lifecycle changes, connectivity observations, notification interactions, and permission results become inputs to Rust.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rust owns decisions.&lt;/strong&gt; Connection policy, session/account generations, synchronization, and notification/call decisions belong in shared native code rather than parallel Kotlin and Rust state machines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adapters execute OS actions.&lt;/strong&gt; Notification rendering, secure-storage access, audio routing, and platform media APIs remain platform responsibilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async results are validated.&lt;/strong&gt; Cancellation and session-generation checks prevent stale work from publishing into a newer session.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The native architecture keeps blocking I/O and long-running work off the UI thread, while OS APIs that require the main thread run there. Native persistence includes local caches and platform-backed credential storage; protecting credentials is separate from encrypting message or media caches.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Try the interface or deploy a test instance
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;&lt;a href="https://hapood.github.io/simple-open-messaging-service/" rel="noopener noreferrer"&gt;SOMS Playground&lt;/a&gt;&lt;/strong&gt; demonstrates conversations, group interactions, and media/calling interfaces using an in-memory simulation. No backend setup is needed.&lt;/p&gt;

&lt;p&gt;For an isolated self-hosting trial, the &lt;strong&gt;&lt;a href="https://hapood.github.io/simple-open-messaging-service/#/deploy" rel="noopener noreferrer"&gt;Docker Compose configuration generator&lt;/a&gt;&lt;/strong&gt; helps prepare a deployment configuration. Treat generated credentials as secrets, and use disposable data during the technical preview.&lt;/p&gt;

&lt;p&gt;Web/PWA, Android, macOS, and Linux clients are available in alpha. Check the release assets for the installation packages actually published for a particular version; source/build support is not the same as an available download.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://github.com/hapood/simple-open-messaging-service" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://github.com/hapood/simple-open-messaging-service/releases" rel="noopener noreferrer"&gt;Release assets&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://github.com/hapood/simple-open-messaging-service/tree/main/spec" rel="noopener noreferrer"&gt;SOMFP specification and schemas&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most useful feedback at this stage is concrete: try two test servers, interrupt connectivity, restore it, and inspect message catch-up and deletion propagation. Reports that include the versions, topology, and reproduction steps will help test whether these architectural choices hold up outside the development environment.&lt;/p&gt;

</description>
      <category>selfhosted</category>
      <category>opensource</category>
      <category>rust</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
