Design patterns
Skill saifoelloh/golang-best-practices-skill/design-patterns
Production-ready Go code review skill for AI agents based on authoritative sources
npx -y skills add saifoelloh/golang-best-practices-skill --skill design-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 16 stars16 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
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.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
4.2 KB, as published. Nobody here has run it
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:
- Refactoring complex or legacy code
- Reducing technical debt
- Extracting reusable patterns
- Simplifying large functions (God Objects)
- Improving code maintainability
- Applying Gang of Four patterns to Go
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)
high-god-object- Extract logic from 300+ line functionshigh-extract-method- Name complex code blocks with descriptive methods
Medium Improvements (11)
medium-primitive-obsession- Replace primitives with value objectsmedium-long-parameter-list- Use parameter objects for >5 paramsmedium-data-clumps- Extract repeated parameter groupsmedium-feature-envy- Move logic closer to datamedium-magic-constants- Replace magic numbers with named constantsmedium-builder-pattern- Fluent API for complex constructionmedium-factory-constructor- Validated object creationmedium-introduce-parameter-object- Group related parametersmedium-switch-to-strategy- Replace type switches with interfacesmedium-middleware-decorator- Decorator pattern for http.Handlermedium-law-of-demeter- Reduce coupling, avoid message chains
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:
- "Refactor this code"
- "Reduce complexity"
- "Extract methods from large function"
- "Apply design patterns"
- "Improve maintainability"
- "Simplify this usecase"
- "Find code smells"
How to Use
For Code Refactoring
- Identify code smells (God Objects, long parameter lists, etc.)
- Apply appropriate refactoring pattern
- Verify tests still pass
- Check for improved readability
For Pattern Application
- Identify appropriate pattern for use case
- Apply pattern incrementally
- 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**:
```go
// Refactored code
Related Skills
- golang-clean-architecture - For usecase complexity patterns
- golang-idiomatic-go - For interface design
Philosophy
Based on Martin Fowler's Refactoring:
- Code smells indicate problems - Detect and address systematically
- Refactor incrementally - Small, safe steps
- Patterns are solutions - Apply when appropriate, not dogmatically
- Maintainability matters - Code is read more than written
Notes
- Focus on common Go refactoring patterns
- All patterns adapted for Go idioms
- Emphasizes readability and maintainability
- Includes Gang of Four patterns applicable to Go