К основному содержанию
скилл CX Codex

component-common-domain-detection — скилл для Claude Code

Скилл component-common-domain-detection ищет бизнес-логику, которая повторяется в нескольких компонентах, и предлагает, что свести в общий сервис, библиотеку или один компонент.

MIT ★ 7 191 обновлён 2026-10-24

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add tech-leads-club/agent-skills --skill component-common-domain-detection -a claude-code
Открыть на GitHub

Что делает component-common-domain-detection

Скилл проходит по кодовой базе и ищет бизнес-логику, которая повторяется в разных компонентах. Сначала он собирает компоненты с одинаковым последним сегментом namespace (*.notification, *.audit, *.validation), потом смотрит импорты и находит классы, которые тянут к себе два и более компонента. Инфраструктуру вроде логгера, конфига или подключения к базе он отсеивает: код общий, но сводить его здесь не предлагают.

Дальше идёт разбор по шагам: что именно делает каждый компонент, насколько отличия мелкие и настраиваемые, как изменится coupling после объединения. На выходе — вариант действий: общий сервис, общая библиотека или слияние компонентов. Сервис советуют для логики, которая часто меняется, библиотеку для устойчивых утилит.

Границы жёсткие. Копипаст внутри файлов и на уровне строк этот скилл не ищет, для этого есть линтеры, а анализ зависимостей отдан соседнему coupling-analysis — если запустить оба, выводы частично пересекутся. Namespace-шаблоны *.util, *.helper и *.common отфильтрованы намеренно, так что чистые утилиты в отчёт не попадут.

Какие задачи решает

  • найти компоненты, которые повторяют логику уведомлений
  • выяснить, какие классы тянут сразу несколько сервисов
  • оценить, как объединение компонентов ударит по связности
  • отделить доменную логику от инфраструктурной перед рефакторингом
  • выбрать между общим сервисом и общей библиотекой

Примеры запросов агенту

  • Найди общую доменную функциональность в компонентах сервиса заказов
  • Покажи классы, которые используются в нескольких компонентах, и скажи, что стоит вынести в библиотеку
  • У нас три компонента с уведомлениями — оцени, что даст их объединение

Как установить component-common-domain-detection

1Через Skills CLI (Vercel)

npx skills add tech-leads-club/agent-skills --skill component-common-domain-detection -a claude-code

2Вручную: положить файлы

~/.claude/skills/component-common-domain-detection/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/component-common-domain-detection/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о component-common-domain-detection

Как установить component-common-domain-detection в Claude Code?

Выполните npx skills add tech-leads-club/agent-skills --skill component-common-domain-detection -a claude-code. Файл скилла появится по пути ~/.claude/skills/component-common-domain-detection/SKILL.md.

Что делает component-common-domain-detection?

Ищет доменную логику, повторяющуюся в нескольких компонентах, и предлагает свести её в общий сервис, библиотеку или один компонент, с оценкой влияния на связность.

Чем он отличается от линтера и скилла coupling-analysis?

Линтеры ловят дубли на уровне кода, а этот скилл работает с доменной логикой на уровне компонентов. Анализ зависимостей вынесен в отдельный coupling-analysis, поэтому их выводы могут пересекаться.

Исходный текст

SKILL.md · MIT
---
name: component-common-domain-detection
description: Finds duplicate business logic spread across multiple components and suggests consolidation. Use when asking "where is this logic duplicated?", "find common code between services", "what can be consolidated?", "detect shared domain logic", or analyzing component overlap before refactoring. Do NOT use for code-level duplication detection (use linters) or dependency analysis (use coupling-analysis).
---

# 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**

```
User: "Find common domain functionality across components"

The skill will:
1. Scan component namespaces for common patterns
2. Detect shared classes used across components
3. Identify duplicate domain logic
4. Analyze coupling impact of consolidation
5. Suggest consolidation opportunities
```

**Example 2: Detect Duplicate Notification Logic**

```
User: "Are there multiple notification components that should be consolidated?"

The skill will:
1. Find all components with notification-related names
2. Analyze their functionality and dependencies
3. Calculate coupling impact if consolidated
4. Recommend consolidation approach
```

**Example 3: Analyze Shared Classes**

```
User: "Find classes that are shared across multiple components"

The skill will:
1. Identify classes imported/used by multiple components
2. Classify as domain vs infrastructure functionality
3. Suggest consolidation or shared library approach
4. Assess impact on coupling
```

