Skip to content

Protocol Overview

Sonata uses Protocol Buffers (protobuf) as its interface definition language, with ConnectRPC providing the RPC framework for client-server communication.

Overview

The protocol layer defines all data structures and service interfaces across the Sonata network. This includes chain state, API services, P2P messages, and storage operations.

Architecture

┌─────────────────────────────────────────────────────────┐
│                    proto/ schemas                       │
│  (account, api, chain, composition, ddex, storage...)   │
└─────────────────────────────┬───────────────────────────┘

                         buf generate


┌─────────────────────────────────────────────────────────┐
│                      gen/ output                        │
│           Go types + ConnectRPC service stubs           │
└─────────────────────────────┬───────────────────────────┘

              ┌───────────────┴───────────────┐
              ▼                               ▼
┌─────────────────────────┐     ┌─────────────────────────┐
│     Server (x/server)   │     │    Clients (SDK)        │
│   Implements services   │     │   Consumes services     │
└─────────────────────────┘     └─────────────────────────┘

Key Components

ComponentDescription
proto/Schema definitions in .proto files
gen/Generated Go code from protobuf schemas
BufBuild tool for protobuf (linting, breaking change detection, generation)
ConnectRPCModern RPC framework compatible with gRPC, gRPC-Web, and HTTP/JSON

Why This Stack?

  • Protobuf: Strongly-typed, language-agnostic, efficient binary serialization
  • ConnectRPC: Simpler than gRPC, browser-compatible, HTTP/JSON fallback
  • Buf: Modern tooling for schema management and code generation

Schema Organization

The proto/ directory is organized by domain:

  • api/v1/ — External API service definitions
  • chain/v1/ — On-chain transaction and state types
  • account/v1/ — Account-related messages
  • storage/v1/ — File storage messages
  • ddex/v1/ — DDEX metadata types
  • composition/v1/ — Music composition types
  • p2p/v1/ — Peer-to-peer network messages
  • store/ — Internal storage key schemas