How to Understand Unfamiliar Code with a Call Graph
Use call graphs to map who calls what in JavaScript, TypeScript and Python code, find entry points and dead code, and read the results with care.

How to Understand Unfamiliar Code with a Call Graph
Opening a new codebase can feel like walking into a city without a map. Files are named sensibly, functions look reasonable, but the important question, how does a request travel through all this, is hard to answer by reading files one after another. A call graph is that map: functions as nodes and calls as arrows. This guide explains how call graphs are built, how to read one, and how to use it for reviews and refactoring, with the Code Call Graph Visualizer as the example.
Static and dynamic call graphs
A dynamic call graph is recorded while the program runs, for example by a profiler; it is accurate for the paths that were executed and blind to everything else. A static call graph is built by reading source code; it covers every path the analyser can see, but has to guess where the code is dynamic. Quick text-based tools sit at the light end of static analysis: they find function definitions and call expressions by pattern and link them by name. That is fast and language-agnostic enough for JavaScript, TypeScript and Python, and good enough for orientation.
What counts as a function
In JavaScript and TypeScript, functions come in several forms: function declarations, arrow functions assigned to constants, function expressions and class methods. In Python, def blocks inside modules and classes. A useful analyser recognises all of them and attributes each call to the innermost function that contains it, so a helper defined inside another function gets its own node. Code at the top level of a file, which often wires things together, deserves its own node too.
Reading the layers
Laying out the graph by call depth makes it readable. Entry points sit at the top: functions nobody else in the loaded files calls, such as route handlers, exported APIs or main. Each row below is one more step away. Arrows that point back up indicate recursion or a cycle between functions, which is worth a second look: sometimes intentional, sometimes a sign of tangled responsibilities.
Practical uses
- Onboarding: load the folder for one feature and follow the path from its entry point.
- Code review: check what else a changed function is called from before approving.
- Refactoring: find functions with many callers (risky to change) and leaves with none (easy to move).
- Dead code hunting: functions with no callers are candidates, but verify before deleting.
- Documentation: export a focused graph as Mermaid or Graphviz and add it to the README.
Focus is the key feature
Whole-project graphs quickly turn into hairballs. Focusing on one function answers the real questions. "What does checkout reach?" shows the downstream tree you might break. "What reaches charge?" shows every path into the payment code, which is exactly what a security reviewer wants to see. Hiding top-level code and external calls reduces the noise further.
Imports tell a second story
Import statements show dependencies between modules rather than functions. A file that imports from many others is a coordinator; a file imported by many is shared infrastructure. Circular imports between two files are a common source of subtle bugs in both JavaScript and Python. Looking at imports and calls together tells you whether the module boundaries match how the code actually behaves.
Where name-based analysis goes wrong
Because names are matched as text, a few patterns mislead:
- Two different functions with the same name in different files may be joined.
- Method calls like user.save() link to any function named save, whatever the object type.
- Callbacks passed as values, decorators, dependency injection and reflection (getattr, eval) are invisible.
- Functions called only from files you did not load look unused.
Knowing these limits turns the graph from a source of false certainty into a useful set of hints. When a precise answer matters, use the language's own tooling: TypeScript's find-all-references, a Python type checker or an IDE call hierarchy.
A routine for a new codebase
- Pick one user-facing feature and collect its files.
- Load them and find the entry point at the top of the graph.
- Focus on it and follow the downstream tree, reading each function as you go.
- Note functions with many callers and any cycles.
- Export the focused graph and keep it with your notes.
Limits
A text-based call graph is a map for reading code, not proof of behaviour. It does not resolve types, follow dynamic calls or see code outside the files you add, and it may over-connect functions that share a name. Confirm important conclusions, especially before deleting code that looks unused.



