Organise a Go project around Go modules and packages that each have one clear responsibility. Start with the simplest layout that works, put executables under cmd/, keep private code in internal/, and add directories only when the project needs them. Go has no mandatory layout, and the official guidance favours simplicity over a fixed template.
The recommendations below apply to current Go releases and to both small services and large multi-binary repositories.
For a small program or library, a flat layout is enough:
As the project grows, introduce structure. A typical service looks like this:
Key points:
cmd/<name>/main.go holds one executable each. Keep main thin, since it should only parse configuration, build dependencies and start the program.internal/ is enforced by the Go toolchain: packages inside cannot be imported from outside the parent module tree. Put most application code here so you can refactor freely.pkg/ is a convention, not a rule. Many projects skip it. Use it only if you intend external projects to import those packages, and remember that every exported package becomes a compatibility promise.tests/ directory of unit tests apart from the code. Go tests live next to the code they test.A module is defined by a go.mod file at the repository root. These are shell commands:
go.mod and go.sum./v2 suffix to the path.go mod tidy before committing to remove unused dependencies. Use go get -u ./... carefully, and read the changes.go.work workspace file for local development.Package design matters more than directory names.
order, auth), not generic names such as util, common or helpers.Because Service depends on a small interface, you can test it with an in-memory fake and swap the database implementation without touching business rules.
MixedCaps, not snake_case. Acronyms keep one case: HTTPClient, userID.order, name the type Order, not OrderOrder, and the constructor order.New.i, r for a reader or ctx for context, and descriptive names for wider scopes.Get prefix (user.Name()), and one-method interfaces with an -er suffix (Reader, Closer).Unit tests live in the same directory with a _test.go suffix. Use the same package name to test internals, or the _test package suffix to test only the public API.
Run all tests and checks from the repository root:
For configuration, read environment variables or a file in main, build a typed config struct, and pass it down, rather than reading globals deep inside packages. Keep build scripts, Dockerfiles and CI configuration in predictable top-level places, and use //go:embed for static files that must ship inside the binary.
No. That repository is a community convention, not an official Go standard. The Go team recommends starting simple, as described in the official guide on organising a Go module.
Use it for code that should not be imported by other modules. It lets you change implementation details without breaking users.
For small programs, yes. Split when a package has distinct responsibilities or becomes hard to navigate, and not before.
Place them in the package that uses them most, or create a focused package with a specific name. Avoid catch-all utils packages.
Keep Go project structure as simple as the project allows. Use a module per repository, cmd/ for executables, internal/ for private code and small, responsibility-focused packages with consumer-defined interfaces. Follow Go naming conventions, keep tests beside the code, and let the toolchain (go vet, go test -race, go mod tidy) enforce quality as the project grows.