layout

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 7 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 returns the strongly connected components of size greater than one in the unit graph, each sorted, outermost sorted for a stable message. A unit in such a component cannot be assigned to a tier, because part of it sits above another part.

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.

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 collapses the package graph onto units, dropping self edges.

Jump to

Keyboard shortcuts

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