---
title: "Go"
description: One folder, one bounded context, in Go.
source: go.dh.md
---
<!-- Made by dh llm from the source; nobody edits this file. -->

# Go

**Possible, and the smallest change of the four.** A context is one package tree inside one Go module. The compiler guards its inside.

## The files

```filetree
go.mod  # one module for the whole app
cmd/
  app/
    main.go  # api, worker, migrate
kernel/
  wiring/
    orders_gen.go  (generated)  # one file per context, committed
contexts/
  orders/
    context.yaml
    register.go  # the one function
    contract/
      v1/  # public
    internal/  # Go will not let another context import this
      api/
        v1/
      mcp/
      domain/
      data/
    policies.yaml
    flags.yaml
    config/
    observability/
    docs/
    tests/
      unit/
      integration/
```

## What the tools allow

| Question | Answer | Tag |
| --- | --- | --- |
| Tests inside the folder | yes; coverage needs `-coverpkg` | MEASURED |
| A planted failing test | fails | MEASURED |
| Tests or docs in the binary | 0 found | MEASURED |
| A `src/` folder | no: `internal/` must sit at the context's root | MEASURED |
| One Go module per context | no: `go.work` would be edited by every new context | MEASURED |

## Another context's inside does not compile

```terminal
$ go build ./...
package bc1/gobase/contexts/billing/internal/domain
	contexts/billing/internal/domain/zz_breach.go:3:8: use of internal package bc1/gobase/contexts/orders/internal/domain not allowed
```

## What changes in the template

| Change | Count | Tag |
| --- | --- | --- |
| Files moved | 4 of 248 | MEASURED |
| Config files edited | 10 | MEASURED |
| Project files per context | 0 | MEASURED |
| Generated files per context | 1 | MEASURED |

## What does not work cleanly

- Two new libraries on neighbouring lines conflict in `go.mod` and `go.sum`. `go mod tidy` fixes it. MEASURED
- The lint tool cannot match a context by wildcard, so our generator checks the layers. MEASURED
- No real Go app exists to try it on. NOT TESTED
