NewsCrawler.org

Structuring a Go codebase for coding agents and human developers

Structuring a Go codebase for coding agents and human developers
Image: Reddit

The author writes about organizing a Go codebase so that both coding agents and human developers can find their way around it. He does not expect agents to get things right immediately and relies on corrections made by humans over time. To support this, he uses a clear file layout with context boundaries and tooling that validates SQL schema, generates code from a source of truth, and builds, tests and releases the project to reduce human error.

After packages are moved, Go import paths break, so the author wrote splint, which also absorbs some of the behaviour of goimports[1]. Running splint fix ./... corrects import paths and package names in one pass. The author's rules require that the root internal/ package contain only the standard library and that go test -c ./... not fail on duplicate packages. He prefers users/model, users/client and users/service over the model/users, service/users, client/users layout typical of gRPC[2] services, because it allows a separate go.mod per service.

The ruleslint tool checks which folders and files a package must contain, and its linters block runs splint in a single command. The package constraints forbid sync.Mutex in model and allow SQL queries only in storage. The author checks these constraints with ruleslint but finds semgrep[3] more flexible, and he leaves open whether scanning the whole tree or only changed files is better.

Read the original incubator.toDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page