Skip to content
Fallow home
All docs pages

Docs home

fallow architecture

Find the options, output fields and exit codes of fallow architecture, which finds import cycles, boundary violations and policy violations.

fallow architecture reports import cycles, boundary violations and rule-pack policy violations.

For the concepts and the workflow, read Architecture.

Synopsis

fallow architecture [OPTIONS] [PATH]

Options

ArgumentDescription
[PATH]Scope reported findings to this file or directory (default: whole project). The full project graph is still built; only reported items are narrowed
OptionDescription
--shared-stateInventory direct imported writes and custom global access sites
--cyclesOnly report import cycles: circular dependencies, re-export cycles and package cycles
--boundariesOnly report boundary violations, boundary coverage and forbidden calls
--policyOnly report rule-pack policy violations
--file <PATH>Only report issues in the specified file(s). Accepts multiple values.
--finding-id <ID>Only report the findings with these finding_id values. Repeat the flag or pass a comma-separated list

The global options are in these groups: Project, Output, Scope, Baselines, Gates, Duplication, Type-aware, Performance.

Option details

Requested rules that are off

When a selection option asks for a rule that the config sets to off, fallow does not run that check. The findings and the exit code do not change. Fallow prints a note on stderr, and adds a requested-rule-off entry with the rule and the flag to workspace_diagnostics:

Note: circular-dependencies is off in config, so --cycles did not check it. Set the rule to "error" or "warn" to run this check.

A run without a selection option gives no note.

Shared-state inventory

--shared-state adds a list of the places where code writes to an imported value, and of the custom properties of window, globalThis, self or global that more than one file reads or writes. Alone, it selects only the inventory. With --cycles, --boundaries or --policy, the run also reports those findings.

  • An imported write is an assignment, an update or a delete of a property of an imported value, with the declaration that the import resolves to.
  • A global group lists the reads and the writes of one custom property in different non-test files. These sites do not prove that the files share one runtime or an order of execution.
  • The inventory is not a finding. It does not change the totals, the health score, a baseline or the exit code.
  • Only the human, json and markdown formats show it. Another format, --sarif-file, --group-by or --finding-id together with --shared-state exits with code 2, also for an empty inventory.
  • The inventory uses static property keys only. It leaves out aliases, dynamic keys, mutator calls, Object.assign, destructuring targets and iteration targets. Check each site in the source before you change the code.
  • In JSON, shared_state.complete is false when a parse error or a limit cut the inventory, and shared_state.truncated is true when a limit cut it. A complete inventory covers the supported syntax only.
  • When one site of a global group matches a file, workspace or diff filter, the output keeps all reads and writes of that group.
  • The fallow-ignore-next-line shared-state and fallow-ignore-file shared-state comments and the sharedStateAllowlist config key remove a site from the inventory.

Relation to fallow dead-code

The fallow dead-code options above are deprecated aliases. fallow dead-code also reports the architecture findings by default. In human output, it then prints a tip on stderr that points to fallow architecture.

Bare fallow reports the architecture findings in an "Architecture" category of its dead-code section. The machine formats keep them in the dead-code part of the output. --only architecture runs only this part, and --skip architecture leaves it out. See global options.

Output

  3 entry points detected (2 package.json, 1 plugin)

── Architecture ─────────────────────────────────────

● Circular dependencies (1)
  src/services/catalog.ts
    → orders.ts → catalog.ts

  Import cycles that can cause initialization failures and prevent tree-shaking
  https://fallow.tools/docs/explanations/dead-code/#circular-dependencies

● Boundary violations (1)
  src/lib/format.ts:1 → src/services/catalog.ts (lib → services)
  Imports that cross defined architecture zone boundaries
  https://fallow.tools/docs/explanations/dead-code/#boundary-violations

✗ 1 circular dependency · 1 boundary violation (0.16s)
  • A cycle shows its first file, then the files of the loop.
  • A boundary violation shows the importing file and line, the imported file, and the two zones.
  • The last line counts the findings of each issue type.

With --format json, the output has the shape of the fallow dead-code output, with these differences:

FieldContent
kind"architecture". A --group-by run gives "architecture-grouped".
schema_versionThe version of the architecture output format, separate from the version of dead-code.
circular_dependencies, re_export_cycles, package_cyclesThe cycle findings. Re-export cycles gives the kind values of a re-export cycle.
boundary_violations, boundary_coverage_violations, boundary_call_violationsThe boundary findings.
policy_violationsThe rule-pack findings.
shared_stateThe inventory: version, complete, truncated, imported_writes and globals. Present only with --shared-state.

The other issue arrays of dead-code are present and empty. The JSON output reference has each field.

fallow report renders a saved architecture or architecture-grouped result in another format. A result with shared_state renders only as Markdown.

Package cycles

A package cycle shows the packages in cycle order, from the package with the lowest name, and one example import for each step:

● Package cycles (1)
  @acme/core → @acme/utils → @acme/core
    packages/core/src/format.ts:3 → packages/utils/src/index.ts
    packages/utils/src/log.ts:1 → packages/core/src/index.ts (type-only)

Each entry of package_cycles has these fields:

FieldContent
packagesThe package labels in cycle order. The last package imports the first.
package_rootsThe root directory of each package, in the same order.
lengthThe number of packages in the cycle.
edgesOne example import for each step: from_package, to_package, path, target_path, line, col and type_only. type_only is true when each import of the step is type-only.
group_truncatedtrue when the group of packages that holds this cycle has more cycles than fallow lists.
  • A label is the package name. When two workspace packages have the same name, the label adds the package root, for example example (examples/basic).
  • Fallow lists at most 20 cycles for one group of packages, shortest first. Each output format then shows the note this package group has more cycles than listed. Break a listed cycle and run fallow again.
  • --changed-since, the diff scope of fallow audit and --workspace keep a cycle when the file of one example import (edges[].path) is in scope. A new cycle always shows, because it adds a step whose imports are all new.
  • --group-by puts a cycle in the group of its first example import file. Per-file severity in overrides uses the highest severity of the example import files.
  • A regression baseline and fallow audit identify a cycle by its package labels, so a cycle that exists already does not fail a gate again.

Baselines

A fallow architecture baseline has the dead-code format and "kind": "dead-code". fallow architecture --baseline also reads a baseline of fallow dead-code --save-baseline. Because the run reports only some issue types, --fail-on-stale-baseline does not gate this command: the stale-baseline gate has the status skipped.

A baseline that fallow architecture --save-baseline writes lists only the architecture findings. When fallow dead-code reads it, fallow prints a warning that the baseline lists only part of the findings.

Exit codes

CodeMeaning
0No finding at error severity, and no other gate failed.
1A finding has a rule at error. By default, circular dependencies, boundary violations, boundary coverage and forbidden calls are at error. Re-export cycles, package cycles and policy violations are at warn. A rule in a rule pack can set its own severity.
2Invalid input, for example --shared-state with --format sarif.

Exit codes has the codes that all commands share.

Examples

# Before an edit, show the rules of a file; after the edit, find the violations
fallow guard src/ui/App.ts --format json --quiet
fallow architecture --format json --quiet

# Report cycles, boundaries and policy rules
fallow architecture

# Report only the import cycles in files that changed since main
fallow architecture --cycles --changed-since main --format json --quiet

# Report only the boundary findings of one workspace
fallow architecture --boundaries --workspace web

# List the writes to imported values and to shared globals
fallow architecture --shared-state --format json

# Render a saved result as a GitHub job summary
fallow architecture --format json -o results.json
fallow report --from results.json --format github-summary