clean-code-boundaries
Skill3 starsChanged 8 months agoMITView on GitHub
Clean Code boundary and encapsulation principles for Go. Use when integrating third-party libraries, calling external APIs, wrapping SDK clients, defining package visibility, or managing dependencies at the edges of the system.
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-designSkill
- clean-code-errorsSkill
- clean-code-functionsSkill
- clean-code-namingSkill
- clean-code-solidSkill
- 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, 7 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Never let third-party types leak into your domain:
- Distinctive: line 25
Create thin adapters that implement your interface using the third-party library
- Distinctive: line 27
When the library changes (or you switch libraries), only the adapter changes
- Distinctive: line 42
Default to unexported (lowercase) — export only what external packages need
- Very specific: line 43
Use internal/ to enforce boundaries at the compiler level:
- Distinctive: line 50
If you export something, you maintain it.
- Distinctive: line 67
When external systems use different domain language or data models, translate at the boundary
- Distinctive: line 82
When adopting a new third-party library, write tests that verify YOUR understanding of its behavior
- Very specific: line 110
If a spec says "store the artifact," the domain code calls store.Put(), not s3Client.PutObject()
≈ “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
Clean Code Boundaries for Go
Apply these principles when code interacts with external dependencies or defines visibility boundaries.
Wrap External Dependencies
- Never let third-party types leak into your domain:
// Bad: domain code depends on AWS SDK types func Deploy(ctx context.Context, client *s3.Client, bucket string) error // Good: domain code depends on your interface type ObjectStore interface { Put(ctx context.Context, key string, data []byte) error } func Deploy(ctx context.Context, store ObjectStore, target string) error - Create thin adapters that implement your interface using the third-party library
- Adapter packages live at the edge:
internal/adapters/awsstore/, not mixed into domain code - When the library changes (or you switch libraries), only the adapter changes
Define Interfaces at the Consumer
- The package that uses the dependency defines the interface it needs
- The package that implements it satisfies the interface implicitly
- This is Go's superpower — implicit interface satisfaction means zero coupling between consumer and provider:
internal/deploy/ → defines Pusher interface (consumer) internal/adapters/aws/ → implements Pusher (provider, doesn't import deploy) cmd/root.go → wires aws.Client as deploy.Pusher
Encapsulation via Package Visibility
- Default to unexported (lowercase) — export only what external packages need
- Use
internal/to enforce boundaries at the compiler level:internal/deploy/ — importable only by this module internal/config/ — importable only by this module pkg/ — only if you intentionally want external consumers - A package's exported API is its contract — keep it minimal
- If you export something, you maintain it. Unexport aggressively.
Principle of Least Privilege
- Give each component access to only what it needs
- Pass specific dependencies, not the whole application context:
// Bad: function has access to everything func Deploy(app *Application) error // Good: function has access to exactly what it needs func Deploy(pusher Pusher, target string) error - Narrow interfaces are a form of least privilege —
io.Readerover*os.File
Anti-Corruption Layer
- When external systems use different domain language or data models, translate at the boundary
- Your domain types should not be shaped by an external API's response format:
// Adapter translates external model to domain model func (a *GitHubAdapter) ListDeployments(ctx context.Context) ([]deploy.Target, error) { resp, err := a.client.Repositories.ListDeployments(ctx, a.owner, a.repo, nil) if err != nil { return nil, fmt.Errorf("list github deployments: %w", err) } return toDeployTargets(resp), nil // translate to domain type }
Learning Tests
- When adopting a new third-party library, write tests that verify YOUR understanding of its behavior
- These tests serve as documentation and catch breaking changes on upgrade:
func TestYAMLMarshal_PreservesOrder(t *testing.T) { // Verify our assumption that yaml.Marshal preserves field order // If a library upgrade breaks this, we'll know immediately } - Learning tests live alongside the adapter that uses the library
Configuration Boundaries
- Environment variables, config files, and CLI flags are external inputs — validate at the boundary
- Parse and validate config into typed structs early; pass typed values inward
- Domain code never reads environment variables or config files directly:
// Bad: buried in domain code func Connect() (*DB, error) { host := os.Getenv("DB_HOST") // hidden dependency // Good: injected from boundary func Connect(host string, port int) (*DB, error) {
Spec Traceability
- Specs describe behavior in domain language, not library language
- Boundary wrappers ensure implementation matches domain language
- If a spec says "store the artifact," the domain code calls
store.Put(), nots3Client.PutObject()
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.

