Tool for helping developers keep their code bases clean and decoupled. It allows visualising a code base complexity using a 3d force-directed graph of files and
Tool for helping developers keep their code bases clean and decoupled. It allows visualising a code base complexity using a 3d force-directed graph of files and
Visualize the entropy of a code base with a 3d force-directed graph.
The more decoupled and modular a code base is, the more spread and clustered the graph will look like.
Ensure your code base decoupling by creating your own rules and enforcing them with dep-tree check
If you want to contribute additional languages, there's a guide here that teaches how to implement them with a hands-on example based on a fictional language.
Contributions are always welcome!
On Mac and Linux, it can be installed using brew:
brew install dep-treeAlternatively, on any platform including Windows it can be installed with pip...
pip install python-dep-tree...or npm:
npm install @dep-tree/clidep-tree is a cli tool for visualizing the complexity of a code base, and creating
rules for ensuring its loosely coupling.
It works with files, meaning that each file is a node in the dependency tree:
package/main.py, src/index.ts, src/lib.rs...).[!NOTE] it only takes into account local files, not files imported from external libraries.
.dep-tree.yml file.Choose the file that will act as the root of the dependency graph (for example src/index.ts), and run:
dep-tree entropy src/index.tsYou can also pass multiple files if you don't have a single entrypoint:
dep-tree entropy src/*It will open a browser window and will render your file dependency graph using a 3d force-directed graph.
The spheres (files) will be placed mimicking some attraction/repulsion forces. Some parts of your code base will tend to gravitate together if they are tightly coupled, and will tend to be separated if they are loosely coupled.
The 3d graph for a clean code base will have groups of nodes clustered together and clearly separated from other clusters:
The 3d graph for a tightly coupled code base will have all the nodes grouped together with no clustering and no clear separation between them:
Given two pieces of code, displays what are the dependencies between them. These pieces of code are specified using a glob patterns, for example:
dep-tree explain 'src/products/**/*.go' 'src/orders/**/*.go'[!WARNING]
Make sure you wrap the two glob patterns with single quotes ('') or double quotes (""), otherwise your shell might expand the globstars, anddep-tree explainwill receive an incorrect number of arguments.
This command will display what Golang files under the src/products directory depend on
other Golang files under the src/orders directory.
It will output something like this:
src/products/books/book.go -> src/orders/renting.go
src/products/price.go -> src/orders/order_manager.go
src/products/storage.go -> src/orders/order_manager.goAdditionally, the --overlap-left (-l) or --overlap-right (-r) arguments can be passed:
--overlap-left: when the left and right glob patterns have some files in common, keep only the
common files at the left, and discard them from the right. This flag is useful for retrieving any
external dependencies of a specific folder:# Retrieves dependencies from files in src/products to any other file that is not inside src/products
dep-tree explain 'src/products/**/*.go' '**/*.go' --overlap-left--overlap-right: when the left and right glob patterns have some files in common, keep only the
common files at the right, and discard them from the left. This flag is useful for retrieving
any file outside a specific folder that depends on that folder.# Retrieves dependencies from any folder but src/products that point to files inside src/products
dep-tree explain '**/*.go' 'src/products/**/*.go' --overlap-rightChoose the file that will act as the root of the dependency graph (for example my-file.py), and run:
dep-tree tree my-file.pyYou can see the controls for navigating through the graph pressing h at any time:
j -> move one step down
k -> move one step up
Ctrl d -> move half page down
Ctrl u -> move half page up
Enter -> select the current node as the root node
q -> navigate backwards on selected nodes or quit
h -> show this help sectionThe dependency linting can be executed with:
dep-tree checkThis is specially useful for CI systems, for ensuring that parts of an application that should not be coupled remain decoupled as the project evolves.
These are the parameters that can be configured in the .dep-tree.yml file:
entrypoints:List of entrypoints that will act as root nodes for evaluating multiple dependency trees. Some ap
No open issues yet, or sync has not completed.