Architecture - robwhite4/claude-memory GitHub Wiki
Architecture Overview
This document describes the technical architecture of Claude Memory.
ποΈ System Architecture
βββββββββββββββββββ ββββββββββββββββββββ
β CLI (cmem) ββββββΆβ Memory System β
βββββββββββββββββββ ββββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββ
β Command Parser β β File System β
βββββββββββββββββββ ββββββββββββββββββββ
β
ββββββββββ΄βββββββββ
βΌ βΌ
ββββββββββββββββ ββββββββββββββββ
β .claude/ β β CLAUDE.md β
ββββββββββββββββ ββββββββββββββββ
π Directory Structure
project-root/
βββ CLAUDE.md # Primary AI context (committed)
βββ .claude/ # Memory system directory
βββ memory.json # Core data store
βββ config.json # User configuration
βββ context/ # Full context files (v1.7.0+)
β βββ knowledge.md # Complete knowledge base
β βββ patterns.md # All patterns
β βββ decisions.md # Decision history
β βββ tasks.md # Task details
βββ backups/ # Automatic backups
β βββ YYYY-MM-DD/ # Daily backup folders
βββ sessions/ # Session data (future)
π§© Core Components
bin/claude-memory.js
)
1. CLI Layer (- Command parsing and routing
- Global flag handling
- Input validation
- Output formatting
2. Memory System (inline in CLI)
- Data persistence
- CLAUDE.md generation
- Context file management
- Backup operations
3. Data Models
Memory Structure
{
version: "1.8.2",
projectName: "Project Name",
createdAt: "ISO-8601",
sessions: [...],
decisions: [...],
patterns: [...],
tasks: [...],
actions: [...],
knowledge: { category: { key: value } }
}
Session Model
{
id: "uuid",
name: "Session Name",
startedAt: "ISO-8601",
endedAt: "ISO-8601",
outcome: "string",
decisionsCount: 0,
patternsCount: 0
}
Decision Model
{
id: "uuid",
timestamp: "ISO-8601",
sessionId: "uuid",
decision: "string",
reasoning: "string",
alternatives: ["string"],
impact: "string"
}
π Data Flow
1. Command Execution
User Input β CLI Parser β Validation β Command Handler β Memory Update β File Write β CLAUDE.md Generation
2. CLAUDE.md Generation
Memory Data β Token Optimization β Template Rendering β Section Assembly β File Write
3. Context File Generation (v1.7.0+)
Memory Data β Category Grouping β Markdown Formatting β Individual File Write
π― Design Principles
1. Single Source of Truth
memory.json
contains all data- Other files are generated views
- No data duplication
2. Token Efficiency
- CLAUDE.md optimized for AI consumption
- Truncation with references to full data
- Smart summarization
3. Human Readable
- All files in Markdown or JSON
- Clear structure and formatting
- Self-documenting
4. Extensibility
- Plugin system planned for v2.0
- Clean command structure
- Modular design
π Security Considerations
Input Validation
- Path traversal prevention
- XSS protection in outputs
- Command injection prevention
- Size limits on inputs
File System
- Restricted to project directory
- Safe file operations
- Backup before modifications
π Performance
Current Optimizations
- Lazy loading of memory
- Efficient file writes
- Minimal dependencies
Future Improvements
- Streaming for large files
- Indexed searches
- Background operations
- Memory compression
π Integration Points
1. Git Integration
.gitignore
awareness- Commit helpers planned
- Branch-aware sessions
2. AI Assistant Integration
- CLAUDE.md format
- Token optimization
- Context references
3. Editor Integration (Future)
- VS Code extension planned
- Language server protocol
- Real-time updates
π Configuration System
Default Configuration
{
"autoSession": true,
"autoSessionHours": 4,
"autoBackup": true,
"backupInterval": 10,
"maxBackupDays": 7,
"tokenOptimization": true,
"silentMode": false
}
Environment Variables
CLAUDE_MEMORY_CONFIG
- Alternate config pathCLAUDE_MEMORY_SILENT
- Silent modeCLAUDE_MEMORY_PROJECT
- Project name override
π§ͺ Testing Architecture
Test Levels
- Unit Tests - Individual functions
- Integration Tests - Command flows
- Security Tests - Input validation
- E2E Tests - Full workflows
Test Coverage
- Target: 80%+ coverage
- Critical paths: 100%
- Security: 100%
For implementation details, see the source code and Development-Workflow.