### Step-by-Step Process

1. **Scan Components**: Identify components with common namespace patterns
2. **Detect Shared Code**: Find classes/files used across components
3. **Analyze Functionality**: Determine if functionality is truly common
4. **Assess Coupling**: Calculate coupling impact before consolidation
5. **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:

1. **Namespace Patterns**: Components ending in same leaf node
   - `*.notification`, `*.audit`, `*.validation`, `*.formatting`
   - Example: `TicketNotification`, `BillingNotification`, `SurveyNotification`

2. **Shared Classes**: Same class used across multiple components
   - Example: `SMTPConnection` used by 5 different components
   - Example: `AuditLogger` used by multiple domain components

3. **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:

1. **Extract leaf nodes** from all component namespaces
   - Example: `services/billing/notification` → `notification`
   - Example: `services/ticket/notification` → `notification`

2. **Group by common leaf nodes**
   - Find components with same leaf node name
   - Example: All components ending in `.notification`

3. **Filter out infrastructure patterns**
   - Exclude: `.util`, `.helper`, `.common` (usually infrastructure)
   - Focus on: `.notification`, `.audit`, `.validation`, `.formatting`

**Example Output**:

```markdown
## Common Namespace Patterns Found

**Notification Components**:

- services/customer/notification
- services/ticket/notification
- services/survey/notification

**Audit Components**:

- services/billing/audit
- services/ticket/audit
- services/survey/audit
```

### Phase 2: Detect Shared Classes

Find classes/files used across multiple components:

1. **Scan imports/dependencies** in each component
   - Track which classes are imported from where
   - Note classes used by multiple components

2. **Identify shared classes**
   - Classes imported by 2+ components
   - Exclude infrastructure classes (Logger, Config, etc.)

3. **Classify as domain vs infrastructure**
   - Domain: Business logic classes (SMTPConnection, AuditLogger)
   - Infrastructure: Technical utilities (Logger, DatabaseConnection)

**Example Output**:

```markdown
## Shared Classes Found

**Domain Classes**:

- `SMTPConnection` - Used by 5 components (notification-related)
- `AuditLogger` - Used by 8 components (audit-related)
- `DataFormatter` - Used by 3 components (formatting-related)

**Infrastructure Classes** (exclude from consolidation):

- `Logger` - Used by all components (infrastructure)
- `Config` - Used by all components (infrastructure)
```

### Phase 3: Analyze Functionality Similarity

For each group of common components:

1. **Examine functionality**
   - Read source code of each component
   - Identify what each component does
   - Note similarities and differences

2. **Assess consolidation feasibility**
   - Are differences minor (configurable)?
   - Can differences be abstracted?
   - Is functionality truly the same?

3. **Calculate coupling impact**
   - Count incoming dependencies (afferent coupling) before consolidation
   - Estimate incoming dependencies after consolidation
   - Compare total coupling levels

**Example Analysis**:

```markdown
## Functionality Analysis

**Notification Components**:

- CustomerNotification: Sends billing notifications
- TicketNotification: Sends ticket assignment notifications
- SurveyNotification: Sends survey emails

**Similarities**: All send emails to customers
**Differences**: Email content/templates, triggers

**Consolidation Feasibility**: ✅ High

- Differences are in content, not mechanism
- Can be abstracted with templates/context
```

### Phase 4: Assess Coupling Impact

Before recommending consolidation, analyze coupling:

1. **Calculate current coupling**
   - Count components using each notification component
   - Sum total incoming dependencies

2. **Estimate consolidated coupling**
   - Count components that would use consolidated component
   - Compare to current total

3. **Evaluate coupling increase**
   - Is consolidated component too coupled?
   - Does it create a bottleneck?
   - Is coupling increase acceptable?

**Example Coupling Analysis**:

```markdown
## Coupling Impact Analysis

**Before Consolidation**:

- CustomerNotification: Used by 2 components (CA = 2)
- TicketNotification: Used by 2 components (CA = 2)
- SurveyNotification: Used by 1 component (CA = 1)
- **Total CA**: 5

**After Consolidation**:

- Notification: Used by 5 components (CA = 5)
- **Total CA**: 5 (same!)

**Verdict**: ✅ No coupling increase, safe to consolidate
```

### 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

