This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Open Code Protocol (OCP) server monolith, a Go-based gRPC/web service system that powers next-generation currency launchpad and payment systems. It implements the first L2 solution on Solana using an intent-based system backed by a sequencer.
# Run all tests with coverage
make test
# Run tests for a specific package
go test ./ocp/rpc/transaction/...
# Run a single test
go test -run TestName ./path/to/package
# Run tests with verbose output
go test -v ./...This is a library project without a main entry point. Integration is done by importing packages into applications.
Intent System & Sequencer (ocp/ package)
- The heart of the L2 solution lives in the
ocp/package - Intent-based transaction system: clients submit intents, sequencer processes them
- Key components:
ocp/rpc/: gRPC service implementations (entry points for client requests)ocp/worker/: Background workers (nonce management, swap processing, sequencer, Geyser integration)ocp/transaction/: Transaction building and local nonce pool managementocp/data/: Data layer with Store interfaces for all domain entities
Data Layer Architecture
- Pattern: Interface-based stores with multiple implementations (Postgres, in-memory)
- Each domain entity (account, intent, fulfillment, action, etc.) has:
ocp/data/{entity}/store.go: Store interface definitionocp/data/{entity}/postgres/: Postgres implementationocp/data/{entity}/memory/: In-memory implementation for testsocp/data/{entity}/tests/: Shared test suite for all implementations
ocp/data/provider.go: Aggregates all stores into a single Provider interface- Provider composes three data sources: BlockchainData, DatabaseData, WebData
gRPC Application Framework (grpc/app/)
- Standardized app lifecycle: Init -> RegisterWithGRPC -> Run -> Stop
- Apps implement the
Appinterface with initialization, service registration, and shutdown - Built-in features: New Relic integration, TLS support, health checks, pprof/expvar
- Interceptor chain: headers -> metrics -> validation -> min version checking
- Configuration via Viper (YAML files or environment variables)
Transaction & Intent Flow
- Client submits intent via
ocp/rpc/transaction/server.go - Intent validated through antispam/AML guards
- Sequencer worker (
ocp/worker/sequencer/) processes intent - Actions scheduled and executed (intent_handler, action_handler, fulfillment_handler)
- Transactions built using local nonce pools to avoid Solana RPC contention
- Fulfillments committed and monitored
Solana Integration
solana/package: Low-level Solana primitives (accounts, transactions, programs)solana/token/: SPL Token program interface- VM indexer client for tracking on-chain state changes
- Geyser worker (
ocp/worker/geyser/) for real-time blockchain event streaming
Workers
- All workers implement
Runtimeinterface (Start method with interval) ocp/worker/sequencer/: Core sequencer logic (intent, action, fulfillment handlers)ocp/worker/nonce/: Nonce allocation and pool managementocp/worker/swap/: Token swap processingocp/worker/account/: Account state synchronizationocp/worker/geyser/: Blockchain event streaming via Geyser
Database Transactions
- Use
database/postgres/db.goutilities:ExecuteTxWithinCtxfor transactions - Automatic retry on serialization failures via
ExecuteRetryable - Context-based transaction passing (no explicit tx parameters)
- Default isolation: ReadCommitted
Testing
- Shared test suites in
{package}/tests/tests.gofor interface conformance - Postgres tests use
ory/dockertestfor containerized database setup testutil/provides shared test utilities (server mocking, VM utilities, wait helpers)- In-memory implementations available for fast unit tests
Configuration
config/package: Interface-based config with env and memory providers- App-level config in
grpc/app/config.go(listen addresses, TLS, logging, New Relic) - Service-specific config in respective packages (e.g.,
ocp/rpc/transaction/config.go)
Metrics & Observability
- New Relic integration throughout (traces, logs, custom events)
metrics/package: Constants, event tracking, tracing utilities- Custom metrics in service packages (e.g.,
ocp/rpc/transaction/metrics.go)
Error Handling
- Sentinel errors defined in store interfaces (e.g.,
ErrAccountInfoNotFound) - Use
github.com/pkg/errorsfor error wrapping with context - gRPC error codes mapped appropriately in RPC handlers
Protobuf definitions are in the separate ocp-protobuf-api repository. This project imports generated Go code from that repo.
When working with data stores:
- Always check existing Store interface before adding new methods
- Implement for both Postgres and memory stores
- Add to shared test suite to ensure consistency
- Use context for cancellation, not timeouts
When adding new RPC methods:
- Follow existing patterns in
ocp/rpc/transaction/server.go - Add metrics collection for the new endpoint
- Implement appropriate authentication via
ocp/auth/signature.go - Add antispam/AML checks if handling user funds
When working with Solana transactions:
- Use
ocp/transaction/package utilities for building transactions - Leverage
LocalNoncePoolto avoid Solana nonce contention - Always include proper signature verification
- Test with local simulation before blockchain submission
Worker development:
- Implement
Runtimeinterface fromocp/worker/runtime.go - Use appropriate intervals based on task criticality
- Include proper context cancellation handling
- Add metrics for monitoring worker health