Cva analysis

From rjmurillo/ai-agents · View interactive version

Cva analysis is an AI agent skill from the GitHub repository rjmurillo/ai-agents. Systematic abstraction discovery using Commonality Variability Analysis. Build matrix of what varies vs what's constant, then let patterns emerge. Prevents wrong abstractions by deferring pattern selection until requirements are analyzed. Use when facing multiple similar requirements and need to dis

How to use this skill

Skill file

CVA Analysis - Discover Natural Abstractions

Commonality Variability Analysis (CVA) is a systematic technique for discovering abstractions from requirements. Instead of choosing patterns first, you build a matrix showing what's COMMON (constant across use cases) vs what VARIES (differs between cases). Patterns emerge naturally from the matrix structure.

Core Insight: Rows (commonalities) map to Strategy pattern. Columns (variabilities) map to Abstract Factory pattern. The matrix reveals whether abstraction is needed at all.

From CLAUDE.md Design Philosophy: "Greatest vulnerability is wrong or missing abstraction." CVA prevents wrong abstractions by making pattern selection evidence-based, not intuition-based.

Triggers

Activate CVA when you encounter:

Quick Reference

| Phase | Purpose | Input | Output | Time |

|-------|---------|-------|--------|------|

| 1. Identify Commonalities | Find what's constant across ALL use cases | Use cases/requirements | List of commonalities (matrix rows) | 5-10 min |

| 2. Identify Variabilities | Find what VARIES between use cases | Commonalities + use cases | List of variabilities (matrix columns) | 5-10 min |

| 3. Build Matrix | Visualize commonality × variability relationships | Rows + columns | CVA matrix (Markdown table) | 5-15 min |

| 4. Map to Patterns | Translate matrix structure to design patterns | Completed matrix | Pattern recommendations + rationale | 5-10 min |

| 5. Validate & Handoff | Validate choices, route to appropriate agents | Pattern recommendations | Validation report + ADR stub | 5-10 min |

Total Time: Quick (15 min), Standard (30 min), Deep (60 min)

When to Use

Use CVA when:

Do NOT use CVA when:

Process

Delegation on each host. "Delegate to the X agent" means the host's subagent tool: Claude Code Task with subagent_type="X"; Copilot CLI task with agent_type="project-toolkit:X"; Codex spawn_agent with agent_type="X", plus fork_turns="none" when the agent reviews or judges work (the default hands it your whole history); Muse Code subagent_spawn with role="X" and an objective, plus worktree_isolation: true for an agent that writes files. If the host has no subagent tool, or no X agent is installed, run the step yourself in this session.

Phase 1: Identify Commonalities

Purpose: Establish what is ALWAYS true across ALL use cases. This becomes the stable foundation.

Steps:

  1. Start with first use case: What does it need? List all capabilities.
  2. Add second use case: What do BOTH need? Extract shared capabilities.
  3. For each additional use case: What do ALL cases need?
  4. Document as matrix ROWS: Each row is a commonality present in every use case.

Example (Payment Processing):

Use Case 1: Credit card payment
Use Case 2: PayPal payment
Use Case 3: Bank transfer

Commonalities (ALL cases need):
- Validate payment amount
- Authorize transaction
- Record transaction
- Handle transaction errors

Verification:

Failure Handling: If no commonalities exist, use cases may be unrelated. Analyze separately or reconsider grouping.


Phase 2: Identify Variabilities

Purpose: Discover what VARIES between use cases. This reveals extension points where Strategy or Abstract Factory patterns may apply.

Steps:

  1. For each commonality, ask: "How does this vary across cases?"
  2. List variations: Document different implementations for each commonality.
  3. Document as matrix COLUMNS: Each column is a variation.
  4. Optional: Add "Future Variations" column for anticipated changes.

Example (continuing Payment Processing):

Commonality: Validate payment amount

Variations:
- Credit Card: Check card limit, validate CVV
- PayPal: Check PayPal balance, validate account status
- Bank Transfer: Check account balance, validate routing number

Commonality: Authorize transaction

