This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
OpenAudio Protocol (go-openaudio) is a Go implementation of the Audius decentralized music distribution protocol. The system consists of validator nodes that run both consensus (CometBFT-based blockchain) and optional storage services (Mediorum) for decentralized audio content.
# Build native binary
make bin/openaudio-native
# Build for Linux (x86_64)
make bin/openaudio-x86_64-linux
# Build for Linux (ARM64)
make bin/openaudio-arm64-linux
# Build Docker dev image
make docker-dev# Start 4-node local devnet
make up
# Stop and cleanup devnet
make downThe devnet creates 4 nodes accessible at:
Before running the devnet, add to /etc/hosts:
echo "127.0.0.1 node1.oap.devnet node2.oap.devnet node3.oap.devnet node4.oap.devnet" | sudo tee -a /etc/hostsThen add the local dev x509 cert to your keychain so you will have green ssl in your browser.
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain dev/tls/cert.pem# Run all tests
make test
# Run unit tests only
make test-unit
# Run mediorum (storage) unit tests
make test-mediorum
# Run integration tests
make test-integration
# Cleanup after failed tests
make test-downCode generation is required when modifying SQL, Protocol Buffers, or Templ templates:
# Regenerate all code
make gen
# Regenerate SQL code from .sql files (using sqlc)
make regen-sql
# Regenerate protobuf code from .proto files
make regen-proto
# Regenerate templ HTML templates
make regen-templ
# Regenerate Ethereum contract bindings
make regen-contractsImportant: When editing .sql files in pkg/core/db/sql/ or pkg/eth/db/sql/, run make regen-sql to regenerate Go code. When editing .proto files in proto/, run make regen-proto. When editing .templ files in pkg/core/console/, run make regen-templ.
# Run linter
make lint
# Run linter with auto-fix
make lint-fix-
Core (
pkg/core/): CometBFT-based blockchain consensus layer- Manages validator consensus, block production, and transaction processing
- Implements Proof of Useful Work (PoUW) for validators
- Handles node registration and peer management
- Runs on ports 26656 (P2P), 26657 (RPC), 26659 (custom API)
-
Mediorum (
pkg/mediorum/): Optional content storage service- Decentralized blob storage for audio files and metadata
- Implements replication across multiple nodes (default: 4x replication)
- Supports multiple storage backends (local filesystem, S3, GCS)
- Only runs on "content nodes" (not "discovery nodes")
- Runs on port 1991
-
ETH Bridge (
pkg/eth/): Ethereum integration layer- Syncs on-chain registry data from Ethereum L1
- Manages validator registration and staking information
- Tracks service provider (SP) information
-
API Layer (
pkg/api/): gRPC/Connect services- Generated from Protocol Buffers definitions in
proto/ - Exposes both gRPC and REST endpoints via ConnectRPC
- Main services: CoreService, StorageService, SystemService, EthService
- Generated from Protocol Buffers definitions in
-
Console (
pkg/core/console/): Web UI dashboard- Built with Templ templates (Go-based HTML templating)
- Accessible at
/console/endpoints - Shows node status, blocks, transactions, peers, uptime
The main entry point (cmd/openaudio/main.go) starts multiple services:
- audiusd-echo-server: HTTP/HTTPS server with reverse proxies (ports 80/443)
- core: CometBFT blockchain node
- mediorum: Storage service (only if storage is enabled)
- uptime: Uptime tracking (disabled for localhost)
- eth: Ethereum bridge service
- Services communicate via gRPC/Connect on port 50051 (h2c - HTTP/2 without TLS)
- HTTP server (Echo framework) proxies requests to backend services
pos.PoSRequestchannel coordinates Proof of Stake operations between services- The
CoreServiceis shared across components and set viaSetCore()after initialization
Validators: Run both core + mediorum storage
- Identified by
nodeEndpointenv var - Store and serve audio content
- Require more resources (storage, bandwidth)
- Are meant to be the replacement for content nodes and the sole supported node type
Content Nodes: Run both core + mediorum storage
- Identified by
creatorNodeEndpointenv var - Store and serve audio content
- Require more resources (storage, bandwidth)
Discovery Nodes: Run core only (consensus + indexing)
- Identified by
audius_discprov_urlenv var - Do not store content
- Lighter resource requirements
- Are deprecated
- PostgreSQL for persistent state (both core and mediorum)
- BoltDB for CometBFT state and blockstore (embedded key-value store)
- Pebble for additional key-value storage needs
- SQL migrations in
pkg/core/db/sql/migrations/andpkg/eth/db/sql/migrations/ - SQLC generates type-safe Go code from SQL queries
Node configuration is primarily environment-variable driven:
- Validators:
nodeEndpoint,delegatePrivateKey,delegateOwnerWallet,spOwnerWallet - Content nodes:
creatorNodeEndpoint,delegatePrivateKey,delegateOwnerWallet,spOwnerWallet - Discovery nodes:
audius_discprov_url,audius_delegate_private_key,audius_delegate_owner_wallet - Network:
NETWORK(prod/stage/dev) - Storage:
AUDIUS_STORAGE_DRIVER_URL(local/s3/gcs) - TLS:
OPENAUDIO_TLS_DISABLED,OPENAUDIO_TLS_SELF_SIGNED
Genesis configurations are in pkg/core/config/genesis/ as JSON files.
- Definitions:
proto/directory - Generated code:
pkg/api/directory - Use
make regen-protoafter changes - ConnectRPC provides both gRPC and REST endpoints from same definitions
- Write queries in
pkg/core/db/sql/*.sqlorpkg/eth/db/sql/*.sql - SQLC config:
sqlc.yamlfiles in each db directory - Generated code appears in same directory as
.sql.gofiles - Use
make regen-sqlafter changes
- HTML templates using Go:
pkg/core/console/*.templ - Generates
*_templ.gofiles - Use
make regen-templafter changes
- Unit tests:
*_test.gofiles alongside source - Integration tests:
pkg/integration_tests/ - Tests run in Docker containers via docker-compose profiles
Examples in examples/ demonstrate SDK usage:
upload/: Upload content to the networkindexer/: Index blockchain dataprogrammable-distribution/: Implement custom distribution logic
Run with: go run ./examples/{example}/main.go (requires devnet running)
pkg/sdk/ provides client libraries for interacting with nodes:
sdk.go: Main SDK clientrelease.go: Release managementrewards/: Rewards queriesmediorum/: Storage operations
The dev Docker image supports hot reloading by mounting source directories:
docker run --rm -it \
-p 80:80 -p 443:443 \
-v $(pwd)/cmd:/app/cmd \
-v $(pwd)/pkg:/app/pkg \
audius/openaudio:dev- The codebase uses Go 1.25 (see
go.mod) - Main binary:
cmd/openaudio/main.go - Health check endpoint:
/health-check(returns JSON with core, storage, git SHA, uptime) - CometBFT version: 1.0.0
- Echo web framework for HTTP server
- Ethereum integration via go-ethereum (geth)
- Storage abstraction via gocloud.dev (supports S3, GCS, local filesystem)