Code Modularization Evaluator

作者 dotneet07fa7eac95c2無授權條款3 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫8 個月前更新

Evaluate and improve code modularization using the Balanced Coupling Model. Analyzes coupling strength, connascence types, and distance to identify refactoring opportunities and architectural improvements. Use when reviewing code architecture, refactoring modules, or designing new systems.

AI 產生的概覽

使用平衡耦合模型評估程式碼模組化,分析耦合強度、距離、波動性與共生性。

功能
引導代理使用平衡耦合模型評估程式庫的模組化程度,對整合強度、距離和波動性進行分類,並識別共生性類型。它會產出結構化評估,包括元件圖、耦合分析表、共生性問題、依優先順序排列的建議以及重構計畫。它還提供關於共生性類型、耦合量度和重構模式的參考資料。
適用情境
適用於審查程式碼架構、重構模組或設計新系統,並希望取得結構化耦合分析的場景。它適合以架構洞察和重構指引為交付物、而非直接修改程式碼的評估工作。
執行需求
不需要指令碼或工具,僅包含指示和參考文件。它依賴代理能夠存取被評估的程式碼;該技能指出,波動性、團隊距離和歷史變更頻率需要靜態分析之外的背景資訊。

Code Modularization Evaluator

Evaluate code modularization using the Balanced Coupling Model from Vlad Khononov's "Balancing Coupling in Software Design." This skill helps identify problematic coupling patterns and provides actionable refactoring guidance.

Core Principle

Coupling is not inherently bad—misdesigned coupling is bad. The goal is balanced coupling, not zero coupling.

The fundamental formula:

MODULARITY = (STRENGTH XOR DISTANCE) OR NOT VOLATILITY

A system achieves modularity when:

  • High integration strength components are close together (same module/service)
  • Low integration strength components can be far apart (different services)
  • Low volatility components can tolerate coupling mismatches

The Three Dimensions of Coupling

Always evaluate coupling across these three dimensions:

1. Integration Strength (What knowledge is shared?)

From strongest (worst) to weakest (best):

LevelTypeDescriptionExample
1IntrusiveUsing non-public interfacesDirect database access to another service, reflection on private fields
2FunctionalSharing business logic/rulesSame validation duplicated in two places, order-dependent operations
3ModelSharing domain modelsTwo services using identical entity definitions
4ContractOnly explicit interfacesWell-designed APIs, DTOs, protocols

2. Distance (How far does knowledge travel?)

From closest to most distant:

  1. Methods within same class
  2. Classes within same file
  3. Classes in same namespace/package
  4. Modules in different namespaces
  5. Separate services/microservices
  6. Services owned by different teams
  7. Different systems/organizations

3. Volatility (How often will it change?)

Use Domain-Driven Design subdomain classification:

  • Core subdomains: High volatility (competitive advantage, frequent changes)
  • Supporting subdomains: Low volatility (necessary but not differentiating)
  • Generic subdomains: Low volatility (solved problems, stable)

Decision Framework

When evaluating code, apply this matrix:

Integration StrengthDistanceResult
HighHigh❌ COMPLEXITY (Distributed monolith)
LowLow❌ COMPLEXITY (Unnecessary abstraction)
HighLow✅ MODULARITY (Related things together)
LowHigh✅ MODULARITY (Independent components apart)

Exception: If volatility is LOW, coupling mismatches are acceptable.

Connascence Analysis

Use connascence to identify specific coupling types. See references/connascence-types.md for detailed examples.

Static Connascence (Compile-time, easier to fix)

Ordered weakest to strongest:

  1. Name (CoN): Components agree on names
  2. Type (CoT): Components agree on types
  3. Meaning (CoM): Components agree on value meanings (magic numbers)
  4. Position (CoP): Components agree on order of values
  5. Algorithm (CoA): Components share algorithm logic

Dynamic Connascence (Runtime, harder to detect)

Ordered weakest to strongest: 6. Execution (CoE): Order of method calls matters 7. Timing (CoTm): Timing of execution matters 8. Value (CoV): Multiple values must change together 9. Identity (CoI): Must reference same instance

Connascence Rules

  1. Minimize overall connascence
  2. Minimize connascence crossing module boundaries
  3. Maximize connascence within module boundaries
  4. Convert stronger connascence to weaker forms
  5. As distance increases, connascence should weaken

