This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build all binaries
go install ./...
# Run all tests
go test ./...
# Run tests with race detection
go test -race ./...
# Run a single package's tests
go test ./store
go test ./db
# Run a specific test
go test -run TestStoreSingleNode ./store
# Lint (must pass before commits)
go vet ./...
gofmt -l .
# Format code (always run after modifying Go files)
go fmt ./...E2E tests require building the binaries first:
go install ./...
RQLITED_PATH=$(go env GOPATH)/bin/rqlited python3 system_test/e2e/single_node.py
RQLITED_PATH=$(go env GOPATH)/bin/rqlited python3 system_test/e2e/multi_node.pyrqlite is a distributed relational database built on SQLite with Raft consensus. Key design principle: single binary with no external dependencies.
-
store/ - Central component managing Raft consensus. Contains FSM (Finite State Machine) that applies commands to SQLite. Handles Execute (writes), Query (reads), snapshots, and cluster coordination.
-
db/ - SQLite abstraction layer. Manages WAL (Write-Ahead Logging), checkpoints, and database hooks for CDC. Uses a forked go-sqlite3 (
github.com/rqlite/go-sqlite3). -
http/ - REST API server. Endpoints:
/db/execute(writes),/db/query(reads),/db/request(unified). Handles consistency levels, authentication, and node status. -
cluster/ - Inter-node communication using protobuf over TCP. Handles request forwarding to leader, node joins/removes.
-
command/ - Protobuf definitions for all operations (execute, query, backup, etc.). Located in
command/proto/. -
snapshot/ - Raft snapshot management. Supports full and incremental snapshots for efficient log truncation.
-
cdc/ - Change Data Capture. Hooks into SQLite preupdate/update callbacks, delivers changes to webhooks.
Writes: HTTP request → Store (Raft consensus) → FSM applies to SQLite → Response
Reads: HTTP request → Consistency check → Query SQLite → Response
Consistency levels: none, weak, linearizable, strong (leader-only reads)
cmd/rqlited/- Server binarycmd/rqlite/- CLI clientcmd/rqbench/- Benchmarking tool
github.com/hashicorp/raft- Consensus algorithmgithub.com/rqlite/go-sqlite3- Forked SQLite driver with additional hooksgo.etcd.io/bbolt- BoltDB for Raft log storagegoogle.golang.org/protobuf- Protocol buffer messages
/db/execute- Write operations (INSERT, UPDATE, DELETE)/db/query- Read operations (SELECT)/db/request- Unified endpoint accepting both reads and writes
- weak (default) - Fast, checks local leadership state, may have ~1s staleness
- linearizable - Verifies leadership via quorum heartbeat, ensures up-to-date reads
- none - Direct local reads, fastest but may be stale; use
freshnessparam to bound staleness - strong - Query goes through Raft log, slowest, mainly for testing
- Standard - Waits for Raft consensus before returning
- Queued (
?queue) - Returns immediately, batched automatically, orders of magnitude faster - Bulk - Multiple statements in single request/Raft entry for better throughput
Functions like RANDOM(), datetime('now') are rewritten before Raft log storage to ensure identical results across all replicas. Disable with ?norwrandom or ?norwtime.
- Raft quorum requires
(N/2)+1nodes (3-node cluster tolerates 1 failure, 5-node tolerates 2) - Auto-discovery via DNS, DNS-SRV, Consul, or etcd
- Manual clustering via
-joinflag or-bootstrap-expect Nfor simultaneous startup - Read-only nodes (
-raft-non-voter): Receive replication but don't vote, scale read throughput
- Hot backup:
/db/backupendpoint, supports SQL dump (?fmt=sql) and compression (?compress) - Auto-backup: Periodic backups to S3, GCS, MinIO, or local filesystem
- Restore:
/boot(fast, single-node) or/db/load(works on clusters) - CDC: Streams INSERT/UPDATE/DELETE to webhooks with at-least-once delivery
- Extensions: Load SQLite extensions via
-extensions-path
- Disk I/O (Raft fsync) is the primary bottleneck
- Queued writes dramatically improve throughput with small durability tradeoff
- SQLite runs in WAL mode with
SYNCHRONOUS=off(Raft provides durability) - Snapshot tuning:
-raft-snap(entries),-raft-snap-wal-size(WAL size threshold)
- Always run
go fmton modified Go source files - Prefer standard library packages over third-party dependencies
- If using a third-party package, explain why it's necessary