/go-specialist:go-structurefrom go-specialist
Recommends and scaffolds Go project layouts by type (CLI, API, library, monorepo). Detects anti-patterns like generic package names, over-nesting, and circular dependencies.
Ships in go-specialist. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Recommend and scaffold idiomatic Go project layouts. Matches structure to project type and size — start simple, grow when needed.
Simplicity first, complexity when necessary. Do not impose structure upfront. Let it emerge from actual needs. A single main.go is a valid starting point.
| Anti-Pattern | Problem | Fix |
|---|---|---|
Generic package names (utils, helpers, common, base) | Become dumping grounds, convey no intent | Rename to specific purpose: validator, auth, cache |
Over-nesting (internal/services/user/handlers/http/v1/) | Cognitive load, cumbersome imports | Flatten to internal/user/handler.go |
Circular dependencies (A imports B, B imports A) | Compilation error, poor separation | Extract shared types into a separate package or use interfaces |
| Business logic in HTTP handlers | Couples domain to transport, hard to test | Move to service layer, handlers only do HTTP concerns |
The main.go monster (all logic in one file) | Untestable, circular deps, impossible to maintain | Extract into packages; main.go only wires deps and starts |
| Shared database across microservices | Distributed monolith, schema changes break all services | Each service owns its data; communicate via APIs |
Using pkg/ for non-library code | Misleading signal, unnecessary indirection | Move to internal/ or project root |
Premature cmd/ for single-binary projects | Unnecessary nesting | Keep main.go at root until multiple binaries are needed |
| Hardcoded DB credentials / config values | Security risk, not deployable across environments | Use env vars or config system; never commit secrets |
Analyze the codebase to classify:
| Signal | Project Type |
|---|---|
Single main.go at root, flag/cobra imports | CLI tool |
net/http or framework imports (gin, chi, echo, fiber) | REST API service |
No main.go, only library packages | Reusable library |
Multiple main.go under cmd/, one go.mod | Monorepo / multi-binary (single module) |
Several go.mod files + a go.work | Multi-module workspace |
go.mod only, empty or minimal | New project (ask user) |
Based on project type and current size, recommend the appropriate layout from the reference patterns below.
Sizing rules:
internal/ with feature-based packagescmd/ + internal/ structureFor existing projects, present a table of findings:
| Finding | Severity | Recommendation |
|---|---|---|
utils/ package detected | Warning | Rename to specific purpose |
Business logic in handler.go | Warning | Extract to service.go |
No internal/ for private code | Info | Consider internal/ as project grows |
For single-purpose tools and prototypes. Grow from here.
mytool/
├── main.go
├── go.mod
├── go.sum
└── README.md
mytool/
├── main.go
├── command/
│ ├── root.go
│ └── version.go
├── go.mod
└── README.md
Organize by feature/domain, not by technical layer.
myapi/
├── cmd/
│ └── api/
│ └── main.go # Minimal: wire deps, load config, start
├── internal/
│ ├── config/
│ │ └── config.go
│ ├── middleware/
│ │ └── auth.go
│ ├── user/ # Feature package
│ │ ├── handler.go # HTTP concerns only
│ │ ├── handler_test.go
│ │ ├── service.go # Business logic
│ │ ├── service_test.go
│ │ ├── repository.go # Data access interface + implementation
│ │ └── repository_test.go
│ └── product/
│ ├── handler.go
│ ├── service.go
│ └── repository.go
├── go.mod
└── README.md
Key rule: cmd/*/main.go is minimal — only dependency wiring, config loading, and server start. All logic lives in internal/.
Each file in a feature package (internal/user/) has a clear, single responsibility:
| File | Layer | Responsibility | Imports |
|---|---|---|---|
handler.go | Transport | HTTP request/response only: parse input, call service, write response. No business logic. | net/http, service interface |
service.go | Business | Domain logic and orchestration. Validates rules, coordinates repositories. Pure Go — no HTTP, no SQL. | Repository interface, domain types |
repository.go | Data access | Defines the Repository interface (port) AND its implementation. Talks to DB. | database/sql, domain types |
model.go | Domain | Entities, value objects, custom error types. No external dependencies. | Standard library only |
Dependency flow: Handler → Service → Repository (interfaces). Dependencies always point inward.
Services receive their dependencies as interfaces via constructors — never create them internally:
// internal/user/repository.go — define the interface (port)
type Repository interface {
FindByID(ctx context.Context, id string) (*User, error)
Save(ctx context.Context, user *User) error
}
// internal/user/service.go — accept interface, not concrete type
type Service struct {
repo Repository
}
func NewService(repo Repository) *Service {
return &Service{repo: repo}
}
// cmd/api/main.go — wire everything together
func main() {
db := connectDB()
userRepo := user.NewPostgresRepository(db)
userService := user.NewService(userRepo)
userHandler := user.NewHandler(userService)
// ... register routes
}
This keeps services testable (mock the interface) and swappable (change DB without touching business logic).
For complex domain logic with clear port/adapter separation.
myservice/
├── cmd/
│ └── api/
│ └── main.go
├── internal/
│ ├── domain/
│ │ └── user/
│ │ ├── entity.go # Domain models, value objects
│ │ ├── repository.go # Port (interface)
│ │ └── service.go # Domain services
│ ├── application/
│ │ └── user/
│ │ ├── create_user.go # Use case
│ │ ├── get_user.go # Use case
│ │ └── service.go # Orchestration
│ └── adapter/
│ ├── http/
│ │ └── user_handler.go # Inbound adapter
│ ├── postgres/
│ │ └── user_repo.go # Outbound adapter (implements port)
│ └── redis/
│ └── cache.go # Outbound adapter
├── api/
│ └── openapi.yaml
├── go.mod
└── README.md
Dependency rule: Dependencies flow inward. Domain has zero external imports. Adapters implement domain interfaces.
Only use pkg/ when code is intended for external import.
mylib/
├── mylib.go # Public API at package root
├── mylib_test.go
├── internal/
│ └── parser/ # Private implementation
│ ├── parser.go
│ └── parser_test.go
├── go.mod
└── README.md
myproject/
├── cmd/
│ ├── api/
│ │ └── main.go
│ ├── worker/
│ │ └── main.go
│ └── scheduler/
│ └── main.go
├── internal/
│ ├── shared/ # Shared internal packages
│ ├── api/ # API-specific code
│ ├── worker/ # Worker-specific code
│ └── scheduler/ # Scheduler-specific code
├── go.mod # ONE module for the whole repo
└── README.md
Generator caveat: /gen-goreleaser and /gen-taskfiles emit a single-binary
build by default. After scaffolding several cmd/* binaries, add one builds:
entry per binary to .goreleaser.yml and extend the build task in
Taskfile.yml, or those binaries never get built or released.
No go.work here. A workspace file exists to union several modules; a repo
with a single go.mod does not need one, and the Go docs advise against
committing go.work in the first place. Reach for a workspace only when the repo
genuinely holds multiple go.mod files (each service its own module, no shared
root module) — then go.work is a local-development convenience, typically
git-ignored rather than checked in.
internal/ is enforced, not conventionalinternal/ is a rule the Go compiler applies, not a naming habit: a package under
.../internal/x can only be imported by code rooted at ... — the directory
containing internal — and this holds at any nesting depth. That is what makes
it a real boundary rather than a hint, and why it is the right home for code you
do not want external consumers importing. See
https://pkg.go.dev/cmd/go#hdr-Internal_Directories.
When creating a new project or restructuring:
Ask user to confirm the detected or intended project type if ambiguous.
Create only the directories needed for the chosen layout. Do not create empty placeholder directories.
For new projects, create:
main.go with minimal bootstrap code (for binaries)go build ./...
go vet ./...
Prefer feature-based organization:
# Good: organized by domain
internal/
├── user/
│ ├── handler.go
│ ├── service.go
│ └── repository.go
└── order/
├── handler.go
├── service.go
└── repository.go
# Avoid: organized by layer
internal/
├── handlers/
│ ├── user.go
│ └── order.go
├── services/
│ ├── user.go
│ └── order.go
└── repositories/
├── user.go
└── order.go
Feature-based packages are self-contained, reduce cross-package imports, and make it easy to understand a domain in one place.
When reviewing an existing project, check for these structural violations:
Grep handler files for signs of business logic leaking into the transport layer:
db.Query, db.Exec) in handler filesCheck service files for HTTP or framework imports that don't belong:
net/http imports in service layerVerify dependencies flow inward (handler → service → repository):
| File | Violation | Severity | Fix |
|---|---|---|---|
user/handler.go | Contains db.Query call | Error | Move to repository |
order/service.go | Imports net/http | Warning | Accept domain types, not HTTP types |
auth/handler.go | 50+ lines of validation logic | Warning | Extract to service method |
| Condition | Action |
|---|---|
No go.mod found | Ask if user wants to run go mod init |
| Project type ambiguous | Ask user to confirm type before recommending |
| Circular dependency detected | Report the cycle and suggest extraction of shared types |
utils/ or helpers/ package found | Flag as anti-pattern, suggest specific name |
What SKILL.md sets; muted values are Claude Code's defaults
11 skills in this plugin
/gen-forgejo-dirGenerate complete .forgejo/workflows directory with Forgejo Actions workflows (test, lint, release) for Go projects/gen-github-dirGenerate complete .github directory with workflows, dependabot, and funding configs for Go projects/gen-gitlab-ciGenerate GitLab CI/CD pipeline configuration for Go projects with testing, coverage, and automated releases/gen-goreleaserGenerate GoReleaser configuration with multi-arch Docker builds and release automationnpx claudepluginhub sgaunet/claude-plugins --plugin go-specialistOther plugins' skills for the same job