User Guides
Dependency Structure Matrix (DSM): user guide
What the DSM is
The Dependency Structure Matrix shows the dependencies between code elements as a table instead of a diagram. The same elements are listed on the rows and on the columns, and each cell holds the dependency between its row element and its column element. A matrix stays readable with hundreds of elements, where a graph becomes unreadable, so it is the tool of choice for large applications, for finding dependency cycles, and for checking the layering of an architecture.

In the screenshot the elements are projects: the Inventory projects of the application, then the third-party elements (Windows SDK, STL, VCIncludes, Externals) on a bluish background. The number in a cell is the weight of the dependency (here: the number of members used).
Reading the matrix
Colors (legend, top left)
| Color | Meaning |
|---|---|
| Blue | Row uses column. The element of the row depends on the element of the column. |
| Green | Column uses row. The element of the column depends on the element of the row. |
| Red | Cycle: both elements use each other. Cells in a cycle are also marked with a red triangle in their corner (with a small cycle icon when the cells are large enough) and a red border. |
| Hatched gray | Not visible to each other: the two elements cannot depend on each other (for example a project that cannot see another one, or two fields), so nothing can be shown. |
| Diagonal line | The row and the column are the same element, or one contains the other. |
| Dark empty cell | No dependency. |
The number is the weight of the dependency (see Weight); an empty cell has no number. The shade of a blue or green cell shows the weight: the heavier the dependency, the brighter the cell, scaled separately for each direction between the lightest and the heaviest dependency of the matrix.
Rows, columns and headers
- Row and column headers list the same elements. The + box in front of a header expands the element into its children (for example a project into its namespaces).
- Third-party elements are shown on a different background than application elements, so they are easy to tell apart. A thin line marks the boundary between groups of rows and columns.
- The two bars between the headers and the matrix can be dragged to resize the header areas. The matrix scrolls in both directions and the headers follow.
A quick example
Read a cell by looking at its row and its column. In the screenshot, the cell of row Inventory.Core, column Inventory shows 18 in the hover tooltip: Inventory uses 18 member(s) from Inventory.Core.
Toolbar reference
| Control | What it does |
|---|---|
| View menu (first button) | Chooses what the matrix shows: View Projects, View Application Projects Only, View Namespaces, View Application Namespaces Only. "Application only" removes third-party elements. |
| Triangularize | Reorders the rows and columns so that the dependencies fall on one side of the diagonal, which reveals the layering. What remains on the wrong side, and the red cells, are layering violations and cycles. |
| Remove empty rows / columns (menu) | Remove Empty Rows and Columns, Remove Empty Columns, Remove Empty Rows, Remove Rows with third party code elements, Remove Rows with application code elements. Use them to shrink a large matrix to what matters. |
| Swap rows and columns (menu) | Swap Headers, Copy Vertical Headers to horizontal Header, Copy Horizontal Headers to Vertical Header. Disabled until the matrix can be modified this way (it is off at the start). |
| Undo / Redo | Step back and forward through your changes to the matrix. |
| Export to Graph (menu) | Export Elements To Graph, Export Horizontal Header To Graph, Export Vertical Header To Graph: opens the elements in the Call Graph. |
| Save the matrix as a PNG image (camera) | Exports the matrix to an image. |
| Zoom out / Zoom in | Changes the size of the cells. The number between the buttons is the current zoom level (19 in the screenshots). |
| WEIGHT | What the number in each cell counts, and whether indirect dependencies are included (next section). |
| BIND | Don't bind Columns and Rows (default) or Bind Columns and Rows: when bound, the columns follow the rows. |
| Bulb | Show details tooltip on hover: switches the hover tooltip on or off (on by default). |
Weight: what the numbers count

| Weight mode | The number in a cell is... |
|---|---|
| Direct & indirect depth of use | how far apart the two elements are in the use chain: 1 for a direct use, larger for an indirect use through other elements. |
| Direct: # namespaces | the number of namespaces of the used element that are used. |
| Direct: # types | the number of types used. |
| Direct: # members | the number of members (methods and fields) used. This is the mode of the screenshots. |
| Direct: # methods | the number of methods used. |
| Direct: # fields | the number of fields used. |
The two buttons next to the menu choose Direct dependencies (default) or Direct and Indirect dependencies. With indirect dependencies, an element that uses another one through intermediate elements also gets a cell. Start with members: the heavy cells are the strong couplings, and a heavy cell between two elements that should be independent is the one to investigate.
Hovering a cell

