reducing-coupling
npx machina-cli add skill msewell/agent-stuff/reducing-coupling --openclawReducing Coupling
Workflow
- Clarify scope and goals.
- Read reference files relevant to the scope.
- Analyze the code for coupling.
- Classify and prioritize findings.
- Produce a refactoring plan.
- Present the plan for approval.
- Execute approved refactorings.
Step 1 — Clarify Scope and Goals
Interpret the user's prompt to determine:
- Target scope: which files, directories, modules, or layers to analyze.
- Concern: general coupling audit, or a specific pain point (e.g., "hard to test", "can't deploy independently", "changing X breaks Y").
- Constraints: anything off-limits for modification (public APIs, shared contracts, third-party code).
If the prompt is ambiguous, ask one focused clarifying question before proceeding.
Step 2 — Read Reference Material
Load only the reference files relevant to the analysis context:
| When you need … | Read |
|---|---|
| Coupling vocabulary, taxonomy, Connascence definitions | references/coupling-taxonomy-and-connascence.md |
| Architectural decoupling patterns (Hex, EDA, CQRS, Modular Monolith, DIP) | references/architectural-patterns.md |
| SOLID principles, DI, Adapter, ACL, Strangler Fig | references/design-principles-and-techniques.md |
| Microservices, frontend, or database coupling | references/context-specific-strategies.md |
| Modern trends, common anti-patterns | references/modern-trends-and-anti-patterns.md |
| Decision framework, measurement, refactoring strategy, testing | references/practical-guidelines.md |
Always load coupling-taxonomy-and-connascence.md — it provides the shared vocabulary for the analysis.
Load additional files based on the architectural context you discover.
Step 3 — Analyze the Code
Read the files within the target scope. For each file and across files, look for:
Structural Indicators
- Direct instantiation of concrete dependencies (no DI).
- Imports/references that cross module or layer boundaries.
- Shared mutable state or global variables.
- God classes/modules with many responsibilities.
- Fat interfaces that force clients to depend on methods they don't use.
- Circular dependencies between modules or packages.
Connascence Indicators
- Connascence of Meaning: magic numbers, stringly-typed status codes, implicit conventions.
- Connascence of Position: long positional parameter lists.
- Connascence of Algorithm: duplicated encoding/hashing/serialization logic.
- Connascence of Execution: required call ordering not enforced by types.
- Connascence of Timing: race conditions, hidden sequencing requirements.
- Connascence of Identity: multiple components referencing the same mutable instance.
Architectural Indicators
- Shared database access across module boundaries.
- Synchronous call chains spanning multiple services or modules.
- Anemic domain models with business logic in service layers.
- Tight coupling to frameworks, platforms, or third-party libraries without adapters.
- No separation between domain logic and infrastructure concerns.
Step 4 — Classify and Prioritize
For each coupling issue found, record:
- Location: file(s) and line range(s).
- Coupling type: use Connascence taxonomy or structural category.
- Boundary: whether it is within a module (lower priority) or across modules/layers/services (higher priority).
- Severity: rate as high / medium / low based on:
- Strength of connascence (stronger = worse).
- Degree (how many elements are coupled).
- Locality (cross-boundary = worse).
- Change frequency of the coupled area (frequently-changed = worse).
Sort findings by severity descending.
Step 5 — Produce the Refactoring Plan
For each finding (or group of related findings), propose a concrete refactoring:
Plan Format
Present the plan as a numbered list. For each item include:
### <N>. <Short title>
**Problem**: <1–2 sentence description of the coupling issue>
**Location**: <file paths and line ranges>
**Coupling type**: <Connascence type or structural category>
**Severity**: high | medium | low
**Proposed refactoring**:
<Description of the change, naming the pattern used (e.g., Extract Interface + DI,
Adapter, ACL, Event-Driven, etc.)>
**Before** (sketch):
<Relevant code excerpt showing the current state>
**After** (sketch):
<Concrete code showing the proposed result>
**Trade-offs**:
- <benefit>
- <cost or risk>
Plan Guidelines
- Propose incremental refactorings — each should be independently shippable.
- Prefer converting strong connascence to weaker forms over eliminating coupling entirely.
- Flag when decoupling would be premature (components always change together, abstraction not yet justified).
- Suggest tests to add before or alongside each refactoring to preserve behavior.
- Keep the plan ordered by priority: highest-severity items first.
Step 6 — Present for Approval
Present the complete refactoring plan to the user. Ask which items to execute, or whether to revise any proposals. Do not modify code until the user approves specific items.
If the user approves all items, confirm the execution order (highest priority first).
Step 7 — Execute Approved Refactorings
For each approved item, in priority order:
- Make the code changes as described in the plan.
- After each item, briefly summarize what was changed and which files were modified.
- If a refactoring reveals new coupling issues, note them but do not add unplanned changes — propose them as follow-up items instead.
References
- references/coupling-taxonomy-and-connascence.md
- references/architectural-patterns.md
- references/design-principles-and-techniques.md
- references/context-specific-strategies.md
- references/modern-trends-and-anti-patterns.md
- references/practical-guidelines.md
Source
git clone https://github.com/msewell/agent-stuff/blob/main/skills/reducing-coupling/SKILL.mdView on GitHub Overview
Reduces coupling by analyzing a codebase scope for coupling issues, classifying them with the Connascence taxonomy, and delivering a concrete refactoring plan with code-change suggestions. This helps improve modularity, testability, and long-term maintainability by reducing brittle dependencies.
How This Skill Works
The workflow begins by clarifying scope and goals, then loads reference materials (including coupling taxonomy). It analyzes the codebase for structural, connascence, and architectural indicators, classifies findings by boundary and severity, and outputs a prioritized refactoring plan with concrete changes and an execution path.
When to Use It
- When the codebase shows high coupling across modules and hard-to-test components.
- When you need to reduce dependencies to enable independent deployment.
- When adding features requires changing many modules, increasing risk.
- When you observe Connascence indicators like magic numbers, long parameter lists, or duplicated logic.
- When preparing to modularize a monolith or define clearer module boundaries.
Quick Start
- Step 1: Clarify the target scope, concern, and constraints (files, modules, and non-modifiable contracts).
- Step 2: Read relevant references (coupling taxonomy and patterns) and scan the code for coupling indicators and boundary crossings.
- Step 3: Produce a prioritized refactoring plan with concrete code changes and present it for approval, then execute the approved refactorings.
Best Practices
- Clarify scope, boundaries, and constraints up front to avoid scope creep.
- Load and reference the coupling taxonomy and architectural patterns early in the analysis.
- Systematically identify and categorize coupling using clear Connascence indicators.
- Prioritize findings by boundary impact, severity, and change risk to guide refactoring.
- Ensure refactorings are incremental, well-documented, and validated with tests; seek approval before executing changes.
Example Use Cases
- Decouple a shared utility library from business services by introducing interfaces and dependency injection to reduce execution-time coupling.
- Replace direct instantiation of concrete classes with abstractions to lower Connascence of Meaning and Position.
- Reduce long parameter lists by introducing parameter objects or builder patterns to address Connascence of Position.
- Isolate shared mutable state to prevent Connascence of Identity across modules.
- Apply a Strangler Fig approach to gradually migrate a monolith toward modular boundaries with adapters and facades.
Frequently Asked Questions
Related Skills
creating-c4-diagrams
msewell/agent-stuff
Creates, reviews, and interprets C4 software architecture diagrams (System Context, Container, Component, Dynamic, Deployment). Produces Structurizr DSL or Mermaid diagram code following C4 model best practices. Use when creating architecture diagrams for a system, reviewing existing C4 diagrams for correctness and anti-patterns, generating Structurizr DSL workspaces, producing Mermaid C4 diagrams for READMEs, or using C4 diagrams as context for design decisions, code generation, risk analysis, or onboarding.
arazzo-specification
msewell/agent-stuff
Guides writing, reviewing, and modifying Arazzo workflow specifications (OpenAPI Initiative standard for multi-step API workflows). Use when creating Arazzo documents from scratch, adding steps or workflows to existing specs, reviewing Arazzo files for correctness, or generating API workflow definitions. Covers document structure, runtime expressions, success criteria, control flow, data threading, reusable components, workflow composition, AI agent integration, and validation.
kotlin-functional-programming
msewell/agent-stuff
Guides writing idiomatic, functional-style Kotlin code using built-in language features. Use when asked to write, review, or refactor Kotlin code for immutability, pure functions, sealed types, error handling, collections, coroutines, or functional architecture patterns.
property-based-testing-with-kotest
msewell/agent-stuff
Writes property-based tests using Kotest's kotest-property module. Identifies testable properties, designs generators, and configures PBT for Kotlin/JVM projects. Use when writing property-based tests, creating custom Arb generators, choosing property patterns (roundtrip, invariant, idempotence, oracle), debugging shrunk counterexamples, or integrating PBT into a Kotlin test suite alongside example-based tests.
mermaid-sequence-diagrams
msewell/agent-stuff
Generates, reviews, and fixes Mermaid sequence diagrams following syntax rules and best practices. Use when creating sequence diagrams from system descriptions, reviewing existing Mermaid sequence diagrams for correctness, fixing parse errors, or refactoring large diagrams into focused sub-diagrams. Covers participants, arrows, activations, control flow, notes, styling, and common anti-patterns.
making-invalid-states-unrepresentable
msewell/agent-stuff
Analyzes existing code and guides new type design to make invalid states unrepresentable using type system techniques such as sum types, newtypes, typestate, branded types, and parse-don't-validate. Use when reviewing code for invalid-state bugs, refactoring types to eliminate impossible states, designing domain models, or applying compile-time correctness patterns. Language-agnostic.