Logo Design Smell Detector

Design Smell Detector

Cộng đồng
ArabelaTso
design-smell-detector

Identify design quality issues in code including high coupling, low cohesion, God classes, long methods, and other code smells. Use when: (1) Reviewing code architecture and design quality, (2) Identifying refactoring opportunities, (3) Detecting God classes or classes with too many responsibilities, (4) Finding high coupling or low cohesion issues, (5) Analyzing code maintainability and technical debt. Detects coupling smells, cohesion problems, complexity issues, size violations, and encapsulation problems with actionable refactoring suggestions.

Tổng quan

Nhà phát hànhArabelaTso
Kho mãSkills-4-SE
Tên kỹ năngdesign-smell-detector
Sao
258
Bản fork
25
Tệp đi kèm
3
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 3 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được ArabelaTso công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Design Smell Detector trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/design-smell-detector
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE.git /tmp/Skills-4-SE
mkdir -p .claude/skills
cp -r /tmp/Skills-4-SE/skills/design-smell-detector .claude/skills/design-smell-detector
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Design Smell Detector trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Design Smell Detector ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Design Smell Detector với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Design Smell Detector

Identify and address design quality issues in code through automated smell detection and refactoring guidance.

Quick Start

Detect Design Smells

bash
# Analyze a single file
python scripts/detect_smells.py src/app.py

# Analyze entire directory
python scripts/detect_smells.py src/

# Output as JSON
python scripts/detect_smells.py src/ --format json

Example Output

Found 5 design smell(s): 1 critical, 3 major, 1 minor

CRITICAL ISSUES:
  🔴 src/services.py:45 - God Class
     Class 'UserManager' has 25 methods (threshold: 20)
     💡 Split into multiple smaller, focused classes

MAJOR ISSUES:
  🟠 src/models.py:120 - Low Cohesion
     Class 'Order' has low cohesion (score: 0.25)
     💡 Group related methods/attributes or split class

  🟠 src/utils.py:89 - Long Method
     Method 'process_order' has 67 lines (threshold: 50)
     💡 Extract smaller methods or refactor

Design Smells Detected

Coupling Smells

High Coupling: Too many dependencies

  • Module imports > 20
  • Constructor dependencies > 10
  • Changes cascade across classes

Feature Envy: Method uses other class more than own

  • External access > internal access
  • Method should move to envied class

Inappropriate Intimacy: Classes too tightly coupled

  • Accessing private fields of other classes
  • Excessive use of getters/setters

Cohesion Smells

Low Cohesion: Class members unrelated

  • LCOM (Lack of Cohesion) > 0.7
  • Methods don't share instance variables
  • Class has multiple responsibilities

God Class: Class knows/does too much

  • Methods > 20
  • Attributes > 15
  • Lines of code > 500

Complexity Smells

High Cyclomatic Complexity: Too many decision points

  • Complexity > 10
  • Deeply nested conditionals
  • Many if/else, loops

Long Method: Method too long

  • Lines of code > 50
  • Multiple responsibilities
  • Hard to understand

Size Smells

Long Parameter List: Too many parameters

  • Parameters > 5
  • Related parameters not grouped
  • Method signature hard to understand

Large Module: Module too large

  • Classes > 20
  • Lines of code > 1000
  • Multiple responsibilities

Encapsulation Smells

Data Class: Only data, no behavior

  • Only getters/setters
  • No business logic
  • Missing encapsulation

Exposed Internal State: Implementation details exposed

  • Public mutable fields
  • Returns references to internal collections
  • Breaks encapsulation

Detection Workflow

1. Run Detection

Analyze codebase for design smells:

bash
python scripts/detect_smells.py src/

2. Review Results

Examine detected smells by severity:

  • Critical: God classes, severe coupling issues
  • Major: Low cohesion, long methods, high complexity
  • Minor: Long parameter lists, feature envy

3. Prioritize Refactoring

Focus on:

  • Critical issues first
  • Frequently changed code
  • High-impact, low-effort improvements

4. Apply Refactoring

Use refactoring strategies based on smell type.

See refactoring_strategies.md for detailed solutions.

5. Verify Improvements

Re-run detection to measure progress:

bash
python scripts/detect_smells.py src/

Compare metrics before/after.

Common Design Smells

God Class

Symptoms:

  • Too many methods (>20)
  • Too many attributes (>15)
  • Low cohesion
  • Multiple responsibilities

Example:

