Common Domain Component Detection
This skill identifies common domain functionality that is duplicated across multiple components and suggests consolidation opportunities to reduce duplication and improve maintainability.
How to Use
Quick Start
Request analysis of your codebase:
- "Find common domain functionality across components"
- "Identify duplicate domain logic that should be consolidated"
- "Detect shared classes used across multiple components"
- "Analyze consolidation opportunities for common components"
Usage Examples
Example 1: Find Common Functionality
Example 2: Detect Duplicate Notification Logic
Example 3: Analyze Shared Classes
Step-by-Step Process
- Scan Components: Identify components with common namespace patterns
- Detect Shared Code: Find classes/files used across components
- Analyze Functionality: Determine if functionality is truly common
- Assess Coupling: Calculate coupling impact before consolidation
- Recommend Actions: Suggest consolidation or shared library approach
When to Use
Apply this skill when:
- After identifying and sizing components (Pattern 1)
- Before flattening components (Pattern 3)
- When planning to reduce code duplication
- Analyzing shared domain logic across the codebase
- Preparing for component consolidation
- Identifying candidates for shared services or libraries
Core Concepts
Domain vs Infrastructure Functionality
Domain Functionality (candidates for consolidation):
- Business processing logic (notification, validation, auditing, formatting)
- Common to some processes, not all
- Examples: Customer notification, ticket auditing, data validation
Infrastructure Functionality (usually not consolidated here):
- Operational concerns (logging, metrics, security)
- Common to all processes
- Examples: Logging, authentication, database connections
Common Domain Patterns
Common domain functionality often appears as:
-
Namespace Patterns: Components ending in same leaf node
*.notification,*.audit,*.validation,*.formatting- Example:
TicketNotification,BillingNotification,SurveyNotification
-
Shared Classes: Same class used across multiple components
- Example:
SMTPConnectionused by 5 different components - Example:
AuditLoggerused by multiple domain components
- Example:
-
Similar Functionality: Different components doing similar things
- Example: Multiple components sending emails with slight variations
- Example: Multiple components writing audit logs
Consolidation Approaches
Shared Service:
- Common functionality becomes a separate service
- Other components call this service
- Good for: Frequently changing logic, complex operations
Shared Library:
- Common code packaged as library (JAR, DLL, npm package)
- Components import and use the library
- Good for: Stable functionality, simple utilities
Component Consolidation:
- Merge multiple components into one
- Good for: Highly related functionality, low coupling impact
Analysis Process
Phase 1: Identify Common Namespace Patterns
Scan component namespaces for common leaf node names:
-
Extract leaf nodes from all component namespaces
- Example:
services/billing/notification→notification - Example:
services/ticket/notification→notification
- Example:
-
Group by common leaf nodes
- Find components with same leaf node name
- Example: All components ending in
.notification
-
Filter out infrastructure patterns
- Exclude:
.util,.helper,.common(usually infrastructure) - Focus on:
.notification,.audit,.validation,.formatting
- Exclude:
Example Output:
Phase 2: Detect Shared Classes
Find classes/files used across multiple components:
-
Scan imports/dependencies in each component
- Track which classes are imported from where
- Note classes used by multiple components
-
Identify shared classes
- Classes imported by 2+ components
- Exclude infrastructure classes (Logger, Config, etc.)
-
Classify as domain vs infrastructure
- Domain: Business logic classes (SMTPConnection, AuditLogger)
- Infrastructure: Technical utilities (Logger, DatabaseConnection)
Example Output:
Phase 3: Analyze Functionality Similarity
For each group of common components:
-
Examine functionality
- Read source code of each component
- Identify what each component does
- Note similarities and differences
-
Assess consolidation feasibility
- Are differences minor (configurable)?
- Can differences be abstracted?
- Is functionality truly the same?
-
Calculate coupling impact
- Count incoming dependencies (afferent coupling) before consolidation
- Estimate incoming dependencies after consolidation
- Compare total coupling levels
Example Analysis:
Phase 4: Assess Coupling Impact
Before recommending consolidation, analyze coupling:
-
Calculate current coupling
- Count components using each notification component
- Sum total incoming dependencies
-
Estimate consolidated coupling
- Count components that would use consolidated component
- Compare to current total
-
Evaluate coupling increase
- Is consolidated component too coupled?
- Does it create a bottleneck?
- Is coupling increase acceptable?
Example Coupling Analysis:
Phase 5: Recommend Consolidation Approach
Based on analysis, recommend approach:
Shared Service (if):
- Functionality changes frequently
- Complex operations
- Needs independent scaling
- Multiple deployment units will use it
Shared Library (if):
- Stable functionality
- Simple utilities
- Compile-time dependency acceptable
- No need for independent deployment
Component Consolidation (if):
- Highly related functionality
- Low coupling impact
- Same deployment unit acceptable
Output Format
Common Domain Components Report
Consolidation Opportunities Table
Detailed Consolidation Plan
Analysis Checklist
Common Pattern Detection:
- Scanned all component namespaces for common leaf nodes
- Identified components with same ending names
- Filtered out infrastructure patterns
- Grouped similar components
Shared Class Detection:
- Scanned imports/dependencies in each component
- Identified classes used by multiple components
- Classified as domain vs infrastructure
- Documented shared class usage
Functionality Analysis:
- Examined source code of common components
- Identified similarities and differences
- Assessed consolidation feasibility
- Determined if differences can be abstracted
Coupling Assessment:
- Calculated current coupling (CA) for each component
- Estimated consolidated coupling
- Compared total coupling levels
- Evaluated if coupling increase is acceptable
Recommendations:
- Suggested consolidation approach (service/library/merge)
- Prioritized recommendations by impact
- Created consolidation plan with steps
- Estimated expected benefits and risks
Implementation Notes
For Node.js/Express Applications
Common patterns to look for:
Shared Classes:
- Check
require()statements - Look for classes imported from other components
- Example:
const SMTPConnection = require('../shared/SMTPConnection')
For Java Applications
Common patterns:
Shared Classes:
- Check
importstatements - Look for classes in common packages
- Example:
import com.company.shared.AuditLogger
Detection Strategies
Namespace Pattern Detection:
Shared Class Detection:
Fitness Functions
After identifying common components, create automated checks:
Common Namespace Pattern Detection
Shared Class Usage Alert
Best Practices
Do's ✅
- Distinguish domain from infrastructure functionality
- Analyze coupling impact before consolidating
- Consider both shared service and shared library approaches
- Look for namespace patterns AND shared classes
- Verify functionality is truly similar before consolidating
- Calculate coupling metrics (CA) before and after
Don'ts ❌
- Don't consolidate infrastructure functionality (handled separately)
- Don't consolidate without analyzing coupling impact
- Don't assume all common patterns should be consolidated
- Don't ignore differences in functionality
- Don't consolidate if coupling increase is too high
- Don't mix domain and infrastructure in same analysis
Common Patterns to Look For
High Consolidation Candidates
- Notification:
*.notification,*.notify,*.email - Audit:
*.audit,*.auditing,*.log - Validation:
*.validation,*.validate,*.validator - Formatting:
*.format,*.formatter,*.formatting - Reporting:
*.report,*.reporting(if similar functionality)
Low Consolidation Candidates
- Infrastructure:
*.util,*.helper,*.common(usually infrastructure) - Different contexts: Same name, different business meaning
- High coupling risk: Consolidation would create bottleneck
Next Steps
After identifying common domain components:
- Apply Flatten Components Pattern - Remove orphaned classes
- Apply Determine Component Dependencies Pattern - Analyze coupling
- Create Component Domains - Group components into domains
- Plan Consolidation - Execute consolidation recommendations
Notes
- Common domain functionality is different from infrastructure functionality
- Consolidation reduces duplication but may increase coupling
- Always analyze coupling impact before consolidating
- Shared services vs shared libraries have different trade-offs
- Some duplication is acceptable if it reduces coupling
- Not all common patterns should be consolidated


