|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Test Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Run all tests |
| 9 | +go test -v ./... |
| 10 | + |
| 11 | +# Build the CLI tool |
| 12 | +go build ./cmd/ltx |
| 13 | + |
| 14 | +# Install the CLI tool |
| 15 | +go install ./cmd/ltx |
| 16 | + |
| 17 | +# Build with version info (for releases) |
| 18 | +go build -ldflags "-s -w -X 'main.Version=<tag>' -X 'main.Commit=<sha>'" -o dist/ltx ./cmd/ltx |
| 19 | +``` |
| 20 | + |
| 21 | +## Architecture Overview |
| 22 | + |
| 23 | +LTX (Lite Transaction File) is a Go library and CLI for managing SQLite transactional data in an encrypted, compactable format. It stores SQLite page-level changes with checksums for replication and backup workflows. |
| 24 | + |
| 25 | +### File Format (Version 3) |
| 26 | + |
| 27 | +The LTX format has three sections: |
| 28 | +1. **Header** (100 bytes) - Transaction metadata, page size, TXID range, timestamps, checksums |
| 29 | +2. **Page Block** - LZ4-compressed page data with individual page headers |
| 30 | +3. **Trailer** (16 bytes) - Post-apply checksum and file integrity checksum |
| 31 | + |
| 32 | +### Core Components |
| 33 | + |
| 34 | +- **ltx.go** - Core types: `Header`, `PageHeader`, `Trailer`, `TXID`, `Checksum`, `Pos` |
| 35 | +- **encoder.go** - Encodes data into LTX format with LZ4 compression and rolling checksums |
| 36 | +- **decoder.go** - Decodes LTX files with checksum verification |
| 37 | +- **compactor.go** - Merges multiple LTX files into one compacted file |
| 38 | +- **checksum.go** - CRC-ISO-64 checksum utilities |
| 39 | + |
| 40 | +### CLI Commands (cmd/ltx/) |
| 41 | + |
| 42 | +| Command | Purpose | |
| 43 | +|---------|---------| |
| 44 | +| `ltx apply -db PATH FILES...` | Apply LTX files to SQLite database | |
| 45 | +| `ltx verify FILES...` | Verify LTX file integrity | |
| 46 | +| `ltx list [-tsv] FILES...` | Display metadata for LTX files | |
| 47 | +| `ltx dump PATH` | Dump all metadata and page info | |
| 48 | +| `ltx checksum DB_PATH` | Compute CRC-ISO-64 checksum of database | |
| 49 | +| `ltx encode-db DB OUTPUT.LTX` | Create LTX snapshot from database | |
| 50 | + |
| 51 | +### Key Types |
| 52 | + |
| 53 | +```go |
| 54 | +type Pos struct { // Replication position |
| 55 | + TXID TXID |
| 56 | + PostApplyChecksum Checksum |
| 57 | +} |
| 58 | + |
| 59 | +type TXID uint64 // Transaction ID |
| 60 | +type Checksum uint64 // CRC-ISO-64 checksum |
| 61 | +``` |
| 62 | + |
| 63 | +### Testing Patterns |
| 64 | + |
| 65 | +- Use `FileSpec` helper for creating in-memory test fixtures |
| 66 | +- Round-trip tests: encode -> decode -> verify |
| 67 | +- Table-driven tests for type parsing/marshaling |
| 68 | + |
| 69 | +# Version Control |
| 70 | + |
| 71 | +Always create feature branches. Never commit to main. Never do anything |
| 72 | +destructive without asking. |
0 commit comments