python
# ❌ God Class
class Application:
    # 30+ methods handling:
    # - User management
    # - Order processing
    # - Payment handling
    # - Reporting
    # - Email notifications
    # - File operations
    pass

Refactoring:

python
# ✅ Split by responsibility
class UserManager:
    pass

class OrderProcessor:
    pass

class PaymentHandler:
    pass

class ReportGenerator:
    pass

High Coupling

Symptoms:

  • Too many imports (>20)
  • Too many constructor dependencies
  • Changes cascade across classes

Example:

python
# ❌ High coupling
class UserService:
    def __init__(self):
        self.db = Database()
        self.cache = Cache()
        self.logger = Logger()
        self.validator = Validator()
        self.email = EmailService()
        self.sms = SMSService()
        # ... many more

Refactoring:

python
# ✅ Dependency injection
class UserService:
    def __init__(self, db, logger, notifier):
        self.db = db
        self.logger = logger
        self.notifier = notifier  # Abstraction

Low Cohesion

Symptoms:

  • Methods don't share attributes
  • Class does unrelated things
  • LCOM score > 0.7

Example:

python
# ❌ Low cohesion
class UserManager:
    def create_user(self):
        pass

    def send_email(self):
        pass

    def log_activity(self):
        pass

    def calculate_discount(self):
        pass

Refactoring:

python
# ✅ High cohesion - focused classes
class UserRepository:
    def create_user(self):
        pass

class EmailService:
    def send_email(self):
        pass

class ActivityLogger:
    def log_activity(self):
        pass

Long Method

Symptoms:

  • Method > 50 lines
  • Multiple responsibilities
  • Hard to understand

Example:

python
# ❌ Long method (100+ lines)
def process_order(order):
    # Validate (20 lines)
    # Calculate price (15 lines)
    # Save to DB (10 lines)
    # Send email (20 lines)
    # Update stats (10 lines)
    # Log activity (15 lines)
    pass

Refactoring:

python
# ✅ Extract methods
def process_order(order):
    validate_order(order)
    total = calculate_total(order)
    save_order(order, total)
    send_confirmation(order)
    update_statistics()
    log_activity(order)

Refactoring Strategies

Reduce Coupling

Dependency Injection:

python
# Inject dependencies instead of creating them
class OrderService:
    def __init__(self, db, logger):
        self.db = db
        self.logger = logger

Interface Abstraction:

python
# Depend on abstractions, not implementations
from abc import ABC, abstractmethod

class PaymentGateway(ABC):
    @abstractmethod
    def charge(self, amount):
        pass

class PaymentProcessor:
    def __init__(self, gateway: PaymentGateway):
        self.gateway = gateway

Improve Cohesion

Extract Class:

python
# Split into focused classes
class User:
    # User data and behavior

class UserRepository:
    # Database operations

class EmailService:
    # Email operations

Move Method:

python
# Move method to appropriate class
class Account:
    def get_formatted_balance(self):  # Moved from reporter
        return f"${self.balance:.2f}"

Reduce Complexity

Extract Method:

python
# Break complex method into smaller ones
def process_order(order):
    validate_order(order)
    calculate_total(order)
    save_order(order)

Replace Conditional with Polymorphism:

python
# Use inheritance instead of conditionals
class Customer:
    def calculate_price(self, base_price):
        return base_price

class PremiumCustomer(Customer):
    def calculate_price(self, base_price):
        return base_price * 0.9

For comprehensive refactoring strategies, see refactoring_strategies.md.

Metrics and Thresholds

Detection Thresholds

SmellMetricThreshold
God ClassMethods> 20
God ClassAttributes> 15
God ClassLOC> 500
High CouplingImports> 20
Low CohesionLCOM> 0.7
Long MethodLOC> 50
High ComplexityCyclomatic> 10
Long Parameter ListParameters> 5

Key Metrics

LCOM (Lack of Cohesion of Methods):

  • Measures how methods share instance variables
  • Range: 0.0 (high cohesion) to 1.0 (low cohesion)
  • Lower is better

Cyclomatic Complexity:

  • Number of linearly independent paths
  • Each if/while/for adds 1
  • Lower is better (< 10)

Fan-out (Coupling):

  • Number of dependencies
  • Lower is better (< 10)

Design Smell Catalog

For complete descriptions, examples, and solutions for all design smells, see smell_catalog.md.

Includes:

  • Coupling Smells: High coupling, Feature Envy, Inappropriate Intimacy
  • Cohesion Smells: Low cohesion, God Class
  • Complexity Smells: High complexity, Long Method
  • Size Smells: Long Parameter List, Large Module
  • Encapsulation Smells: Data Class, Exposed Internal State

