Store Refactorer
This Skill provides Claude Code with specific guidance for refactoring god stores into modular, maintainable slices.
When to use this skill
- When a store exceeds 300 lines (god store)
- When splitting Zustand stores into focused slices (≤120 lines each)
- When implementing Zustand v5 best practices (individual selectors, no destructuring)
- When creating facade exports for backward compatibility
- When consolidating duplicate stores across the codebase
- When eliminating circular dependencies between stores
- When applying Dexie persistence with partialize for selective persistence
Instructions
For detailed implementation guidance, refer to: Store Refactorer Agent
Workflow Integration
This skill is part of the eliminate-god-stores workflow:
- Store Analysis: Calculate size, identify circular dependencies, recommend slice boundaries
- Slice Extraction: Extract focused slices (≤120 lines each) with single responsibility
- Store Unification: Create unified store with composed slices
- Migration Execution: Create facade exports, update consumers, validate
- Validation & Cleanup: Verify zero breaking changes, update documentation
Quality Standards
Code Quality
- ✅ Max 120 lines per slice (excluding imports/comments)
- ✅ Max 10 functions per slice
- ✅ Max 5 dependencies per slice
- ✅ Individual selectors (Zustand v5 pattern)
- ✅ Persist on combined store (not per slice)
- ✅ Partialize for selective persistence
Backward Compatibility
- ✅ Zero breaking changes (facade exports)
- ✅ All old imports still work
- ✅ Consumer migration is optional
- ✅ API stability maintained
Example Usage
"Analyze and split src/lib/state/rag-store.ts using the eliminate-god-stores workflow"
This will:
- Analyze the god store (1,595 lines)
- Recommend slice boundaries (e.g., document-crud, chunk-management, embedding-ops)
- Extract slices (≤120 lines each)
- Create unified store with composed slices
- Create facade export for backward compatibility
- Validate with incremental TypeScript checking
Validation Commands
# TypeScript check (incremental, excludes test files)
pnpm tsc --noEmit --incremental
# Test suite
pnpm test
# Coverage check
pnpm test -- --coverage
Success Criteria
- ✅ All slices ≤120 lines
- ✅ Zero TypeScript errors (code files only)
- ✅ 100% test pass rate
- ✅ ≥80% test coverage
- ✅ Zero breaking changes
- ✅ Documentation updated (AGENTS.md, CLAUDE.md)
Converted and distributed by TomeVault — claim your Tome and manage your conversions.