Abstract: Four new plugins make finding and fixing file dependency cycles even easier. “Dependency Cycles” architecture identifies them. “Architecture Overlap” graph and report makes it easy to compare any two architectures and can be used to see where “Dependency Cycles” are in “Directory Structure”. Finally “Dependency Hubs” identifies key files contributing to the cycle.
You set out to change one file. Then that change needs another change somewhere else, and that one needs another, until the “quick fix” touches half the codebase. The culprit is often a dependency cycle: files that all depend on each other, so none of them can change alone. On Windows, cycles can also make linking take forever.
Understand is great for finding dependencies. These new plugins go further: they find the cycles, show where they live in your code, and point to the files to start with when breaking them up.
Finding Dependencies
The first question is what dependency cycles to find. Dependency violations can find circular dependencies between architectures and even recommend ways to break the cycle. Automatic architectures like CMake or Visual Studio Structure make it straightforward to find dependencies between build system components.
So, for this article, let’s focus on file dependencies. It turns out there’s already an automatic architecture for finding file dependencies called Visibility Matrix Cores, based on network analysis. Dependency Cycles builds on it with a few changes:
- A name that says what it finds
- Cycles named after their hub files, so they’re easier to understand and track over time
- Header and code files grouped together
So, introducing the “Dependency Cycles” automatic architecture. For cycle names, let’s use the “hub” files (more on that below). Finally, let’s give the option to combine companion files (on by default). So, for C++, a header and code file are considered together. The algorithm for it works even if the project has a setup with header and code files in different directories.
For the CMake Sample Project, it finds 13 cycles. I’ll show the architecture as a “File Metrics Chart” because it’s prettier than a wall of text and more informative. From the image, the biggest cycle is “cmMakeFile”, followed by “cmCTest”. You can see the companion file clusters like “cmTarget” and “cmake” inside cmMakeFile.

Cycle Severity
The first thing I want to know about the cycle is how big it is. The chart gives me a hint which are the biggest. To get more information, I can use some existing metrics. Let’s look at the biggest cycle “cmMakeFile”.

From Contents, I can see that there are 559 Files involved in the cycle. But, because Dependency Cycles groups by companion files, the number of Children also matters. The cycle is between 272 companion file groups and the 15 Entities that belong directly to the architecture, for a total cycle size of 287.
Cycle Location
So far, only the companion file grouping and cycle names are new to this version of Understand.
Here’s where things get really cool. Suppose I want to know what’s in this cycle. I don’t really want to look through 559 files, or even the smaller 287 direct children and entities in the architecture. I want a summary view, like where this cycle is in “Directory Structure.”
Introducing “Architecture Overlap” plugins. I’ll show the chart first. Here is the “Dependency Cycles” architecture overlaid on “Directory Structure”:

I love this chart! I can immediately see that most of the cmMakeFile cycle (light blue) are in files directly belonging to source. The other smaller cycles are mostly confined to specific libraries. The second biggest cycle, cmCTest, is mostly in cTest, but with a few files in Source.
If I need more concrete numbers, I can open the “Architecture Overlap” report. It starts with the same chart and then gives me tables of details. Here’s the beginning of the first table:

As the picture showed, cmMakeFile is completely in the direct children of Source. cmCTest actually crosses three folders, but is mostly in cmCTest. Cycles that cross boundaries seem especially concerning so I’ll click on “cmCTest” to get more detail. I’ll skip to the second table in the report to see which architectures in Directory Structure contain parts of the cmCTest cycle:

The three folders that contain cmCTest cycle are “Source/CTest”, “Source” and “Source/Lexer Parser”.
More Fun Overlaps
Since I really love the new architecture overlap plugins, let’s do a few more use cases. First, CMake’s “Source” directory has 773 direct files, so Directory Structure doesn’t break the code down much. The custom Functional Decomposition architecture in the sample project gives a clearer picture. Cycle colors are the same so I’ll skip the legend in the screenshot. Now I can see that even though cmMakeFile cycle is all within Source, it crosses a lot of functional groups.

I don’t have to limit my overlap to cycles. For instance, what if I want to know what parts of the code a specific Git Author works on. I’ll make the automatic “Git Author” architecture to see the last author to touch each piece of code and overlap that on “Directory Structure”. CMake is clearly being taken over by a robot.

Dependency Hubs
Alright, back to cycles. I know cmMakeFile is my biggest cycle with 287 members (559 files) and that it’s entirely inside files inside the “Source” folder, and covers many parts of the “Functional Decomposition” architecture. What if I wanted to break it up?
I’ll start the same way Dependency Cycles decided the cycle name. I want to find the hub(s) of the cycle.
The Dependency Hubs algorithm was initially developed for AI. Specifically, architecture overviews need to summarize potentially hundreds of files, but for speed we try to do it in a single prompt. AI tends to be more accurate looking directly at source code, so after listing the architecture contents, the overview prompt includes source code from key files. But how to identify the file most likely to help the AI determine the purpose of the code?
Testing showed that the file with the most incoming dependencies from its peer files was the most useful for AI to read. Like Dependency Cycles, companion files are grouped before finding incoming dependencies. From within companion files, header files are preferred over code files, and shorter files are preferred over longer ones.
Now this algorithm exists in Python and is used by Dependency Cycles to name cycles. But there’s also an interactive report “Dependency Hubs” to show the raw results. Let’s run it on cmMakeFile cycle.

From the report, I have two main directions I could go to break up this cycle. I could try to remove outgoing dependencies from the hub file(s) to remove them from the cycle. Or I could try to remove incoming dependencies from the files with the least incoming dependencies to remove them from the cycle.
Conclusion
The plugins get me a lot more information than I had before. I now know where the cycles are and have an idea which files I could start with. There’s more we could build from here. For instance, it would be nice to get the same dependency violations view of files that exists for architectures so I could see recommended edges to remove. A view similar to the “Architecture Overlap” graph but over “File Dependencies” instead of a treemap also seems useful to see where cycles are. Or, circling back to Git, maybe certain authors should be skippable so that automated commits don’t obscure useful information. With so many possibilities, we need your feedback to choose. What matters most to you?