Evaluation Checklist

When analyzing code, check for:

Red Flags (Immediate Action Required)

  • Direct database access to another service's data (Intrusive coupling)
  • Reflection to access private fields
  • Business logic duplicated across services
  • Microservices requiring synchronized deployments
  • CBO (Coupling Between Objects) > 14 for a class
  • Instability index 0.3-0.7 for frequently-changing modules
  • Circular dependencies between modules

Warning Signs (Investigate Further)

  • Magic numbers/values shared between components (CoM)
  • Position-dependent parameters in APIs (CoP)
  • Algorithm logic duplicated in multiple places (CoA)
  • Methods must be called in specific order (CoE)
  • Long method chains: a.b().c().d() (Law of Demeter violation)
  • Classes with "Manager", "Helper", "Utility" doing too much

Healthy Patterns

  • Contract-based integration between services
  • DTOs that truly abstract internal models
  • High cohesion within modules
  • Single responsibility per class
  • Dependency injection for external dependencies

Refactoring Strategies

By Integration Strength Problem

Intrusive → Contract Coupling:

  1. Identify all direct dependencies on implementation details
  2. Define explicit interface/contract
  3. Create adapter layer
  4. Route all access through adapter

Functional → Model Coupling:

  1. Extract shared business logic to dedicated module
  2. Define clear ownership
  3. Consume via explicit dependency

Model → Contract Coupling:

  1. Create integration-specific DTOs
  2. Map between internal models and DTOs at boundaries
  3. Version contracts independently of models

By Connascence Type

FromToTechnique
CoM (Meaning)CoN (Name)Replace magic values with named constants/enums
CoP (Position)CoN (Name)Use named parameters, builder pattern, or parameter objects
CoA (Algorithm)CoN (Name)Extract algorithm to single location, reference by name
CoT (Type)CoN (Name)Use duck typing or interfaces
CoE (Execution)ExplicitUse state machines, builder pattern, or constructor injection
CoI (Identity)ExplicitUse dependency injection with explicit wiring

By Distance Problem

High Strength + High Distance (Distributed Monolith):

  • Option A: Reduce distance—merge services/modules
  • Option B: Reduce strength—introduce contracts, async messaging

Low Strength + Low Distance (Over-abstraction):

  • Remove unnecessary abstraction layers
  • Inline overly generic code
  • Combine closely-related classes

Analysis Workflow

When asked to evaluate code modularization:

  1. Map the component structure

    • Identify modules, services, classes
    • Draw dependency graph
  2. Assess Integration Strength

    • For each dependency, classify: Intrusive/Functional/Model/Contract
    • Flag high-strength cross-boundary dependencies
  3. Measure Distance

    • Note component locations (same file → different systems)
    • Identify team/ownership boundaries
  4. Evaluate Volatility

    • Classify each component's subdomain type
    • Note historically frequently-changed areas
  5. Apply the formula

    • Check: Does strength match distance appropriately?
    • Does volatility excuse any mismatches?
  6. Identify Connascence

    • Scan for specific connascence types
    • Prioritize: high strength + low locality + high degree
  7. Recommend actions

    • Prioritize by impact and effort
    • Provide specific refactoring techniques

Output Format

Structure your evaluation as:

markdown
## Modularization Assessment
### Summary[Brief overview of coupling health]
### Component Map[Describe module/service structure]
### Coupling Analysis| Component Pair | Strength | Distance | Volatility | Balance ||---------------|----------|----------|------------|---------|| A → B         | Model    | High     | High       | ❌      |
### Connascence Issues1. [Specific connascence type]: [Location] - [Impact]
### Recommendations1. **Priority 1**: [Action] - [Rationale]2. **Priority 2**: [Action] - [Rationale]
### Refactoring Plan[Step-by-step approach for highest-priority item]

References

  • For detailed connascence examples: see references/connascence-types.md
  • For coupling metrics: see references/coupling-metrics.md
  • For refactoring patterns: see references/refactoring-patterns.md

Limitations

  • Cannot assess runtime behavior without execution context
  • Volatility assessment requires domain knowledge
  • Team/organizational distance requires project context
  • Historical change frequency not available from static analysis alone

來源與署名

來源:dotneet/claude-code-marketplace位於review-tool/skills/code-modularization-evaluator提交07fa7ea

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架