layout

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package layout builds repository import graphs for dependency-boundary tests.

Design

LoadRepo reads both Go modules, records package edges and maps them to repository-relative paths. The graph supports transitive reachability and directory-level strongly connected components. Tests define tier rules and their explicit exceptions.

Keeping the graph reader separate from policy lets the tests verify package placement and module direction. The lint workflow reports issues without a failing issue exit code, so these boundaries are enforced through Go tests.

References

Index

Constants

This section is empty.

Variables

View Source
var ErrGoList = fmt.Errorf("layout: go list failed")

ErrGoList reports that the go command could not enumerate the module.

Functions

func Cycles

func Cycles(g map[string][]string) [][]string

Cycles finds groups of directory units whose dependencies form a loop. These units cannot be placed in a consistent dependency order. Each group contains at least two units. Names within each group are sorted, and groups are sorted by their first name so diagnostics remain consistent.

func Unit

func Unit(pkg string) string

Unit is the directory a tier is assigned to: the first path element, except under a namespace, where it is the first two. The library and server containers preserve that granularity within each module.

Types

type Graph

type Graph struct {
	Module  string
	Imports map[string][]string
	// External records imports outside this module, which LoadRepo needs to
	// resolve edges from the server module back into the library.
	External map[string][]string
}

Graph is this module's package import graph, keyed by package path relative to the module path ("mdm", "ddm/predicate"). Only in-module imports are recorded; the standard library and third-party dependencies are not part of a tier question.

func Load

func Load(dir string) (*Graph, error)

Load runs go list in dir and returns the in-module import graph.

func LoadRepo

func LoadRepo(root string) (*Graph, error)

LoadRepo returns one graph spanning every module in the repository. The server is its own module, so a single go list would stop at the library and the tier tests would quietly cover half the tree. Server packages keep their directory as a prefix ("server/service"), so a package's key is its path from the repository root either way.

func (*Graph) Packages

func (g *Graph) Packages() []string

Packages returns every in-module package path, sorted.

func (*Graph) Reaches

func (g *Graph) Reaches(from string) []string

Reaches returns every package transitively imported by from, sorted. A package does not reach itself unless the graph says so.

func (*Graph) UnitGraph

func (g *Graph) UnitGraph() map[string][]string

UnitGraph shows which directory units depend on each other. It omits imports between packages that belong to the same unit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL