User Guides
Dependency Matrix (DSM)
The Dependency Structure Matrix shows the dependencies between code elements as a table. It stays readable with hundreds of elements, which makes it the tool of choice to find dependency cycles and to check the layering of a large code base. This page explains every control, menu and action of the screen, with screenshots of a real analysis of Cppcheck 2.22.
What the matrix shows
The same code elements are listed on the rows (left) and on the columns (top). The cell at the crossing of a row and a column describes the dependency between those two elements:
- its color tells the direction of the dependency, or a cycle;
- its number is the weight of the dependency, by default the number of members used;
- an empty dark cell means no dependency.
A graph with 60 namespaces and their arrows is unreadable; the same 60 namespaces in a matrix fit on one screen, and cycles stand out as red blocks.

Opening the matrix
| From | How |
|---|---|
| Menu bar | Design & Architecture › DSM. |
| Features panel | Design & Architecture › DSM. |
| Code Quest (query results) | Export › Export to matrix, Export to matrix rows or Export to matrix columns. See Show a query result in the matrix. |
| Call Graph | The Export to matrix button opens the elements of the graph in the matrix. |
The page title in the top bar reads DSM. The matrix opens on the projects of the solution; Cppcheck shows cli, cppcheck and two groups of third-party code, Externals and Windows SDK.

The screen at a glance
The numbers in the screenshot match the table. Controls 1 to 17 form the toolbar; 18 to 21 are the areas of the matrix. The tooltip column quotes the text shown when you hover the control.

| # | Control | Tooltip | What it does |
|---|---|---|---|
| 1 | View menu | Choose what the matrix shows | Projects or namespaces, with or without third-party code. See View menu. |
| 2 | Triangularize | Triangularize the dependency matrix | Reorders rows and columns to reveal the layering. See Triangularize. |
| 3 | Remove menu | Remove empty rows / columns | Shrinks the matrix. See Remove menu. |
| 4 | Swap menu | Swaps or copies the headers. Greyed out until the matrix can be changed this way. See Swap menu. | |
| 5 | Undo | Cancels the last change of the matrix (triangularize, remove, swap...). Greyed out when there is nothing to undo. | |
| 6 | Redo | Applies again a change you undid. | |
| 7 | Export to Graph menu | Export to Graph | Opens the elements in the Call Graph. See Export menus. |
| 8 | Save as PNG (camera) | Save the matrix as a PNG image | Saves the matrix as an image file. |
| 9 | Zoom Out | Zoom Out | Makes the cells smaller, to see more of the matrix. |
| 10 | Zoom value | The number displayed between the two zoom buttons (19 here). | |
| 11 | Zoom In | Zoom In | Makes the cells larger, to read the numbers. |
| 12 | WEIGHT menu | What the number in each cell counts | Members, methods, types... See Weight. |
| 13 | Direct dependencies | Direct dependencies | Counts only direct uses (default, highlighted). |
| 14 | Direct and Indirect dependencies | Direct and Indirect dependencies | Also counts uses through other elements. |
| 15 | BIND: don't bind | Dont bind Columns and Rows | Rows and columns can be changed separately (default, highlighted). |
| 16 | BIND: bind | Bind Columns and Rows | The columns follow the rows: expanding or removing a row does the same on the matching column. |
| 17 | Details tooltip (bulb) | Show details tooltip on hover | Switches the hover card on (highlighted, default) or off. |
| 18 | Legend | The meaning of the colors, and the reminder "Right click: For more actions". See Colors. | |
| 19 | Column headers | The elements of the columns, grouped under their project. The + box expands an element into its children; − collapses it. | |
| 20 | Row headers | The same elements on the rows, with the same + / − boxes. Projects are written vertically on the far left. | |
| 21 | Matrix | The cells. The diagonal line marks where a row meets the same element in the columns. |
The bars between the headers and the matrix can be dragged to give more room to the names.
Colors and numbers
| Cell | Meaning (as given by the legend) |
|---|---|
| Blue | Row uses column. |
| Green | Column uses row. |
| Red | Cycle: both elements use each other. The first cell of a group of elements in a cycle carries a red corner mark, and a red frame surrounds the whole group. |
| Hatched gray | Not visible to each other: the two elements cannot depend on each other. |
| Dark, no number | No dependency. |
| Diagonal line | The row and the column are the same element. |
| Small red corner with + | Shown when a baseline is set (here Cppcheck 2.15): the dependency is new since the baseline. |
| Bold header name | Shown when a baseline is set: the element is new or changed since the baseline. |
The number is the weight of the dependency (see Weight). The brighter a blue or green cell, the heavier the dependency. To be sure of the direction of a dependency, hover the cell: the card states it in a sentence, such as uses 16 member(s) from.
View menu

| Item | Rows and columns are |
|---|---|
| View Projects | All projects, including the third-party groups (default). |
| View Application Projects Only | Your projects, without third-party code. |
| View Namespaces | All namespaces, including third-party ones. |
| View Application Namespaces Only | The namespaces of your code. This is the view used in most screenshots of this page. |
Triangularize
Click Triangularize (2) to reorder the rows and columns so that most dependencies fall on one side of the diagonal. Elements used by many others move to one end, elements that use many others to the other end: the order becomes the layering of your code. What remains on the wrong side of the diagonal, and every red cell, is a layering violation or a cycle.

