docs/DOC_MAINTENANCE.md
This guide ensures documentation stays synchronized with code changes and follows the principle-based approach established in PR #787.
Key Insight: Code examples become outdated quickly. Documentation should focus on stable concepts rather than volatile implementations.
✅ DO Document:
❌ DON'T Document:
Trigger: Modifying ReplicaClient interface or any public interface
Required Updates:
Search for interface definitions in docs:
rg "type ReplicaClient interface" docs/ CLAUDE.md AGENTS.md .claude/
Update interface signatures (don't forget parameters!)
Document new parameters with clear explanations of when/why to use them
Update all example calls to include new parameters
Files to Check:
AGENTS.md - Interface definitionsdocs/REPLICA_CLIENT_GUIDE.md - Implementation guidedocs/TESTING_GUIDE.md - Test examples.claude/agents/replica-client-developer.md - Agent knowledge.claude/commands/add-storage-backend.md - Backend templates.claude/commands/validate-replica.md - Validation commandsTrigger: Adding new functionality, methods, or components
Approach:
See implementation in file.go:linesReference tests in file_test.goTrigger: Moving or renaming functions, restructuring code
Required Actions:
Search for references:
# Find function name references
rg "functionName" docs/ CLAUDE.md AGENTS.md .claude/
Update or remove:
DB.init() in db.go:123"), update itVerify links: Ensure all file:line references are still valid
Use this checklist when making code changes:
Search docs for affected code:
# Search for function names, types, or concepts
rg "YourFunctionName" docs/ CLAUDE.md AGENTS.md .claude/
Update interface definitions if signatures changed
Update examples if they won't compile anymore
Convert brittle examples to patterns if refactoring made them stale
Update file:line references if code moved
Verify contracts still hold (update if behavior changed)
Run markdownlint:
markdownlint --fix docs/ CLAUDE.md AGENTS.md .claude/
Search before committing:
git diff --name-only | xargs -I {} rg "basename {}" docs/
Review doc references in your PR description
Test examples compile (if they're meant to)
Monthly: Spot-check one documentation file against current codebase
Questions to ask:
replica_client.go?Rule: Delete outdated documentation rather than let it mislead
Better: A brief pattern description + reference to source than an outdated example
### How to initialize DB
```go
func (db *DB) init() {
db.mu.Lock()
defer db.mu.Unlock()
// ... 50 lines of code copied from db.go
}
\```
Problem: This will be outdated as soon as the implementation changes.
### DB Initialization Pattern
**Principle**: Database initialization must complete before replication starts.
**Pattern**:
1. Acquire exclusive lock (`mu.Lock()`)
2. Verify database state consistency
3. Initialize monitoring subsystems
4. Set up replication coordination
**Critical**: Use `Lock()` not `RLock()` as initialization modifies state.
**Reference Implementation**: See `DB.init()` in db.go:150-230
Benefits: Stays accurate even if implementation details change, focuses on the "why" and "what" rather than the "how".
# Find all code examples in documentation
rg "^```(go|golang)" docs/ CLAUDE.md AGENTS.md .claude/
# Find file:line references
rg "\.go:\d+" docs/ CLAUDE.md AGENTS.md .claude/
# Find interface definitions
rg "type .* interface" docs/ CLAUDE.md AGENTS.md .claude/
# Lint all docs
markdownlint docs/ CLAUDE.md AGENTS.md .claude/
# Auto-fix issues
markdownlint --fix docs/ CLAUDE.md AGENTS.md .claude/
# List all go files mentioned in docs
rg -o "[a-z_]+\.go:\d+" docs/ CLAUDE.md AGENTS.md | sort -u
# Verify they exist and line numbers are reasonable
When updating documentation, ask:
Is this a stable concept or a volatile implementation?
Will this stay accurate for 6+ months?
Does this explain WHY or just WHAT?
Would a link to source code be better?