At a Glance: Source Code Analysis with Git and IntelliJ
- Git is an underrated tool for source code archaeology: hotspots, churn, the bus factor, and logical coupling can all be derived from the commit history using built-in features.
- Hotspots often account for only 1–3% of the codebase but attract a disproportionately large share of development activity. These files are therefore the first point of inspection.
- The bus factor shows how much knowledge is concentrated in the hands of just a few people. Commit messages provide the “why” behind changes, provided they are maintained in a meaningful way.
- In IntelliJ, the Dependency Structure Matrix (DSM), UML diagrams, Call Hierarchy, data flow analysis, and “Annotate with Git Blame” help you understand architecture and dependencies. The DSM requires IntelliJ Ultimate.
- Tools provide maps; interpretation remains the team’s responsibility. Source code archaeology is an ongoing mindset, not a one-time action.
In Part 2 of the series, we introduced you to many common tools for source code archaeology. It became clear that each tool has its own strengths and weaknesses and can therefore be applied individually to different problems and questions. So it’s not about using a single tool—often, different tools complement each other and thus maximize the overall benefit.
In addition to commercial solutions, however, there are also tools that many of you already use in your system environment and that therefore require no additional integration effort.
In this blog post, we’ll take a look at how you can use Git and IntelliJ as effective analysis tools for source code archaeology to analyze complex source code. Here are the topics we’ll cover:
- Historical Analysis with Git: Git serves as the project’s memory to identify hotspots, error-prone files, churn rates, and the bus factor.
- Structural analysis with IntelliJ: The Dependency Structure Matrix (DSM) and UML diagrams immediately reveal cyclic dependencies and “god classes.”
- Understanding Control and Data Flow: Call hierarchy and data flow analyses help trace the path of data and business logic through complex layers.
The Built-in Toolkit at a Glance
| Goal / Problem | Method / Tool |
|---|---|
| Find error-prone files (hotspots & code churn) | Git |
| Uncover knowledge silos (bus factor) | Git |
| Identify hidden dependencies (logical coupling) | Git |
| Untangle architecture & spaghetti code | IntelliJ (Dependency Structure Matrix/UML) |
| Understanding call hierarchies | IntelliJ (Call Hierarchy) |
| Deciphering the origins and paths of values | IntelliJ (Data Flow Analysis/Analyze Data Flow) |
| Tracing the history of individual lines | IntelliJ/Git (Annotate with Git Blame/Show History) |
| Reducing Cognitive Load & Staying on Track | IntelliJ (Structure Window/Quick Definition/Bookmarks) |
How Can You Analyze Source Code Using Built-in Tools Like Git?
With just a few commands, Git provides initial insights into hotspots, churn, bus factor, and logical coupling—all of which you can glean directly from the commit history.
Hotspots and Code Churn: Identifying Error-Prone Files Using Git
Before we bring out the big guns on our code, we’d first like to introduce a built-in tool that every developer can use right away—provided, of course, that Git is used for version control.
For example, Git can be used to determine which files have been modified most frequently (hotspots). The following command displays the 20 most frequently modified files, including the number of changes made to each. Since this picture can quickly become skewed by older, long-completed development phases in long-running projects, you can limit the time range of the command using --after=<date> or --before=<date> to get a more meaningful picture.
And where changes occur frequently, errors often arise as well. Adam Tornhill describes in Software Design X-Rays (2018) that hotspots often account for only 1–3% of the codebase, yet they attract a disproportionately large share of development activity. Areas that are both frequently modified and highly complex are of particular interest.
Git can also be used to determine the volatility (code churn) of files. The following command sums the added and deleted lines per file over the optional time range and displays the 20 files with the highest churn values:
A high churn rate for a file, like the change rate, is an indicator of a high error rate. As early as 2005, Microsoft Research demonstrated using Windows Server 2003 as an example that this metric is highly likely to identify error-prone modules.
Beyond the raw numbers, commit messages in particular offer valuable insights into the history and context (the “why”) of code changes. They explain the motivation or technical requirement behind a modification. However, this requires that the team maintain meaningful commit messages and avoid generic terms. References to additional documentation, such as Jira tickets, further support this process.
How can the bus factor be determined using Git?
The bus factor—the minimum number of team members whose absence would bring a project to a standstill—can be determined from the commit history by analyzing who is responsible for the most lines of code in the current version. In source code archaeology, this metric helps identify risky knowledge silos early on. The following command can be used to determine the distribution of code authors directly in the terminal:
This identifies the people whose contributions are most heavily represented in the current code—and thus also those who understand it best. If this person becomes unavailable, a corresponding knowledge risk arises. Since it’s entirely possible that the same author may check in under different names, it may be necessary to merge the names by first generating a mail map file as described here:
After manually adjusting this list—so that each person is represented by exactly one canonical line—the file must be saved under the name .mailmap in the repository’s root directory. From that point on, Git automatically applies it to blame, log, shortlog, and other commands.
Logical Coupling: Identifying Hidden Dependencies in the History
In addition to the bus factor, Git can also provide the raw data for logical coupling, since files that are frequently modified together have a high degree of coupling. With
the modified (modified, added, deleted) files are listed for each commit. While it’s still possible to manually identify where coupling exists over a short period of time or in a small codebase with few commits, additional tools are needed to extract these couplings when there are many commits.
With these and other commands, Git thus proves to be an excellent tool for gaining an initial insight into a codebase. It not only shows what has happened in the past but also allows you to draw conclusions about where vulnerabilities may be hidden. For example, CodeScene uses precisely this kind of Git log data as the basis for its analyses, while other tools such as CodeCharta automatically apply relevant metrics using their built-in Git log parser.
For those who want to delve deeper into the topic, we recommend Adam Tornhill’s “Your Code as a Crime Scene”. The book is considered the cornerstone of so-called Behavioral Code Analysis—an approach that examines code not only structurally but also based on its history (commits, frequency of changes, authors).
Structural Code Analysis with IntelliJ: Understanding Architecture and Data Flows
IntelliJ shows you architecture, call chains, and data flows directly within the IDE, without requiring any additional tools.
The Git history provides initial clues about error-prone areas of code and reveals the why behind all past changes. But to understand how the application works right now, we need to dig a little deeper: into the structure, the call history, and the data flow. You don’t need any external extensions for this either. IntelliJ comes equipped out of the box with an excellent set of features and tools to thoroughly examine existing applications.
Uncovering Architecture and Spaghetti Code: Dependency Structure Matrix (DSM) and UML
Using the Dependency Structure Matrix and UML diagrams in IntelliJ, you can immediately identify cyclic dependencies and “God” classes. If you’re faced with a large, sometimes confusing legacy system, you shouldn’t even try to read it line by line right away. Instead, a successful analysis starts at the architectural level. With an IntelliJ Ultimate subscription and the “Dependency Structure Matrix” (DSM) plugin developed by JetBrains, you can generate the Dependency Structure Matrix for the entire codebase via the Code → Analyze Code → Dependency Matrix menu. This matrix displays modules and packages in a square grid and maps all dependencies between them at the package and class levels.
The particular benefit of the DSM lies in its ability to immediately expose poor architectural patterns: Cells marked in red indicate cyclic dependencies, where components depend on one another in a loop: the classic structures that developers often refer to as spaghetti code. In addition, so-called “God classes” can be identified at a glance, as they stand out from the grid as rows or columns with extremely high numbers. This saves hours of manual research when trying to pinpoint the project’s architectural weaknesses.
Furthermore, the DSM actively supports refactoring efforts: Since the effects of dependencies can be visualized, you can immediately see which classes are potentially affected by a change. It thus serves not only as a diagnostic tool but also as a basis for decision-making to gradually reduce coupling and sustainably improve maintainability.
To make our application visually tangible in the next step, IntelliJ offers the Diagrams plugin. With a simple right-click on a class or package in the project tree and the selection of Diagrams → Show Diagram, the IDE generates an interactive UML diagram on the fly. The main benefit is the ability to gain an abstract overview of complex structures: At a glance, we can see deeply nested inheritance hierarchies, which implementations actually exist, and which classes are surprisingly tightly coupled with one another. Using the diagram, you can selectively show or hide the visibility of fields or methods to focus purely on the relationships without being distracted by lines full of implementation details.
How do you analyze call hierarchies using the Call Hierarchy?
You start at business entry points such as REST endpoints or listeners and trace the calls using the Call Hierarchy.
When analyzing call hierarchies, the choice of entry point is crucial. While developers often intuitively turn to the main method or technical startup listeners, these are usually not very productive for source code archaeology, as they merely initialize the infrastructure but hardly represent any business logic.
Which entry point is the right one depends heavily on the application’s architecture. In web applications, REST endpoints (e.g., @GetMapping or @PostMapping) form the business interfaces, while in event-driven systems, listeners such as @JmsListener or @KafkaListener serve as entry points. For batch systems or background processes, on the other hand, it’s worth analyzing @Scheduled methods or queue consumer logic.
To find these business entry points, the “Search Everywhere” function (press Shift twice) helps you search specifically for annotations. Once such a business endpoint is found, you can open the Call Hierarchy using the keyboard shortcut Ctrl + Alt + H (Windows/Linux) or ⌥^H (macOS). This allows you to precisely trace the actual data flow—for example, from the controller through the service to the repository.
The advantages of the Call Hierarchy are obvious:
- Impact analysis: Before changing or removing a method, you can immediately see who calls it and what side effects might occur.
- Understanding control flow: Complex call chains become transparent without having to manually jump through the code.
- Faster navigation: It allows you to jump directly to the caller or the called method of a call, which massively speeds up navigation in large, unfamiliar codebases.
Data Flow Analysis in IntelliJ: Deciphering the Origins and Paths of Values
With “Analyze Data Flow to/from Here”, you can see which code paths set a value and where it is passed on. While the call hierarchy illuminates the control flow of methods, the “Analyze Data Flow to/from Here” feature helps you understand the actual path data takes through the application. Right-clicking on a variable or parameter allows you to analyze which code paths set the value (to here) or where the value is passed after assignment (from here). Especially in legacy systems, where states are passed across many layers, this is a great help in deciphering the origin or usage of complex data structures without having to manually trace the entire history.
Trace the history of individual lines of code with git blame
With git blame—integrated into IntelliJ as “Annotate with Git Blame” - you can see, for each line, who changed it and when, and use “Show History for Selection” to view the evolution of a section.
To trace the evolution of the code directly in the editor, IntelliJ offers a version control integration. By right-clicking on the editor margin (gutter) and selecting the appropriate option for Git analysis (“Annotate with Git Blame”), you can immediately see who changed each line and when. This helps you immediately identify the person with the relevant expertise without having to search external systems. Often, the associated commit messages also provide the necessary context to understand complex or illogical implementations. If you’re interested in a specific section or method rather than the entire file, you can use the “Show History for Selection” to focus on that area. This hides changes to other parts of the file and shows precisely how that specific business logic has evolved over time.
Reducing Cognitive Load in Large Classes: Navigation and Bookmarks
With the Structure Window, Quick Definition, and bookmarks, you can find relevant sections without having to scroll for a long time. Especially in large classes, an abundance of details often makes it difficult to understand the essential logic. The Structure Window (Structure Window) provides a clear summary of all methods and fields in a file, allowing you to quickly navigate to relevant sections without having to scroll for a long time.
In addition, the Quick Definition (Quick Definition) lets you display the contents of a method or class directly at your current location in a small window. This allows you to look up definitions without leaving the current context in the editor or having to switch between different files.
Bookmarks (Bookmarks) are equally helpful for navigation. They allow you to mark important or frequently visited sections of the code so you can quickly return to them at any time without having to navigate through the entire project structure again. You can set a bookmark using the keyboard shortcut F11 (Windows/Linux) or F3 (macOS). The list of all set bookmarks can be accessed with Shift + F11 (Windows/Linux) or Cmd + F3 (macOS).
In summary: IntelliJ is far more than just a tool for writing code. It is a powerful toolkit for source code archaeology. By using the IDE as an analysis platform, we transform static files into a living model of the application that helps us navigate the “code jungle.” But despite all the support these tools provide, the decisive factor always remains human curiosity. The tools give us the maps, but in the end, we must interpret and understand the structure of the system ourselves. With this toolkit at our disposal, we are now well-equipped not only to navigate even the deepest legacy structures but also to untangle them step by step.
Conclusion: Why Git and IntelliJ Are Sufficient for Effective Source Code Diagnosis
The historical perspective provided by Git and the structural perspective provided by IntelliJ together offer a robust picture of the system. In this post, we’ve seen that effective source code archaeology isn’t a matter of complex, specialized tools, but rather a matter of perspective. The real strength lies in the combination of two complementary perspectives that we already have on our computers every day:
- The historical perspective (Git): It acts as our memory. It shows us where the problematic areas in the code lie, where technical debt accumulates, and who possesses the most implicit knowledge.
- The structural perspective (IntelliJ): It’s our X-ray machine for the current state. It helps us untangle architectural nodes, visualize dependencies, and trace the data flow.
Both approaches allow us to work on a legacy system not just “blindly,” but by starting with a well-founded diagnosis. The findings help us identify the areas where maintenance effort or the risk of changes are particularly relevant to the business. In the next part of this blog series, we’ll examine relationships across many classes and components and show how they can be queried specifically as a graph. Source code archaeology is not a one-time event, but rather an ongoing mindset in software development. So start using your daily tools—Git and your IDE—specifically for analysis. The answers to your architectural questions are often right in front of you. You just have to bring them to light in a targeted way.
Sources & References
- The screenshots used in this blog post are based on the Spring PetClinic repository (https://github.com/spring-projects/spring-petclinic), which is published under the Apache License 2.0.
- Adam Tornhills, Your Code as a Crime Scene
The “Source Code Archaeology” Blog Series
- Part 1_ Fundamentals & Business Perspective: – What source code archaeology achieves and why the most reliable way to modernize legacy systems begins with understanding the existing business logic and the technical state of the application.
- Part 2: The Tool Market – Which tools exist in the field of source code archaeology and which tool is suitable for which problem.
- Part 3: Analysis with On-Board Tools – How development teams can uncover valuable system knowledge using existing standard tools without an additional budget.
- Part 4: Graph-Based Code Analysis – A comparison of conventional tools with AI-powered code graphs, and how both approaches can be combined.
(Coming November 24, 2026) - Part 5: Artificial Intelligence & Autonomy – From MCP servers to AI agents: Can generative AI soon take over source code archaeology entirely?
(Coming December 1, 2026)
More on Software Modernization
More articles in this subject area
Discover exciting further topics and let the codecentric world inspire you.
Blog authors
Sheila Ferreira Lopes
IT Consultant
Do you still have questions? Just send me a message.
Stefanie Wittram
Do you still have questions? Just send me a message.
Do you still have questions? Just send me a message.