Skip to content

Architecture

How clusters exchange messages over NATS, Hyperswarm and L1 advertisements.

Decentralized NATS

Mesh architecture

Select the diagram to open it at full size.

Agent-side SDK

Component Role
advertise() API and advertise module Subscribe to local subjects on the local NATS mesh, and advertise inter-cluster subjects through the Hyperswarm bridge API client
send, recv, send_recv and subscribe APIs Basic messaging functions
Connection resolver Obtains the connection for a subject_id. The connection is cached and is the same for internal and external subjects
NATS connection Always connects to the local NATS mesh
Local NATS subscriber Serves local subjects

Cluster NATS

Component Role
Cluster NATS server Routes subjects to local connections and to the leaf connection
NATS leaf node Connects to the server over a leaf connection managed by NATS, and to the bridge over TCP

Hyperswarm bridge

Component Role
TCP connection manager and packet parser Obtain NATS messages from the TCP stream. Both push and pull work
Message type handler Routes messages to the subscribe or publish handler after the message policy
subscribe request handler Queries L1 for the subject_id and asks the connection manager for the owning bridge
Publish handler and publish module Look up the public key of the target and send the message
Encryptor Encrypts data with the key of the target bridge
Connection manager Adds new Hyperswarm connections to the table
Hyperswarm connections pool Holds live connections
Signature verification and decryption Verifies and decrypts incoming messages, using the cluster agent
Table CRUD module Stores subject_id, hsm_topic_id and pub_key
Message send/receive policy executor and policy state Filter and rate limit messages

Bridge advertisement and configuration

Component Role
Bridge advertisement API Accepts subjects to advertise
Cluster-advertise policy checker Checks that the subject may be advertised, against the list of advertised subjects
Advertisement packet creator Builds the advertisement with the public key from the key derivation module
Signer and cluster key manager client Sign the advertisement through the cluster signing agent
Cluster signing agent Holds the key on a local volume (default) or uses a custom wallet client for remote signing
L1 client Publishes the message with Nostr and queries L1
Bridge config API Accepts configuration updates

Cluster controller

Component Role
Bridge deployer API Accepts a bridge deployment
Bridge config API Accepts a configuration update
Pre-check policy Checks that deployment parameters match the policy of the cluster and that configuration updates are allowed
Bridge deployer Kubernetes client Deploys the bridge
Bridge config updater Pushes configuration updates to the bridge over REST