Keep your code well structured.
LayerLens is a tool that:
-
Automatically generates a dependency diagram as a Mermaid
flowchartwithin every directory of your Dart or Flutter package. -
Identifies and alerts you to any cyclic dependencies.
NOTE: LayerLens shows inside-package dependencies. For cross-package dependencies use flutter pub deps.
Unlike other dependency visualization and cycle detection tools that focus on language-specific concepts, LayerLens innovates by operating on file system concepts. It assumes that organizing our code by files and directories we accurately reflect our *mental model of the project.
Specifically, LayerLens:
-
Restricts each diagram to the content of a single directory, so that every directory has its own diagram.
-
For each directory treats immediate sub-directories and files as equal elements, and shows dependencies between these elements as a directed graph.
As result:
-
Each directory diagram is simple. It does not contain (1) any internal details of directories or files, and (2) any details of code outside the directory.
-
All diagrams together are enough to detect cycles in application.
-
Run
dart pub global activate layerlens -
Verify you can run
layerlens. If you getcommand not found, make sure your path contains pub cache.
-
Add
layerlens: <version>to the sectiondev_dependenciesin the package's pubspec.yaml. -
Run
dart pub getorflutter pub getfor the package. -
Verify you can run
dart run layerlens.
To see the diagrams in your IDE:
-
VSCode: install
Markdown Preview Mermaid Supportextension -
Android Studio: enable the "Mermaid" extension in the Markdown language settings
-
Run command:
-
With global configuration:
layerlensin the root of the package or in other place with--path <your package root> -
With package configuration:
dart run layerlensin the package root
-
-
Find the generated file DEPS.md in each source folder, where libraries or folders depend on each other.
-
In VSCode, right click DEPS.md and select 'Open Preview'
Make your pre-submit bots failing in case of issues, using flags:
--fail-on-cycles: fail if there are dependency cycles--fail-if-changed: fail if the generated diagrams has changed
Copy the content of run-layerlens.yaml
to .github/workflows.
It will work if your repo policy allows bots to update files.
If you want to generate the DEPS.md only for a specific folders, use --only and --except options,
formatted as glob syntax.
For example, to generate the diagrams:
- only for the root
lib/folder:dart run layerlens --only "lib" - only for the root
lib/folder:dart run layerlens --only "lib" - for all folders except
l10n/:dart run layerlens --except "l10n" - only for root
lib/and it's subfolder: runlayerlens --only "lib" --only "lib/subfolder1" - for the entire subtree for a given subfolder:
layerlens --only "lib/subfolder1" --only "lib/subfolder1/**"
While layerlens concepts are language agnostic, for now only dart is supported.
Please submit an issue, if you want other language to be added.
See CONTRIBUTING.md for details.
Apache 2.0; see LICENSE for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.
