This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Run all tests (Kaocha)
clj -M:test
# Run specific test namespace
clj -M:test --focus konserve-sync.sync-test
# Watch mode (re-run on file changes)
clj -M:test --watch
# Run ClojureScript tests (shadow-cljs)
npx shadow-cljs compile testkonserve-sync is a single-writer replication layer for konserve key-value stores. It enables real-time sync from a primary store to multiple subscribers.
sync.cljc - Main orchestration layer
SyncContextrecord holds supervisor, state atom, and options- Server-side:
register-store!,serve-subscription!,unregister-store! - Client-side:
subscribe!,unsubscribe!,register-callback! - State atom structure:
{:stores {store-id {...}}, :subscriptions {...}, :receivers {...}}
emitter.cljc - Server-side change detection
- Hooks into konserve's write-hook system via
k/add-write-hook! EmitterStatewraps store with update channel and filter function- Broadcasts changes to the update channel for relay to subscribers
receiver.cljc - Client-side update application
ReceiverStatewraps local store with callback registryapply-update!writes incoming messages to local konserve storeCallbackRegistryenables per-key update notifications
protocol.cljc - Message protocol and store identification
- Message types:
:sync/subscribe,:sync/update,:sync/batch-complete, etc. store-idcomputes UUID from normalized config via hasch- Critical:
:scopekey must match between client/server for store identity
transport/protocol.cljc - Transport abstraction
PSyncTransport:send!,on-message!,close!PSyncServer:on-connection!,broadcast!
transport/channels.cljc - In-memory channel transport for testing
transport/kabel.cljc - Network transport via WebSockets
- Server calls
register-store!which sets up write-hook emitter - Client calls
subscribe!with local-key-timestamps map - Server compares timestamps, sends only newer/missing keys in batches
- Batch acks provide backpressure flow control
- After initial sync completes, incremental updates flow via write-hooks
superv.async- Supervision and error handling (go-try,<?,S)konserve- Key-value store abstractionhasch- Content-addressed hashing for store-id computationkabel- Network transport (dev/test dependency)kaocha- Test runner
- All source files are
.cljc(cross-platform Clojure/ClojureScript) - Reader conditionals:
#?(:clj ... :cljs ...)for platform-specific code - Async operations use
go-try/go-loop-trywith supervisorS - Error propagation via
<?(throwing take from channel)