DRY Principle References
This directory contains a patterns-and-examples reference for the DRY principle, covering when to apply it, when to deliberately avoid it, and context-specific guidance for React, Node.js, and TypeScript codebases.
Quick Navigation
| Reference File | Topics Covered | When to Read |
|---|---|---|
| patterns-examples.md | Rule of Three, configuration centralization, data normalization, shared types, custom hooks, coincidental duplication, over-abstraction, YAGNI, context-specific guidance | When deciding whether to extract repeated code or keep it inline |
Reading Strategy
For extracting repeated logic
- Read main SKILL.md for trigger criteria and Critical Patterns
- MUST read: patterns-examples.md Core Patterns section for the specific extraction pattern (React hooks, middleware, config, types)
For deciding whether duplication is intentional
- Read main SKILL.md Decision Tree
- CHECK: patterns-examples.md “When NOT to Apply DRY” section for coincidental duplication and over-abstraction examples
For context-specific DRY guidance (API routes, tests, CSS)
- Read main SKILL.md
- CHECK: patterns-examples.md “DRY in Different Contexts” section
File Descriptions
patterns-examples.md
Comprehensive DRY reference with side-by-side wrong/correct examples across frontend and backend contexts
- Rule of Three: email validation extraction across React forms; async error handler middleware for Express routes
- Configuration centralization: AUTH_CONFIG constant replacing scattered hardcoded values
- Data normalization: normalized entity store replacing duplicated user data in orders and invoices
- Shared TypeScript types: single User interface imported everywhere instead of redefined per file
- Custom hooks: useFetch
hook eliminating repeated fetch/loading/error state pattern across components - When NOT to apply: coincidental duplication (validateUser vs validateProduct with different change reasons), over-abstraction, YAGNI single-use utilities
- Context guide: API routes, database queries, configuration, tests, and CSS/styles
Cross-Reference Map
- patterns-examples.md → supplements SKILL.md Critical Patterns and Edge Cases
- Related skills: SOLID Principles (SRP: each piece of knowledge in one place)