This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pgstream is a PostgreSQL Change Data Capture (CDC) tool and Go library. It captures WAL changes from PostgreSQL and routes them to multiple targets: PostgreSQL, Elasticsearch/OpenSearch, Kafka, or Webhooks. It supports schema tracking, DDL replication, data snapshots, and column-level transformations for anonymization.
# Build
make build
# Run all unit tests (with race detector, 10m timeout)
make test
# Run a single test
go test -run TestName ./pkg/path/to/package
# Run integration tests (requires Docker for testcontainers)
PGSTREAM_INTEGRATION_TESTS=true go test -timeout 180s github.com/xataio/pgstream/pkg/stream/integration
# Lint (golangci-lint v2)
make lint
# Run code generation (CLI definition + transformer definition)
make generate
# Generate migration binaries
make gen-migrations
# Fuzz tests
make fuzz
# License header check
make license-checkSource (PostgreSQL WAL / Kafka) → Listener
→ Processor chain: Filter → Injector → Transformer → Target Writer
→ Checkpointer (tracks LSN/offset progress)
The streaming pipeline is assembled in pkg/stream/stream.go. Sources produce WAL events, which flow through an ordered chain of processors before reaching the target writer. Each processor is optional and configured independently.
cmd/— CLI commands (cobra):run,init,snapshot,status,destroy,validatecmd/config/— Configuration parsing (YAML, env vars, CLI flags via viper)pkg/stream/— Pipeline orchestration: wires listeners, processors, and checkpointers togetherpkg/wal/listener/— WAL event sources (PostgreSQL replication, Kafka consumer)pkg/wal/processor/— Processing stages:postgres/— PostgreSQL target writersearch/— Elasticsearch/OpenSearch indexerkafka/— Kafka batch writerwebhook/— HTTP webhook notifiertransformer/— Column value transformationsfilter/— Schema/table filteringinjector/— Metadata/ID injection
pkg/wal/replication/— Replication slot managementpkg/wal/checkpointer/— LSN/offset checkpoint trackingpkg/snapshot/— Initial and on-demand snapshot logicpkg/transformers/— Data transformation implementations (greenmask, neosync, go-masker integrations)internal/— Internal utilities (postgres client, search store, migrator, test helpers)migrations/— SQL migrations (core schema + injector), compiled to Go via go-bindata
Supports YAML files, .env files, and CLI flags. Config parsing lives in cmd/config/. Environment variables use the PGSTREAM_ prefix.
Located in pkg/stream/integration/. They use testcontainers-go to spin up PostgreSQL, Elasticsearch, OpenSearch, and Kafka. Gated by PGSTREAM_INTEGRATION_TESTS=true env var.
- Error wrapping: Use
fmt.Errorfwith%w. Thegithub.com/pkg/errorspackage is forbidden. - No fmt.Print: Use structured logging (zerolog).
fmt.Print*calls are blocked by linter. - Formatting: gofumpt (enforced by golangci-lint).
- License headers: All
.gofiles must start with// SPDX-License-Identifier: Apache-2.0. - No CGO: Builds use
CGO_ENABLED=0. - Interface-driven design: Processors, listeners, and stores use interfaces extensively with mock implementations for testing.