Graph
graph rules check the whole import graph: cycles, files nothing imports, and whether one
layer reaches another through any number of hops, which per-file rules can’t see.
graph: cycles: - name: no-cycles message: "These files import each other." within: "packages/*/src/**" withinNot: "**/*.test.ts" orphans: - name: no-dead-modules message: "Nothing imports this file. Register it, or delete it." within: "packages/*/src/**" withinNot: "**/*.test.ts" entry: ["packages/*/src/index.ts", "packages/*/src/main.ts"] reach: - name: adapters-through-ports message: "An adapter reaches infrastructure only through a port." from: "packages/*/src/adapters/**" to: "packages/*/src/infrastructure/**" via: "packages/*/src/ports/**"graph is a top-level key. Its globs expand aliases.
Fields
Section titled “Fields”Every rule needs name and message.
| Rule | Field | Meaning |
|---|---|---|
cycles |
within, withinNot |
Files to check. Required: within. |
orphans |
within, withinNot |
Files to check. Required: within. |
orphans |
entry |
Entry points, which nothing needs to import. Required. |
reach |
from, fromNot |
Origin files. Required: from. |
reach |
to, toNot |
Files they must not reach. Required: to. |
reach |
via |
Files a path may pass through. Omit to forbid every route. |
cycles
Section titled “cycles”Reports each group of files that import each other, once. A cycle through a file outside
within isn’t seen. Its baseline entry
is keyed on the set of files.
orphans
Section titled “orphans”Reports a file in scope that nothing imports and isn’t an entry. An import from anywhere
counts, including tests.
Reports a from file that can reach a to file without passing through a via file. The
route is appended to the message:
packages/server/src/adapters/http/todos.ts [adapters-through-ports] An adapter reaches infrastructure only through a port. (route: packages/server/src/adapters/http/todos.ts → packages/server/src/shared/db.ts → packages/server/src/infrastructure/pg-live.ts)The baseline entry is keyed on origin and target, not the route.
What’s in the graph
Section titled “What’s in the graph”Every walked file, with an edge per import that resolves to another walked file, type-only
imports included. External packages and builtins aren’t in it. check reports unresolved
imports separately.