Best Practices

1. Detect Regularly

Integrate into workflow:

bash
# Pre-commit hook
python scripts/detect_smells.py src/

# CI/CD pipeline
make check-design-smells

2. Track Metrics Over Time

Monitor trends:

Sprint 1: 15 God classes, 45 long methods
Sprint 2: 12 God classes, 38 long methods
Sprint 3: 8 God classes, 25 long methods

3. Prioritize Strategically

Focus on:

  • Code changed frequently
  • Critical business logic
  • High-impact areas

4. Refactor Incrementally

  • Small, safe changes
  • Run tests after each change
  • Commit frequently

5. Measure Improvements

Before/after metrics:

Before: LCOM = 0.85 (low cohesion)
After:  LCOM = 0.25 (high cohesion)

Common Scenarios

Scenario 1: Legacy Codebase Modernization

Goal: Identify technical debt in legacy system

Approach:

  1. Run smell detection on entire codebase
  2. Generate metrics report
  3. Identify top 10 worst files
  4. Create refactoring backlog
  5. Tackle incrementally

Scenario 2: Code Review Enhancement

Goal: Automated design quality checks in PR reviews

Approach:

  1. Add smell detection to CI pipeline
  2. Fail build if critical smells introduced
  3. Report metrics in PR comments
  4. Require fixes before merge

Scenario 3: Architecture Assessment

Goal: Evaluate system architecture quality

Approach:

  1. Detect coupling and cohesion issues
  2. Identify God classes and large modules
  3. Analyze dependency structure
  4. Recommend architectural improvements

Integration with Development Workflow

Pre-commit Hook

bash
#!/bin/bash
# .git/hooks/pre-commit

python scripts/detect_smells.py src/
if [ $? -ne 0 ]; then
    echo "Critical design smells detected. Commit aborted."
    exit 1
fi

CI/CD Pipeline

yaml
# .github/workflows/quality.yml
name: Design Quality Check

on: [push, pull_request]

jobs:
  check-smells:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Detect design smells
        run: python scripts/detect_smells.py src/

      - name: Upload report
        uses: actions/upload-artifact@v3
        with:
          name: smell-report
          path: smell-report.json

IDE Integration

Most IDEs support similar analysis through plugins:

  • PyCharm: Built-in inspections for coupling/cohesion
  • VS Code: Python linting extensions
  • SonarLint: Real-time smell detection

Troubleshooting

False Positives

Problem: Legitimate design flagged as smell

Solution:

  • Understand context and constraints
  • Consider if threshold should be adjusted
  • Document reasons for exception

Overwhelming Results

Problem: Too many smells to address

Solution:

  • Filter by severity (critical first)
  • Focus on frequently changed code
  • Set incremental goals

Refactoring Breaks Tests

Problem: Tests fail after refactoring

Solution:

  • Ensure comprehensive test coverage first
  • Refactor incrementally
  • Run tests after each small change

Reference Documentation

Design Smell Catalog

See smell_catalog.md for:

  • Complete smell definitions
  • Detection criteria and thresholds
  • Code examples (before/after)
  • Metrics explanations (LCOM, cyclomatic complexity, fan-out)
  • All coupling, cohesion, complexity, size, and encapsulation smells

Refactoring Strategies

See refactoring_strategies.md for:

  • Coupling reduction strategies (DI, interfaces, facades)
  • Cohesion improvement (extract class, move method)
  • Complexity reduction (extract method, polymorphism)
  • Size reduction (split classes, parameter objects)
  • Encapsulation improvement
  • Refactoring workflow and best practices
  • Anti-patterns to avoid
  • Success metrics

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Design Smell Detector làm được gì?

Identify design quality issues in code including high coupling, low cohesion, God classes, long methods, and other code smells. Use when: (1) Reviewing code architecture and design quality, (2) Identifying refactoring opportunities, (3) Detecting God classes or classes with too many responsibilities, (4) Finding high coupling or low cohesion issues, (5) Analyzing code maintainability and technical debt. Detects coupling smells, cohesion problems, complexity issues, size violations, and encapsulation problems with actionable refactoring suggestions.

Vì sao nên dùng Design Smell Detector trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Design Smell Detector là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Design Smell Detector trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/design-smell-detector. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Design Smell Detector?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Design Smell Detector với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Design Smell Detector với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Design Smell Detector có miễn phí không?

Có. Kỹ năng này được ArabelaTso phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