Variations:
- Credit Card: Contact card issuer API
- PayPal: OAuth flow with PayPal
- Bank Transfer: ACH authorization

Verification:

Failure Handling: If all variability (no commonality), design may be too broad. Narrow scope or reconsider.


Phase 3: Build CVA Matrix

Purpose: Create visual artifact showing commonality × variability relationships. Makes implicit design explicit for team discussion.

Steps:

  1. Create Markdown table: Commonalities as rows, variabilities as columns
  2. Fill each cell: Concrete implementation for that commonality/variability pair
  3. Highlight patterns: Where cells are identical (sharing opportunity), where they differ (extension point)
  4. Optional: Render the matrix as a Mermaid diagram by hand (a matrix exporter is planned, not yet implemented)

Example Matrix:

| Commonality | Credit Card | PayPal | Bank Transfer |

|-------------|-------------|--------|---------------|

| Validate amount | Check card limit, CVV | Check PayPal balance, account | Check account balance, routing |

| Authorize | Card issuer API | PayPal OAuth | ACH authorization |

| Record | Log to CardTransactionDB | Log to PayPalTransactionDB | Log to BankTransactionDB |

| Handle errors | Card decline codes | PayPal error codes | ACH rejection codes |

Interpretation:

Verification:

Failure Handling: If matrix shows no useful patterns, abstraction may not be beneficial. Document rationale for concrete implementation.


Phase 4: Map to Patterns

Purpose: Translate matrix structure to design patterns. Patterns EMERGE from analysis, not imposed.

Steps:

  1. Read ROWS (commonalities):
  1. Read COLUMNS (variabilities):
  1. Check for multidimensional variability:
  1. Document recommendations:

Example Output:

## Pattern Recommendations

### Primary: Abstract Factory Pattern

**Rationale**: Each payment method (Credit Card, PayPal, Bank Transfer) requires a coherent family of related operations. Matrix columns show consistent product families.

**Implementation**:

public interface IPaymentFactory {

IAmountValidator CreateValidator();

ITransactionAuthorizer CreateAuthorizer();

ITransactionRecorder CreateRecorder();

IErrorHandler CreateErrorHandler();

}

public class CreditCardPaymentFactory : IPaymentFactory {

// Concrete implementations from "Credit Card" column

}


**Alternative**: Strategy pattern per row (4 separate strategies). Rejected because operations are not independent - they share payment method context. Factory keeps cohesion.

Create ADR stub for architect agent:

# ADR-XXX: Payment Processing Abstraction

## Context
CVA matrix revealed 3 payment methods with 4 common operations, each varying by method.

## Decision
Use Abstract Factory pattern with `IPaymentFactory` per method.

## Rationale
- Matrix columns show coherent product families
- Operations share payment method context (not independent)
- New payment methods extend without modifying existing

## Alternatives Considered
- Strategy per operation: Rejected (operations not independent, loses cohesion)
- No abstraction: Rejected (3 methods with clear variations justify abstraction per YAGNI threshold)

Verification:

Failure Handling: If no patterns fit cleanly, document rationale for concrete implementation. Abstraction may not be warranted yet.


Phase 5: Validation and Handoff

Purpose: Validate abstraction choices and route to appropriate agents for review.

Steps:

  1. Run validation script:

```bash

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/cva-analysis/scripts/validate-cva-matrix.py cva-matrix.md; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

```

  1. Route to decision-critic (if abstraction recommended):

```bash

# Use decision-critic skill to validate abstraction choice

/decision-critic "Validate Abstract Factory pattern for payment processing per CVA analysis"

```

  1. Route to architect agent (for ADR creation):

```text

# Hand off ADR stub to architect agent

Delegate to the architect agent: "Create ADR from CVA analysis stub"

```

  1. Document reassessment triggers:

```markdown

## Reassessment Triggers

Re-run CVA when:

```

Outputs:

Verification:

Failure Handling: If validation fails, return to earlier phase based on issue:


Anti-Patterns

| Anti-Pattern | Why Bad | Example | Instead |