- The row and the column of the cell are highlighted with a golden band and the cell gets a gold border, so you never lose track of which pair you are reading.
- Labels with the names of the two elements appear on the headers.
- A tooltip shows both elements with their metrics, LOC, Debt, Rating (A to E) and MI, and the sentence that explains the cell, for example uses 18 member(s) from. When the cell has a comparison state, the tooltip also shows the differences (the LOC, debt and MI variations).
- The tooltip footer reminds the two actions: Double Click Show Dependencies Details and Right Click Advanced Actions.
- An arrow beside the cell indicates the direction of the dependency (up for "row uses column", left for "column uses row", both for a cycle).
Switch the tooltip off with the bulb button if it hides the matrix.
Acting on a dependency
Double-click a cell to open the details of that dependency: the code elements that create the dependency between the row and the column elements.
Right-click a cell for the advanced actions:

| Item | Result |
|---|---|
| Build a Graph made of Code Elements involved in this dependency | Opens a Call Graph with the elements behind the cell. |
| Open this dependency (default action, bold) | Same as double-click. |
| Open this dependency (keep only involved dependencies) | Opens the dependency and keeps only the dependencies involved in it. |
| Edit a code query that matches this dependency | Creates a CQLinq query selecting this dependency, so you can refine or save it. |
| Generate a code rule that warns if this dependency exists | Creates a rule that fails when this dependency is found. Use it to forbid a dependency that violates your architecture, then enforce it in the quality gate and in CI. |
Export a query result to the matrix
Any CQLinq query result can be shown in the matrix, to see how the elements it selects depend on each other. This answers questions such as "do the complex methods call each other?" or "which of these types use each other?".
- Open the Queries page and run a query that returns code elements. In the screenshot: the methods with a cyclomatic complexity above 10 (15 methods), grouped by project, namespace and type.
- Click the Export menu above the result and choose one of the matrix entries.

| Entry | Result |
|---|---|
| Export to matrix | The result elements are placed on both the rows and the columns: the matrix shows the dependencies among them. |
| Export to matrix rows | The result elements become the rows of the matrix. |
| Export to matrix columns | The result elements become the columns of the matrix. |
The other entries of the same menu export the result to a graph or a treemap (see the Call Graph and Code Map guides) or to an HTML, Excel, XML or text file. The Group By buttons next to the menu choose how the result is grouped (project, namespace, type) and Scope limits the query to the solution or to a smaller scope.
Reading the exported matrix

- The rows and columns are the methods of the result, organized under their type, namespace and project. The boxes with a minus sign collapse a group and the plus sign expands it again.
- Cells follow the usual colors: blue row uses column, green column uses row, red cycle, hatched elements that cannot see each other.
- In the screenshot a red frame surrounds a block of methods around the diagonal, with a red corner mark in its first cell: this marks a group of elements that depend on each other. Double-click a cell to see the dependency behind it.
- Hovering a cell highlights its row and column (golden band) and shows the full name of the method on the header, here
isValidEmail(conststd::string&). - All the toolbar actions work on the exported matrix: Triangularize, remove empty rows and columns, weight mode, zoom and export to graph or PNG.
Tip: use Remove Empty Rows and Columns after the export to keep only the elements that really depend on each other, then Triangularize to order them.
Recipes
- Find cycles. Choose View Application Projects Only (or namespaces), press Triangularize, and look for red cells: each pair of elements that use each other. Double-click one to see what creates the cycle.
- Check the layering. After Triangularize, cells on the wrong side of the diagonal are upward dependencies. Right-click one and generate a rule to forbid it.
- Who depends on STL? Read the STL row (or column): the cells list the application elements that use it, and the number says how many members.
- Shrink a big matrix. Use Remove Empty Rows and Columns, then remove third-party rows to concentrate on your own code.
- Go from matrix to picture. Export the elements to the Call Graph to see the same dependencies as arrows.
- Zoom to the details. Expand a project with the + box to see its namespaces, then again for types, and read weights by members.
