Skip to content

Dependency Graph

The graph command visualizes and analyzes dependency relationships across the monorepo workspace. It detects cycles, enforces architectural layering rules, and generates graph visualizations in multiple formats.

Subcommands

graph visualize

Generates a visualization of the workspace dependency graph:

bash
# Text output to stdout (default)
dart run monorepo_toolkit graph visualize

# DOT format for Graphviz
dart run monorepo_toolkit graph visualize --format dot --output graph.dot

# Mermaid diagram for Markdown
dart run monorepo_toolkit graph visualize --format mermaid --output graph.md

# JSON for programmatic use
dart run monorepo_toolkit graph visualize --format json --output graph.json
FormatUse case
textQuick terminal overview (default)
dotGraphviz rendering (dot -Tpng graph.dot -o graph.png)
mermaidEmbed in GitHub Markdown or docs
jsonProgrammatic analysis or custom tooling

graph stats

Displays dependency statistics for the workspace:

bash
dart run monorepo_toolkit graph stats

Reports total package count, total edges, most-depended-on packages, and packages with the most dependencies.

graph cycles

Detects circular dependencies in the workspace:

bash
dart run monorepo_toolkit graph cycles

Returns exit code 0 if no cycles are found, or exit code 1 with a list of detected cycles.

graph validate

Validates dependency rules from ADR-006 (architectural layering constraints):

bash
dart run monorepo_toolkit graph validate

# Show detailed output including passing checks
dart run monorepo_toolkit graph validate --verbose

Returns exit code 0 if all rules pass, or exit code 1 with a list of violations.

Architectural rules enforced

The validate subcommand enforces these layering constraints:

RuleDescription
api-restricted-deps*_api packages depend ONLY on shared/, utilities/, and other *_api
no-impl-cross-dep*_impl packages cannot depend on other *_impl from different features
shared-no-upward-depshared/ cannot depend on features/, infrastructure/, packages/, or apps/
utility-no-upward-deputilities/ cannot depend on features/, infrastructure/, packages/, or apps/
no-upward-deppackages/ cannot depend on feature impl or app packages
no-devtools-depApp packages cannot depend on devtools packages

Dependencies must flow downward:

apps/ -> features/ -> infrastructure/ -> packages/ -> shared/ -> utilities/

Package categories

The validator automatically categorizes packages based on their path:

CategoryPath patternExample
appapps/template_app
sharedshared/feature_sdk, app_config
utilityutilities/app_utilities, app_lints
api*_api in infrastructure/ or features/auth_api, monitoring_api
impl*_impl in infrastructure/ or features/auth_impl, monitoring_impl
featurefeatures/ without _api/_impl suffixintroduction
infrastructureinfrastructure/ without suffixstandalone infra packages
packagepackages/app_asset, app_ui_kit
devtoolsdevtools/monorepo_toolkit

CI integration

Add graph validation to your CI pipeline to catch architectural violations early:

yaml
- name: Validate dependency graph
  run: dart run monorepo_toolkit graph validate

- name: Check for cycles
  run: dart run monorepo_toolkit graph cycles

Both commands return non-zero exit codes on failure, which will fail the CI step.

Melos shortcuts

bash
melos run graph:visualize   # Visualize dependency graph
melos run graph:stats       # Show dependency statistics
melos run graph:cycles      # Detect circular dependencies
melos run graph:validate    # Validate architectural rules

Built by Banua Coder