Analyzing a Codebase Over Time
At Logikcull, we’ve been in the midst of a react migration for over 4 years now (soon after I joined in 2019). I wanted to share a cool idea I had to visualize the progress over time.
It’s great if companies store metrics in chart tools like grafana or datadog which can easily be referenced. We didn’t do anything like this for the progress of the react vs backbone migration. But in this case, we could just leverage git to check out the codebase at different points in time!
I wanted a way to count the lines of code of legacy (backbone.js) code, versus react. These are conveniently stored in 2 separate directories, which makes this an easy comparison. The open source library
cloc helped here! As the name implies, it specializes at counting lines of code 🙂.
Then, the idea is to checkout the git repository at different points in time, and run
cloc at each interval. For my comparison, I wanted to look at 4 years of time, with weekly check-ins (208 weeks total). You write this in whatever language
you ask ChatGPT for you feel most comfortable in - here’s what a Node script I wrote looks like:
The script in summary does the following:
- Checks out repo at different weekly intervals in the past, using the
clocon codebase and output relevant results to a csv (we needed to exclude certain directories of auto-generated code which could skew the results)
We can then visualize the progress by creating a chart from the csv!