|--------------|---------|---------|---------|

| Pattern-First Design | Violates CVA principle: patterns emerge, not imposed. Leads to wrong abstractions. | Decide "we need Strategy pattern" BEFORE running CVA | Run CVA first. Let matrix reveal pattern. If no pattern emerges, abstraction may not be needed. |

| Forcing Abstractions | Creates complexity without benefit. Worse than no abstraction per CLAUDE.md. | CVA shows no variability, but create Strategy anyway "for future" | When CVA shows no variability, explicitly document decision NOT to abstract. Revisit when variability emerges. |

| Skipping Matrix Visualization | Loses pedagogical and collaborative benefits. Matrix makes assumptions explicit. | Identify commonalities/variabilities mentally, skip matrix, jump to pattern | Always create visual matrix (Markdown table minimum). Use for team review, ADR rationale. |

| Analysis Paralysis | CVA is a tool, not an end. Over-analysis wastes time. | Spend 3 hours on CVA for 2 simple use cases | Use tiered approach: Quick (15 min) for simple, Standard (30 min) moderate, Deep (60 min) architectural. Set timer. |

| Ignoring Temporal Dimension | Today's constant may be tomorrow's variable. | CVA assumes "currency" constant (USD only). 6 months later, need multi-currency. | Include "Future Variations" column for anticipated changes. Balance YAGNI with known roadmap. |

| Using CVA for Single Use Case | CVA requires 2+ cases to identify commonality/variability. | Run CVA on payment before any other transaction exists | Wait for 2nd use case (YAGNI), OR document anticipated cases with stakeholder validation. |

Integration with Other Skills

architect Agent

CVA produces ADR stub with pattern rationale. Architect agent creates formal ADR.

Handoff Protocol:

Delegate to the architect agent: "Create ADR from CVA analysis at cva-payment-processing.md"

decision-critic Skill

Validates abstraction choices discovered via CVA. Applies inversion thinking to pattern recommendation.

Usage:

/decision-critic "Validate Abstract Factory pattern for payment processing per CVA matrix"

independent-thinker Agent

Challenges whether abstraction is needed at all. Use when CVA is borderline (minimal variability).

Usage:

Delegate to the independent-thinker agent: "Challenge whether payment abstraction is justified given only 2 current methods"

Verification Checklist

After completing CVA:

Reassessment Triggers

Re-run CVA when:

  1. 3+ new use cases added (may reveal new patterns or invalidate current abstraction)
  2. Major architectural shift (e.g., monolith → microservices)
  3. Performance issues with current abstraction (overhead not justified)
  4. Team feedback: Abstraction is too complex, not pulling weight, or forcing designs
  5. Quarterly review (align with retrospective cycle)

Tiered Depth Levels

Choose depth based on decision impact:

| Tier | Time | Use Cases | When to Use |

|------|------|-----------|-------------|

| Quick | 15 min | 2-3 | Simple decisions, clear patterns, low risk |

| Standard | 30 min | 3-5 | Moderate complexity, some uncertainty, medium risk |

| Deep | 60 min | 6+ | Architectural decisions, high uncertainty, high risk |

Time-boxing: Set timer, commit to best-available analysis when time expires. CVA is a tool, not a perfectionist exercise.

.NET Examples

See references/matrix-building-examples.md for complete .NET examples:

References

Scripts

validate-cva-matrix.py

Check CVA matrix completeness and suggest patterns.

Usage:

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/cva-analysis/scripts/validate-cva-matrix.py cva-matrix.md; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

Exit Codes:

Planned scripts (not yet implemented)

Two helpers are designed in references/SKILL_SPEC.md but not yet built. Create the matrix and any diagram by hand until they ship; do not invoke them.

Extension Points

  1. Pattern Mapping: Add new pattern types beyond Strategy/Abstract Factory
  1. Matrix Formats: Add export formats beyond Markdown
  1. Multidimensional Analysis: Handle complex cases with 3+ axes
  1. AI Integration: Automated pattern suggestion
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.