```markdown
## Common Domain Components Found

### Notification Functionality

**Components**:

- services/customer/notification (2% - 1,433 statements)
- services/ticket/notification (2% - 1,765 statements)
- services/survey/notification (2% - 1,299 statements)

**Shared Classes**: SMTPConnection (used by all 3)

**Functionality Analysis**:

- All send emails to customers
- Differences: Content/templates, triggers
- Consolidation Feasibility: ✅ High

**Coupling Analysis**:

- Before: CA = 2 + 2 + 1 = 5
- After: CA = 5 (no increase)
- Verdict: ✅ Safe to consolidate

**Recommendation**: Consolidate into `services/notification`

- Approach: Shared Service
- Expected Size: ~4,500 statements (5% of codebase)
- Benefits: Reduced duplication, easier maintenance
```

### Consolidation Opportunities Table

```markdown
## Consolidation Opportunities

| Common Functionality | Components   | Current CA | After CA | Feasibility | Recommendation                |
| -------------------- | ------------ | ---------- | -------- | ----------- | ----------------------------- |
| Notification         | 3 components | 5          | 5        | ✅ High     | Consolidate to shared service |
| Audit                | 3 components | 8          | 12       | ⚠️ Medium   | Consolidate, monitor coupling |
| Validation           | 2 components | 3          | 3        | ✅ High     | Consolidate to shared library |
```

### Detailed Consolidation Plan

```markdown
## Consolidation Plan

### Priority: High

**Notification Components** → `services/notification`

**Steps**:

1. Create new `services/notification` component
2. Move common functionality from 3 components
3. Create abstraction for content/templates
4. Update dependent components to use new service
5. Remove old notification components

**Expected Impact**:

- Reduced code: ~4,500 statements consolidated
- Reduced duplication: 3 components → 1
- Coupling: No increase (CA stays at 5)
- Maintenance: Easier to maintain single component

### Priority: Medium

**Audit Components** → `services/audit`

**Steps**:
[Similar format]

**Expected Impact**:

- Coupling increase: CA 8 → 12 (monitor)
- Benefits: Reduced duplication
```

## 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:

```
services/
├── CustomerService/
│   └── notification.js      ← Common pattern
├── TicketService/
│   └── notification.js     ← Common pattern
└── SurveyService/
    └── notification.js      ← Common pattern
```

**Shared Classes**:

- Check `require()` statements
- Look for classes imported from other components
- Example: `const SMTPConnection = require('../shared/SMTPConnection')`

### For Java Applications

Common patterns:

```
com.company.billing.audit     ← Common pattern
com.company.ticket.audit      ← Common pattern
com.company.survey.audit      ← Common pattern
```

**Shared Classes**:

- Check `import` statements
- Look for classes in common packages
- Example: `import com.company.shared.AuditLogger`

### Detection Strategies

**Namespace Pattern Detection**:

```javascript
// Extract leaf nodes from namespaces
function extractLeafNode(namespace) {
  const parts = namespace.split('/')
  return parts[parts.length - 1]
}

// Group by common leaf nodes
function groupByLeafNode(components) {
  const groups = {}
  components.forEach((comp) => {
    const leaf = extractLeafNode(comp.namespace)
    if (!groups[leaf]) groups[leaf] = []
    groups[leaf].push(comp)
  })
  return groups
}
```

**Shared Class Detection**:

```javascript
// Find classes used by multiple components
function findSharedClasses(components) {
  const classUsage = {}
  components.forEach((comp) => {
    comp.imports.forEach((imp) => {
      if (!classUsage[imp]) classUsage[imp] = []
      classUsage[imp].push(comp.name)
    })
  })

  return Object.entries(classUsage)
    .filter(([cls, users]) => users.length > 1)
    .map(([cls, users]) => ({ class: cls, usedBy: users }))
}
```

## Fitness Functions

After identifying common components, create automated checks:

### Common Namespace Pattern Detection

```javascript
// Alert if new components with common patterns are created
function checkCommonPatterns(components, exclusionList = []) {
  const leafNodes = {}
  components.forEach((comp) => {
    const leaf = extractLeafNode(comp.namespace)
    if (!exclusionList.includes(leaf)) {
      if (!leafNodes[leaf]) leafNodes[leaf] = []
      leafNodes[leaf].push(comp.name)
    }
  })

  return Object.entries(leafNodes)
    .filter(([leaf, comps]) => comps.length > 1)
    .map(([leaf, comps]) => ({
      pattern: leaf,
      components: comps,
      suggestion: 'Consider consolidating these components',
    }))
}
```