Use Undo (5) to go back to the previous order.
Remove menu

| Item | Effect |
|---|---|
| Remove Empty Rows and Columns | Removes every row and column without any dependency. |
| Remove Empty Columns | Removes only the empty columns. |
| Remove Empty Rows | Removes only the empty rows. |
| Remove Rows with third-party code elements | Keeps only your code on the rows. |
| Remove Rows with application code elements | Keeps only third-party code on the rows: useful to see which libraries are used. |

Swap menu
Available once the rows and columns differ, for example after opening a dependency.

| Item | Effect |
|---|---|
| Swap Headers | The rows become the columns and the columns become the rows. |
| Copy Vertical Headers to horizontal Header | The columns get the same elements as the rows. |
| Copy Horizontal Headers to Vertical Header | The rows get the same elements as the columns. |

Weight: what the numbers count

| Weight | The number in a cell is |
|---|---|
| Direct & indirect depth of use | How far apart the two elements are in the chain of uses: 1 for a direct use, more through other elements. |
| Direct: # namespaces | The number of namespaces used. |
| Direct: # types | The number of types used. |
| Direct: # members | The number of members (methods and fields) used. This is the default. |
| Direct: # methods | The number of methods used. |
| Direct: # fields | The number of fields used. |
The two buttons after the menu (13, 14) choose between Direct dependencies and Direct and Indirect dependencies. With indirect dependencies, an element that reaches another one through intermediate elements also gets a cell.
Hovering a cell
With the bulb (17) on, hovering a cell shows a details card:

cli and anonymous_namespace{cppcheckexecutor.cpp} use each other.- The row and the column of the cell are highlighted with a golden band, and the cell gets a golden border.
- Golden labels give the full names of the row element and of the column element.
- The card shows both elements with their LOC, Debt, Rating (A to E) and MI (maintainability index).
- Between them, a sentence states the dependency: has dependency cycle with for a red cell, uses N member(s) from otherwise. The arrow shows the direction.
- The footer reminds the actions: Double Click Show Dependencies Details, Right Click Advanced Actions.

Right-click menu of a cell

| Item | What it does |
|---|---|
| Build a Graph made of Code Elements involved in this dependency | Opens the Call Graph with the elements that create the dependency. |
| Open this dependency (bold: same as double-click) | Opens a new matrix with the children of the two elements, to see exactly which types or members are involved. |
| Open this dependency (keep only involved dependencies) or Open this cycle (keep only involved dependencies) on a red cell | Same, but keeps only the elements that take part in the dependency or the cycle. |
| Edit a code query that matches this dependency | Opens Code Quest with a generated CQLinq query that selects the elements of the dependency. |
| Generate a code rule that warns if this dependency exists | Creates a rule that reports an issue while the dependency exists. Use it to forbid a dependency that breaks your architecture, and enforce it with quality gates in CI. |
Open this dependency
On the cell where anonymous_namespace{programmemory.cpp} uses 16 members from ValueFlow, Open this dependency shows the types behind it: assign and Executor on the rows, the ValueFlow types (Value, Value+Bound, Value+ValueType...) on the columns.

Edit a code query that matches this dependency
Code Quest opens a Generated Query tab. For the cycle cell above, the query selects the namespaces that use or are used by anonymous_namespace{cppcheckexecutor.cpp} at depth 1, and returns 2 namespaces. Edit it, run it, or save it as a rule.

Export menus

| Item | Opens in the Call Graph |
|---|---|
| Export Elements To Graph | All the elements of the matrix. |
| Export Horizontal Header To Graph | The elements of the columns. |
| Export Vertical Header To Graph | The elements of the rows. |
The camera button (8) saves the matrix as a PNG image, for a report or a design review.
Show a query result in the matrix
In Code Quest, run a query that returns code elements, then open Export above the result grid:
| Item | Result |
|---|---|
| Export to matrix | The result elements on both rows and columns: how they depend on each other. |
| Export to matrix rows | The result elements on the rows only. |
| Export to matrix columns | The result elements on the columns only. |
Then use Remove Empty Rows and Columns to keep the elements that really depend on each other, and Triangularize to order them.
Recipes
| Question | Steps |
|---|---|
| Which namespaces are in a cycle? | View › View Application Namespaces Only, Triangularize, look for red cells and red frames. |
| What creates this cycle? | Right-click the red cell › Open this cycle (keep only involved dependencies). |
| Is my layering respected? | Triangularize; cells left on the wrong side of the diagonal are upward dependencies. |
| Forbid a dependency | Right-click the cell › Generate a code rule that warns if this dependency exists. |
| Which libraries does my code use? | View Namespaces, then Remove › Remove Rows with application code elements. |
| Make a big matrix readable | Remove Empty Rows and Columns, Zoom Out, collapse groups with the − boxes. |
| See it as a diagram | Export to Graph › Export Elements To Graph. |
Related pages
- Call Graph: the same dependencies as boxes and arrows.
- Code Map (Treemap): size and quality of the elements.
- Analyze your first project.
Thanks for your feedback. Tell us more or request a feature.
