DEV Community

Alan Potter
Alan Potter

Posted on

2

Using a Graph Database for Better Understanding of Unfamiliar Code

Like Dustin, I worked on a project for the AppLand Hackathon. I was particularly interested in understanding how to make the visualizations generated from recordings in AppMaps easier to understand.

The basic structure of code can be somewhat hidden by its use of trivial helper classes. Theses are classes with simple functions (getters, setters, predicates, etc) that don't use other classes. I wanted to see if there was a way to use a graph database to help identify such classes in an unfamiliar code base.

I put together a simple JavaScript program that uses the CallTree class from the AppMap model code to a graph in a Neo4j database. For each function in the call tree, it creates a node for the class that contains the function. It creates an edge from that class to the classes containing each of the functions called.

Once that's in place, a cypher query shows all the "leaf" classes, i.e. those that don't call methods in other classes:

MATCH(n)
WHERE NOT (n)-[:CALLS]->()
RETURN n 
ORDER BY n.defined_class 
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

This query returns 10 classes that don't have a CALLS relationship with any other classes.

These are the simple classes I was looking for, and excluding them from AppMaps definitely improved the visualizations.

You can read more about my Hackathon project here, and check out the code, too.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay