Where forge puts a project's generated config and middleware packages (internal/config and internal/middleware since v1.19.0; pkg/config and pkg/middleware before), how forge decides which a project has, the forge.yaml layout pin, and how to re-export either from your own pkg/ package so another module can import it. Use when a CLI, operator or sibling service in another module needs the typed config or the auth types, when a skill or error names pkg/config or pkg/middleware and your tree has...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Go Layout?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/reliant-labs-go-layout)
---
name: services/go-layout
description: Where forge puts a project's generated config and middleware packages (internal/config and internal/middleware since v1.19.0; pkg/config and pkg/middleware before), how forge decides which a project has, the forge.yaml layout pin, and how to re-export either from your own pkg/ package so another module can import it. Use when a CLI, operator or sibling service in another module needs the typed config or the auth types, when a skill or error names pkg/config or pkg/middleware and your tree has internal/config, or before moving a project with `forge fix internal-packages`.
---
# Config and middleware packages: where they live and how to publish them
**Config and middleware live under `internal/`, so the project's public surface stays small.** `internal/config` (the typed loader `forge generate` writes, plus `roots_gen.go` in a graph project) and `internal/middleware` (the auth interceptor, `procedures_gen.go`, the MCP tool table) are plumbing: Go keeps them importable only from inside the module, and `pkg/` is what a project promises other modules under semver. Projects scaffolded before v1.19.0 have them at `pkg/config` and `pkg/middleware` and stay there, with nothing to do, until they run `forge fix internal-packages` (playbook `migrations/v1.19.0/internal-packages`); forge reads which layout a project has from its tree, and `forge.yaml`'s `layout: {config_package: pkg/config, middleware_package: pkg/middleware}` pins either one. `forge scaffold package config` and `middleware` are refused where they would collide with these.
**Publishing them to another module.** Another module (a CLI, an operator, a sibling service) cannot import `<module>/internal/config`. A project that wants to share its typed config or the auth types re-exports them from a package of its own under `pkg/`; the package is then semver API the project owns, so export only what callers need:
```go
// pkg/config/config.go (yours)
// Package config publishes the service's typed config to other modules.
package config
import cfg "example.com/app/internal/config"
type Config = cfg.Config
var (
Load = cfg.Load
Defaults = cfg.Defaults
)
```
A graph project's `roots_gen.go` exists to be imported from another module: the repo that keeps a deployment's values checks them against the binary's schema in a unit test (`for _, r := range appconfig.Roots() { r.Validate(env) }`). On the `internal/` layout that repo imports your re-export, so publish the roots too:
```go
var (
Roots = cfg.Roots
RootNamed = cfg.RootNamed
ValidateRootEnv = cfg.ValidateRootEnv
)
```
The same shape works for middleware (`type Claims = mw.Claims`, `var GetUser = mw.GetUser`). Aliases keep one type, so a value from the re-export and the internal package are interchangeable inside the module. Forge recognises a `pkg/config` that imports `internal/config` as a re-export, not as the old layout, so it neither regenerates into it nor reports it as a half-finished move. A project still on the old layout that wants this: run `forge fix internal-packages` first, then add the re-export.
## Which layout a project has
Forge reads it from the tree, per package, so a project may have moved one and not the other: a `pkg/config` (or `pkg/middleware`) that holds forge's package stays there; otherwise the package is `internal/config` (`internal/middleware`). `forge.yaml`'s `layout:` pins either, and a pin wins:
```yaml
layout:
config_package: pkg/config # or internal/config
middleware_package: pkg/middleware # or internal/middleware
```
`config.loader_package` (the directory the typed-access lint allows to read the environment) defaults to the config package's directory. `forge scaffold package config` and `forge scaffold package middleware` are refused where they would collide with these. Moving an existing project: `migrations/v1.19.0/internal-packages`.