### Shared Class Usage Alert

```javascript
// Alert if class is used by multiple components
function checkSharedClasses(components, exclusionList = []) {
  const classUsage = {}
  components.forEach((comp) => {
    comp.imports.forEach((imp) => {
      if (!exclusionList.includes(imp)) {
        if (!classUsage[imp]) classUsage[imp] = []
        classUsage[imp].push(comp.name)
      }
    })
  })

  return Object.entries(classUsage)
    .filter(([cls, users]) => users.length > 1)
    .map(([cls, users]) => ({
      class: cls,
      usedBy: users,
      suggestion: 'Consider extracting to shared component or library',
    }))
}
```

## 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:

1. **Apply Flatten Components Pattern** - Remove orphaned classes
2. **Apply Determine Component Dependencies Pattern** - Analyze coupling
3. **Create Component Domains** - Group components into domains
4. **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

© tech-leads-club · MIT · tech-leads-club/agent-skills

Похожие скиллы

Все скиллы по теме «Код-ревью и рефакторинг» →
code-modularization-evaluator dotneet Скилл code-modularization-evaluator разбирает связи между модулями по Balanced Coupling Model и подсказывает, что переписать. Пригодится при ревью архитектуры и разбиении монолита. CX Codex +1 462установок domain-model-boundaries-mapper patricio0312rev Скилл domain-model-boundaries-mapper анализирует архитектуру проекта по принципам Domain-Driven Design: находит доменные модули, границы ответственности и зависимости. Помогает спланировать разделение связанных компонентов. CX Codex +1 270установок domain-architect pproenca Скилл domain-architect определяет бизнес-домены в Swift-проекте через возможности продукта, а не через имена папок. Строит карту слоёв каждого домена — от типов до UI. CX Codex +1 249установок pattern-detection Rudolf S. Скилл pattern-detection находит правила именования, архитектурные слои и форматы тестов в проекте. Помогает писать новый код в едином стиле кодовой базы. CX Codex +1 ★ 587звёзд репо domain-driven-design wondelai Скилл domain-driven-design для Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI и OpenCode: учит агента строить модель по бизнес-домену через bounded contexts, агрегаты и ubiquitous language. CX Codex +1 7 700установок principle-model-the-domain backnotprop Скилл principle-model-the-domain для Claude Code моделирует состояние и правила предметной области, когда логика разрастается ветвлениями между файлами. CX Codex +1 10 200установок

Из того же набора130

Весь набор →
harness-eval Скилл harness-eval для Claude Code. Проверяет инструкции и скиллы в репозитории на битые пути, повторы и практическую пользу — до ручной правки harness. CX Codex +1 ★ 7 191звёзд репо multi-platform-launch Скилл multi-platform-launch для Claude Code помогает спланировать запуск продукта на нескольких площадках. Он включается при запросах о Product Hunt, листе ожидания, бета-запуске или стратегии продвижения по каналам. CX Codex +1 ★ 7 191звёзд репо coupling-analysis Скилл coupling-analysis оценивает архитектурную связность модулей по силе интеграции, дистанции и частоте изменений. Помогает понять, какие зависимости рискованны и где нарушена связность. CX Codex +1 ★ 7 191звёзд репо partner-affiliate Скилл partner-affiliate помогает спроектировать партнёрскую и реферальную программу: уровни, комиссии, интеграционные партнёры. Срабатывает на вопросы про реселлеров и долю выручки. CX Codex +1 ★ 7 191звёзд репо ai-sdr Скилл ai-sdr помогает спроектировать и запустить автономных AI-агентов для продаж, настроить квалификацию лидов и выбрать стек инструментов. CX Codex +1 ★ 7 191звёзд репо component-flattening-analysis Скилл component-flattening-analysis для Claude Code находит классы не на своём уровне и помогает выстроить плоскую иерархию компонентов. Разбирает корневые пространства имён. CX Codex +1 ★ 7 191звёзд репо the-jury Скилл the-jury собирает панель из 3–5 субагентов: они дают слепые независимые мнения, совещаются анонимно и выносят один вердикт с уверенностью и следующим шагом. CX Codex +1 ★ 7 191звёзд репо gtm-engineering Скилл gtm-engineering проектирует автоматизацию GTM, интеграции API и пайплайны лидогенерации для Claude Code. Помогает RevOps и инженерам строить инфраструктуру вместо хаоса инструментов. CX Codex +1 ★ 7 191звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой