clean-code-solid
Skill3 starsChanged 8 months agoMITView on GitHub
SOLID design principles applied to Go. Use when creating or editing Go types, structs, interfaces, or when making architectural decisions about type relationships, dependency injection, or package structure. Triggers on new struct/interface definitions, refactoring type hierarchies, or adding dependencies between packages.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- masonhuemmer/dopsword for word, first seen Mar 24, 2026
Other versions1 project uses a version of this.
Word for word · 1
- masonhuemmer/dops★ 3100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- bubbletea-patternsSkill
- charm-stylingSkill
- clean-code-boundariesSkill
- clean-code-designSkill
- clean-code-errorsSkill
- clean-code-functionsSkill
- clean-code-namingSkill
- clean-code-testingSkill
- cli-structureSkill
- create-runbookSkill
- demo-recordingSkill
- mutation-testingSkill
- shell-scriptsSkill
- spec-workflowSkill
- tdd-workflowSkill
- tui-layoutSkill
- tui-testingSkill
- wizard-formsSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
If a struct has methods spanning multiple concerns (e.g., parsing AND persistence), split it
- Very specific: line 61
If a function accepts an io.Writer, every writer must behave like a writer — no panics, no no-ops that silently discard data
- Distinctive: line 62
Do not implement interfaces partially — if you can't fulfill the contract, don't implement it
- Distinctive: line 67
Keep interfaces small — Go interfaces are implicitly satisfied, so small interfaces are natural
- Very specific: line 68
Prefer io.Reader (1 method) over a FileSystem interface with 15 methods
- Very specific: line 69
If a consumer only needs Read, don't make it depend on ReadWriteCloser
- Very specific: line 132
Never import from main or cmd in library packages
- Distinctive: line 137
Prefer composition: embed types to reuse behavior, don't simulate class hierarchies
- Distinctive: line 139
Keep the dependency graph acyclic — if two packages need each other, extract a shared interface package
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SOLID Principles for Go
Apply these principles when designing types, interfaces, and package structure.
Single Responsibility Principle (SRP)
- A struct should have one reason to change — one responsibility, one owner
- If a struct has methods spanning multiple concerns (e.g., parsing AND persistence), split it
- Packages are also a unit of responsibility — each package has a clear purpose
- Signal a violation: you can't describe what the struct does without using "and"
- Apply to functions too: a function with multiple flag arguments often handles multiple responsibilities
// Bad: mixed concerns
type Report struct { ... }
func (r *Report) Generate() []byte { ... }
func (r *Report) SaveToFile(path string) error { ... }
func (r *Report) SendEmail(to string) error { ... }
// Good: separated concerns
type Report struct { ... }
func (r *Report) Generate() []byte { ... }
type ReportWriter struct { ... }
func (w *ReportWriter) Save(data []byte, path string) error { ... }
type Notifier struct { ... }
func (n *Notifier) Send(to string, data []byte) error { ... }Open/Closed Principle (OCP)
- Types should be open for extension, closed for modification
- In Go, this means: define behavior via interfaces, add new implementations without changing existing code
- New specs should result in new types implementing existing interfaces, not edits to switch statements
- Signal a violation: adding a new feature requires modifying existing, tested code
// Good: new output formats don't change existing code
type Formatter interface {
Format(data []byte) ([]byte, error)
}
type JSONFormatter struct{}
func (f *JSONFormatter) Format(data []byte) ([]byte, error) { ... }
// Adding YAML support = new file, no changes to existing code
type YAMLFormatter struct{}
func (f *YAMLFormatter) Format(data []byte) ([]byte, error) { ... }Liskov Substitution Principle (LSP)
- Any implementation of an interface must be substitutable without changing correctness
- If a function accepts an
io.Writer, every writer must behave like a writer — no panics, no no-ops that silently discard data - Do not implement interfaces partially — if you can't fulfill the contract, don't implement it
- Signal a violation: type assertions or type switches on interface values to handle special cases
Interface Segregation Principle (ISP)
- Keep interfaces small — Go interfaces are implicitly satisfied, so small interfaces are natural
- Prefer
io.Reader(1 method) over aFileSysteminterface with 15 methods - If a consumer only needs
Read, don't make it depend onReadWriteCloser - Define interfaces at the call site (consumer), not at the implementation site
- Standard library models this well:
io.Reader,io.Writer,fmt.Stringer
// Bad: fat interface forces unnecessary dependencies
type Repository interface {
Get(id string) (*Entity, error)
List() ([]*Entity, error)
Create(e *Entity) error
Update(e *Entity) error
Delete(id string) error
Migrate() error
Backup() error
}
// Good: segregated by consumer need
type EntityGetter interface {
Get(id string) (*Entity, error)
}
type EntityLister interface {
List() ([]*Entity, error)
}
type EntityWriter interface {
Create(e *Entity) error
Update(e *Entity) error
Delete(id string) error
}Dependency Inversion Principle (DIP)
- High-level packages should not import low-level packages
- Both should depend on interfaces (abstractions)
- In Go: accept interfaces, return structs
- Inject dependencies via constructor parameters, not global state
// Bad: high-level directly depends on low-level
package deploy
import "myapp/internal/awsclient"
func Deploy(target string) error {
client := awsclient.New() // hard dependency
return client.Push(target)
}
// Good: depend on abstraction
package deploy
type Pusher interface {
Push(target string) error
}
func Deploy(p Pusher, target string) error {
return p.Push(target)
}- Wire dependencies at the composition root (usually
main.goor awirefunction) - Never import from
mainorcmdin library packages
Go-Specific Guidance
- Go does not have inheritance — use embedding for reuse, interfaces for polymorphism
- Prefer composition: embed types to reuse behavior, don't simulate class hierarchies
- Accept interfaces, return concrete types — this is the Go way to apply DIP
- Keep the dependency graph acyclic — if two packages need each other, extract a shared interface package
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

