Architecture

Lattice is a local-first, peer-to-peer replicated state machine engine written in Rust. It provides an application-agnostic framework for building distributed data structures that synchronize across a mesh of nodes without a central authority. All reads and writes are served from a local embedded database (redb), giving zero-latency offline operation, while a QUIC-based networking layer (Iroh) handles encrypted replication across peers.

Core Protocol: Weaver

The heart of Lattice is the Weaver Protocol, a hybrid Merkle DAG + linearized witness log architecture:

  1. Intentions (DAG): Every write produces a SignedIntention — a BLAKE3-hashed, Ed25519-signed operation that includes a Condition (pointers to prior hashes from the same author and any causally-dependent operations). These form a content-addressed DAG.
  2. Floating resolution: Out-of-order intentions are buffered as “floating” and indexed by their missing dependency hash. When the dependency arrives, dependents are woken and applied.
  3. Witness log (linearization): The local node “witnesses” each applied intention by appending it to a monotonic, cryptographically chained WitnessRecord log, establishing a local total order.

Serialization is dual-format: Borsh for deterministic canonical hashing/signing, Protobuf for wire transport and IPC.

Storage Architecture

State Machines (Pluggable CRDTs)

State machines are pluggable via the StateMachine trait (defined in lattice-model). Two ship:

Both expose runtime introspection via embedded prost-reflect FileDescriptorSet, enabling the CLI and bindings to discover and invoke store methods dynamically without compile-time knowledge.

Networking Layer

Node Orchestration

Runtime & Interfaces

Cryptographic Primitives

PrimitiveAlgorithmPurpose
HashBLAKE3 (32 bytes)Content addressing, DAG linkage, fingerprints
SignatureEd25519Intention signing, witness signing
ClockHybrid Logical Clock (HLC)Causal ordering, LWW conflict resolution
IdentityEd25519 keypair (identity.key)Node identity, bound to Iroh QUIC endpoint

Dependency Graph (Layered)

lattice-model          (primitives, traits, zero deps)
    ↓
lattice-storage        (redb, StateBackend)
lattice-systemstore    (Y-Adapter, SystemLayer)
lattice-kvstore        (KvState, LWW CRDT)
lattice-logstore       (LogState, append-only)
    ↓
lattice-kernel         (Weaver, ReplicationController, IntentionStore)
    ↓
lattice-net-types      (Transport/GossipLayer traits, NetworkStore)
lattice-sync           (Negentropy Reconciler)
    ↓
lattice-net            (NetworkService, transport-agnostic)
lattice-net-iroh       (IrohTransport, GossipManager, production QUIC)
lattice-net-sim        (ChannelTransport, BroadcastGossip, in-memory)
    ↓
lattice-node           (Node, StoreManager, RecursiveWatcher)
    ↓
lattice-api            (gRPC/UDS, RpcServer/Client)
lattice-runtime        (RuntimeBuilder, LatticeBackend)
    ↓
lattice-bindings       (UniFFI → Swift/Kotlin)
lattice-cli            (REPL, dynamic Protobuf)
lattice-daemon         (latticed binary)