Design patterns

From saifoelloh/golang-best-practices-skill · View interactive version

Design patterns is an AI agent skill from the GitHub repository saifoelloh/golang-best-practices-skill. Go design patterns and refactoring skill. Use when refactoring complex code, reducing technical debt, or applying design patterns. Detects code smells and suggests pattern-based solutions.

How to use this skill

Skill file

Golang Design Patterns & Refactoring

Expert-level code refactoring and design pattern application for Go. Detects code smells, suggests refactoring strategies, and applies proven design patterns to improve maintainability.

When to Apply

Use this skill when:

Rule Categories by Priority

| Priority | Count | Focus |

|----------|-------|-------|

| High | 2 | Critical refactoring needs |

| Medium | 11 | Code quality improvements |

Rules Covered (13 total)

High-Impact Patterns (2)

Medium Improvements (11)

Common Refactoring Patterns

God Object → Extracted Methods

// ❌ 500 line function
func (u *Usecase) Process() { ... }

// ✅ Extracted methods
func (u *Usecase) Process() {
    u.validate()
    u.transform()
    u.persist()
}

Primitive Obsession → Value Object

// ❌ Primitive types
func CreateUser(email string) { ... }

// ✅ Value object
type Email struct { value string }
func CreateUser(email Email) { ... }

Type Switch → Strategy Pattern

// ❌ Type switch
switch v := val.(type) { ... }

// ✅ Strategy pattern
type Processor interface { Process() }

Trigger Phrases

This skill activates when you say:

How to Use

For Code Refactoring

  1. Identify code smells (God Objects, long parameter lists, etc.)
  2. Apply appropriate refactoring pattern
  3. Verify tests still pass
  4. Check for improved readability

For Pattern Application

  1. Identify appropriate pattern for use case
  2. Apply pattern incrementally
  3. Ensure pattern improves, not complicates code

Output Format

## High Priority Refactoring: X

### [Rule Name] (Line Y)
**Code Smell**: God Object / Long Parameter List / Primitive Obsession
**Impact**: Hard to maintain / Test / Understand
**Refactoring**: Extract Method / Introduce Parameter Object / Create Value Object
**Example**:

// Refactored code

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.