README.md
What it documents: Project overview, current status, quick start
Update when: Milestone reached, tech stack changed
Truth Syncing is the practice of automatically updating source-of-truth documentation when code changes. It prevents documentation drift by making doc updates a mandatory part of task completion.
Traditional projects suffer from temporal drift: code evolves, but docs stay frozen in time.
Sprint 1: Initial Implementation
Database: MongoDB with Mongoose ODMimport mongoose from 'mongoose';Sprint 5: Migration to PostgreSQL
Developer implements migration, updates code:
import { Pool } from 'pg';But forgets to update docs:
Database: MongoDB with Mongoose ODM ⚠️ STALESprint 10: AI Agent Confusion
AI agent reads ARCHITECTURE.md, sees “MongoDB”, generates Mongoose queries for a PostgreSQL database.
Result: Code doesn’t work. Hours wasted debugging.
Before archiving a completed task, update the relevant source-of-truth files to reflect system changes.
The Flow: NEXT → CODE → TRUTH → ARCHIVE
1. Work on task in NEXT-TASKS.md2. Implement code changes3. Update docs/core/ (Truth Syncing)4. Archive task to docs/archive/Result: Documentation is always synchronized with code.
Source of Truth files are the canonical reference for how the system works:
README.md
What it documents: Project overview, current status, quick start
Update when: Milestone reached, tech stack changed
ARCHITECTURE.md
What it documents: System design, component structure, data flow
Update when: New service added, database changed, architecture evolved
PATTERNS.md
What it documents: Coding conventions, design patterns, best practices
Update when: New pattern established, old pattern deprecated
DOMAIN-LOGIC.md
What it documents: Business rules, core principles, system constraints
Update when: Rule changed, new constraint added
The Rule: If a task changes the system, a source-of-truth file must be updated.
When completing a task, ask:
“Did this task change how the system works?”
Examples:
ARCHITECTURE.md and PATTERNS.mdARCHITECTURE.mdPATTERNS.mdREADME.mdExamples (Chores):
Rule: If it doesn’t change architecture, patterns, or business logic, skip Truth Syncing.
Use this decision matrix:
| Change Type | Update Target | Example |
|---|---|---|
| Milestone reached | README.md → Current Phase | ”Phase 2 Complete: CLI tool shipped” |
| New file added | ARCHITECTURE.md → File structure | Add bin/cortex-tms.js to CLI section |
| Component added | ARCHITECTURE.md → Components | Document new ValidationService |
| Rule changed | DOMAIN-LOGIC.md → Specific rule | Update Rule 4 line limits |
| New pattern | PATTERNS.md → Add pattern | Document new “API Error Handling” pattern |
| Pattern deprecated | PATTERNS.md → Mark deprecated | Strike through old “Class Component” pattern |
| New decision | docs/decisions/ → Add ADR | Create 0023-switch-to-postgresql.md |
| Tech stack change | ARCHITECTURE.md → Tech decisions | Update from Bun to Node in stack section |
Example: Task completed: “Migrate from MongoDB to PostgreSQL”
<!-- ARCHITECTURE.md (STALE) -->## Tech Stack
- **Database**: MongoDB with Mongoose ODM- **ORM**: Mongoose schemas for type safetyTask is ✅ Done, but docs are wrong.
<!-- ARCHITECTURE.md (CURRENT) -->## Tech Stack
- **Database**: PostgreSQL 15- **ORM**: Prisma for type-safe queriesTask is ✅ Done and docs are accurate.
When archiving the task, mention which truth files were updated:
# Sprint: Database Migration (2026-01-10 to 2026-01-24)
## Completed Tasks
✅ **Migrate from MongoDB to PostgreSQL** - Implemented Prisma schema - Migrated all data - Updated connection logic in `src/db/connection.ts`
## Truth Updates- `ARCHITECTURE.md` → Updated tech stack section- `docs/decisions/0023-switch-to-postgresql.md` → Added ADRWhy: Creates an audit trail. Future developers can trace architectural changes.
Before archiving a task, verify:
docs/core/*.md file needs updating?Task: “Add real-time notifications using WebSockets”
Truth Updates Needed:
Update ARCHITECTURE.md
## System Components
### WebSocket Server- **Purpose**: Real-time bidirectional communication- **Technology**: Socket.io- **Location**: `src/services/websocket.ts`Update PATTERNS.md
## Real-Time Communication Pattern
**Canonical Example**: `src/services/websocket.ts`
**Rules**:- Use Socket.io for WebSocket abstraction- Authenticate via JWT in handshake- Namespace events by feature (auth, chat, notifications)Archive Task
✅ Add real-time notifications using WebSockets
**Truth Updates**:- ARCHITECTURE.md → Added WebSocket Server section- PATTERNS.md → Added Real-Time Communication PatternTask: “Replace Express with Fastify for API server”
Truth Updates Needed:
Update ARCHITECTURE.md
## Tech Stack
- **API Framework**: Fastify 4 (previously Express)- **Why**: 2x faster, built-in schema validation, better TypeScript supportUpdate PATTERNS.md
## API Route Pattern
~~**Old (Express)**:~~```typescriptapp.get('/api/users', async (req, res) => { ... });New (Fastify):
fastify.get('/api/users', async (request, reply) => { ... });Create ADR
# 42. Migrate from Express to Fastify
**Status**: Accepted**Date**: 2026-01-20
## ContextExpress middleware performance is bottlenecking API response times.
## DecisionMigrate to Fastify for 2x performance improvement.
## Consequences- Faster API responses- Better TypeScript support- Migration effort: ~2 weeksArchive Task
✅ Replace Express with Fastify
**Truth Updates**:- ARCHITECTURE.md → Updated API Framework- PATTERNS.md → Updated API Route Pattern- docs/decisions/0042-migrate-to-fastify.md → Created ADRTask: “Remove class components, fully migrate to hooks”
Truth Updates Needed:
Update PATTERNS.md
## Component Patterns
~~**Class Components** (Deprecated 2026-01)~~
**Function Components with Hooks** (Current Standard)- Use `useState` for local state- Use `useEffect` for side effects- Use custom hooks for reusable logicArchive Task
✅ Remove class components, fully migrate to hooks
**Truth Updates**:- PATTERNS.md → Deprecated class component pattern- All components now use hooksThe complete workflow: FUTURE → NEXT → CODE → TRUTH → ARCHIVE
Promote Task from Backlog
Move task from FUTURE-ENHANCEMENTS.md to NEXT-TASKS.md
Implement Task
Write code, run tests, commit changes
Truth Syncing
Update docs/core/ files to reflect system changes
Validation
Run cortex-tms validate --strict to ensure docs are valid
Archive Task
Move completed task from NEXT-TASKS.md to docs/archive/sprint-YYYY-MM.md
Repeat
When NEXT-TASKS.md has < 3 tasks, promote more from backlog
1. Implement feature2. ✅ Mark task done3. (Maybe update docs... probably forget)4. Archive task5. ⚠️ Docs drift from realityResult: 3 months later, docs are 50% accurate.
1. Implement feature2. Update docs (mandatory)3. Validate docs (automated)4. ✅ Mark task done5. Archive taskResult: Docs are always accurate.
Truth Syncing is enforced through validation:
cortex-tms validate --strictChecks:
Failed validation = Failed build in CI/CD.
This repository uses Truth Syncing to build itself.
Recent Example:
Task: “Add cortex-tms validate command”
Truth Updates:
ARCHITECTURE.md → Added CLI validation sectionPATTERNS.md → Added validation patternREADME.md → Updated feature list with validationdocs/archive/sprint-2025-12.md → Archived task with truth update referencesResult: Anyone reading the docs knows validation exists and how it works.
Mistake: “I’ll update docs after the sprint ends”
Why it fails: You forget. 3 months later, docs are wrong.
Fix: Update docs before archiving the task. Make it part of “done”.
Mistake: Adding a new ARCHITECTURE-v2.md instead of updating ARCHITECTURE.md
Why it fails: Now there are two sources of truth. AI agents don’t know which to trust.
Fix: Update the canonical file. Archive old versions to docs/archive/.
Mistake:
✅ Task completed
Truth updates: Updated some docsWhy it fails: No audit trail. Can’t trace which docs changed.
Fix:
✅ Task completed
Truth updates:- ARCHITECTURE.md → Updated database section- PATTERNS.md → Added caching patternNo Documentation Drift
Docs are updated with every system change. Truth always matches reality.
AI Agents Trust Docs
When docs are accurate, AI agents follow them confidently. No hallucinations.
Audit Trail
Archive entries show which docs changed when. Easy to trace architectural evolution.
Enforced Discipline
“Done” means code and docs are updated. No shortcuts.
Add this to your Definition of Done in NEXT-TASKS.md:
## 🎯 Definition of Done
- [ ] Code implemented and tested- [ ] Truth Syncing: Updated relevant docs/core/ files- [ ] Validation: `cortex-tms validate --strict` passes- [ ] Changes committed with conventional format- [ ] Task archived with truth update references#!/bin/bash
# Check if code changed but docs didn'tCODE_CHANGED=$(git diff --cached --name-only | grep -E "^src/")DOCS_CHANGED=$(git diff --cached --name-only | grep -E "^docs/core/")
if [ -n "$CODE_CHANGED" ] && [ -z "$DOCS_CHANGED" ]; then echo "⚠️ Code changed but docs/core/ unchanged" echo "Did you update truth files (ARCHITECTURE, PATTERNS, etc.)?" read -p "Continue anyway? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fifiResult: Git warns if you commit code without updating docs.
Add to CLAUDE.md:
## Post-Task Protocol
After completing a task, follow these steps:
1. **Truth Syncing**: Ask yourself "Which docs/core/ file needs updating?"2. **Update Truth**: Modify ARCHITECTURE.md, PATTERNS.md, etc.3. **Validate**: Run `cortex-tms validate --strict`4. **Archive**: Reference truth updates in archive entryResult: AI agent automatically performs Truth Syncing.
Now that you understand Truth Syncing: