Codebase Visualization
This guide will show you how to create codebase visualizations using codegen.
Blast radius visualization of the `export_asset` function. Click and drag to pan, scroll to zoom.
Overview
To demonstrate the visualization capabilities of the codegen we will generate three different visualizations of PostHog’s open source repository.
Call Trace Visualization
Visualizing the call trace of a function is a great way to understand the flow of a function and for debugging. In this tutorial we will create a call trace visualization of the patch
method of the SharingConfigurationViewSet
class. View the source code here.
Basic Setup
First, we’ll set up our codebase, graph and configure some basic parameters:
Building the Visualization
We’ll create a function that will recursively traverse the call trace of a function and add nodes and edges to the graph:
Adding Edge Metadata
We can enrich our edges with metadata about the function calls:
Visualizing the Graph
Finally, we can visualize our call graph starting from a specific function:
Take a look
View on codegen.sh
Common Use Cases
The call graph visualization is particularly useful for:
- Understanding complex codebases
- Planning refactoring efforts
- Identifying tightly coupled components
- Analyzing critical paths
- Documenting system architecture
Function Dependency Graph
Understanding symbol dependencies is crucial for maintaining and refactoring code. This tutorial will show you how to create visual dependency graphs using Codegen and NetworkX. We will be creating a dependency graph of the get_query_runner
function. View the source code here.
Basic Setup
We’ll use the same basic setup as the Call Trace Visualization tutorial.
Building the Dependency Graph
The core function for building our dependency graph:
Visualizing the Graph
Finally, we can visualize our dependency graph starting from a specific symbol:
Take a look
View on codegen.sh
Blast Radius visualization
Understanding the impact of code changes is crucial for safe refactoring. A blast radius visualization shows how changes to one function might affect other parts of the codebase by tracing usage relationships. In this tutorial we will create a blast radius visualization of the export_asset
function. View the source code here.
Basic Setup
We’ll use the same basic setup as the Call Trace Visualization tutorial.
Helper Functions
We’ll create some utility functions to help build our visualization:
Building the Blast Radius Visualization
The main function for creating our blast radius visualization:
Visualizing the Graph
Finally, we can create our blast radius visualization:
Take a look
View on codegen.sh
What’s Next?
Was this page helpful?