com um clique
ai-development-guide
// Detects code smells, anti-patterns, and debugging issues. Use when: fixing bugs, reviewing code quality, or refactoring.
// Detects code smells, anti-patterns, and debugging issues. Use when: fixing bugs, reviewing code quality, or refactoring.
Guides PRD, ADR, Design Doc, and Work Plan creation. Use when: planning features, writing specs, or creating technical documents.
Applies coding standards for clean, maintainable code. Use when: writing functions, handling errors, refactoring, or reviewing code style.
Selects implementation strategy (vertical/horizontal/hybrid) with risk assessment. Use when: planning features or deciding development approach.
Designs integration and E2E tests with mock boundaries. Use when: writing E2E tests, integration tests, or reviewing test quality.
Validates approach and checks assumptions before/after tasks. Use when: starting work, encountering errors, or switching phases.
Applies TDD process, test quality criteria, and mock guidelines. Use when: writing unit tests, using mocks, or reviewing test quality.
| name | ai-development-guide |
| description | Detects code smells, anti-patterns, and debugging issues. Use when: fixing bugs, reviewing code quality, or refactoring. |
Immediately stop and reconsider design when detecting the following patterns:
Prioritize primary code reliability over fallback implementations. In distributed systems, excessive fallback mechanisms can mask errors and make debugging difficult.
Infrastructure Layer:
Application Layer:
Review Triggers (require design review):
Before Implementing Any Fallback:
Note: Use your language's standard error handling mechanism (exceptions, Result types, error values, etc.)
❌ AVOID: Silent fallback that hides errors
[handle error]:
return DEFAULT_USER // Error is hidden, debugging becomes difficult
✅ PREFERRED: Explicit failure with context
[handle error]:
logError('Failed to fetch user data', userId, error)
propagate ServiceError('User data unavailable', error)
✅ ACCEPTABLE: Documented fallback with monitoring (when justified in Design Doc)
[handle error]:
// Fallback defined in Design Doc section 3.2.1
logWarning('Primary data source failed, using cache', error)
incrementMetric('data.fallback.cache_used')
cachedData = fetchFromCache()
if not cachedData:
propagate ServiceError('Both primary and cache failed', error)
return cachedData
| Duplication Count | Action | Reason |
|---|---|---|
| 1st time | Inline implementation | Cannot predict future changes |
| 2nd time | Consider future consolidation | Pattern beginning to emerge |
| 3rd time | Implement commonalization | Pattern established |
Cases for Commonalization
Cases to Avoid Commonalization
// ❌ Bad: Immediate commonalization on 1st duplication
function validateUserEmail(email) { /* ... */ }
function validateContactEmail(email) { /* ... */ }
// → Premature abstraction
// ✅ Good: Commonalize on 3rd occurrence
// 1st time: inline implementation
// 2nd time: Copy but consider future
// 3rd time: Extract to common validator
function validateEmail(email, context) { /* ... */ }
Symptom: Fixing one error causes new errors Cause: Surface-level fixes without understanding root cause Avoidance: Identify root cause with 5 Whys before fixing
Symptom: Many bugs after implementation Cause: Ignoring Red-Green-Refactor process Avoidance: Always start with failing tests
Symptom: Frequent unexpected errors when introducing new technology Cause: Assuming "it should work according to official documentation" without prior investigation Avoidance:
Certainty: low (Reason: no examples of MCP connection found)
Exploratory implementation: true
Fallback: use conventional API
Symptom: Duplicate implementations, architecture inconsistency, integration failures Cause: Insufficient understanding of existing code before implementation Avoidance Methods:
# How to read stack traces
1. Read error message (first line) accurately
2. Focus on first and last of stack trace
3. Identify first line where your code appears
Symptom: Application crash on startup
Why1: Configuration loading failed → Why2: Config file format changed
Why3: Dependency update → Why4: Library breaking change
Why5: Unconstrained dependency version specification
Root cause: Inappropriate version management strategy
To isolate problems, attempt reproduction with minimal code:
// Track problems with structured logs
log('DEBUG:', {
context: 'user-creation',
input: { email, name },
state: currentState,
timestamp: currentTimestamp()
})
Complete these stages sequentially before any implementation:
1. Discovery - Identify all affected code:
2. Understanding - Analyze each discovered location:
3. Identification - Produce structured report:
## Impact Analysis
### Direct Impact
- [Unit]: [Reason and modification needed]
### Indirect Impact
- [System]: [Integration path → reason]
### Data Flow
[Source] → [Transformation] → [Consumer]
### Risk Assessment
- High: [Complex dependencies, fragile areas]
- Medium: [Moderate coupling, test gaps]
- Low: [Isolated, well-tested areas]
### Implementation Order
1. [Start with lowest risk or deepest dependency]
2. [...]
Critical: Do not implement until all 3 stages are documented
Relationship to Pattern 5: This process provides the structured methodology to avoid "Insufficient Existing Code Investigation"
When unused code is detected:
In use? No → Delete
Yes → Working? No → Delete + Reimplement
Yes → Fix/Extend
Principle: Prefer clean implementation over patching broken code