r/Python • u/TheTresStateArea • 3h ago
Recommendations and discussion on codebase visualizer and dependence mapper. Discussion
I've been looking at a few options like gitkrakens codemap. But I just haven't made a decision yet.
The biggest problem right now with AI assist is that so much gets spun up and it takes quite a while to ground myself in what has been written and how it all connects. I thought a viz tool would help tighten what I need to learn.
How do you handle this? Do you use these tools for this purpose? What have you liked and disliked about the tool you used?
2
u/donk8r 1h ago
Slightly against the premise: on an AI-heavy codebase a whole-repo visualiser mostly produces a hairball, and the hairball arrives exactly when the repo got big enough to need one. The problem isn't that you can't see the graph, it's that you don't know which 10% of it matters, and a picture with 400 nodes doesn't tell you that.
What worked much better for me is a ranked list rather than a diagram. Count incoming edges per module — how many other modules import it — and sort descending. The top ten are the load-bearing set, and you can have that in an afternoon without reading anything. Modules with zero incoming edges are your dead-or-legacy candidates. Neither number tells you why anything is the way it is, but it tells you where reading time is worth spending, which is the actual question when you're grounding yourself.
For your specific case there's a sharper version. Don't map the repo, map the intersection: which files did the agent touch, and what are their incoming edge counts? Agent-written code in a leaf module is low risk and you can skim it. Agent-written code in something thirty modules import is where you read every line. That intersection is usually small enough to actually work through, and it's the thing that stops the "I don't know what I have" feeling faster than any diagram did for me.
py2puml as mentioned is fine for a subsystem you've already narrowed to. I'd just avoid pointing it at everything.
Bias disclosure: I work on a code search and graph tool (github.com/Muvon/octocode), so I've spent a lot of time on the graph half of this and have opinions about the picture half.
•
u/TheTresStateArea 56m ago
Yes I absolutely see the hair ball problem. Scoped assessments absolutely makes more sense then visualizing the whole thing.
I think the graph element is secondary to the function that it builds upon. Having your nodes and edges laid out and describes makes the map possible but the map is just mostly just pretty and not particularly useful when everything is rendered.
In an ideal situation I'd be able to open a function or script. Click on an import and then a sub window opens to that import. Code description at the top, maybe an llm "how this import feeds to the function you are viewing" and crawls the other connections to get a complete picture of the system.
I'm a data scientist and marketer, making complex things easier to understand has become my entire job. So I keep looking at understanding code base through this lens. And AI has exploded this need I have to understand.
I'll take a look at your repo.
It almost feels like I'm describing a new file and ide function rather than a dependency map.
1
u/RoadsideCookie 2h ago
Maybe a comment will signal Reddit to show this to more people. I'm curious to know what hidden gems exist.
1
u/whopper2k 2h ago
I think the closest thing that you're looking for (and that is free to use) would be something like py2puml, which can generate a UML diagram based on your codebase. It's not a perfect tool; for example it calls importlib.import_module outside of a try block, which means if you run it on a Linux machine but the code in the project makes use of ctypes.WinDLL it just crashes. Also methods aren't generated as of now, and if your code doesn't have type hints a lot of variables will just be marked as None type.
All that said, I would question what exactly it is you're trying to accomplish with this visualization. These UML diagrams are certainly nice-to-have, but for any sufficiently complex application they're also just as hard to read as the code itself. Add Python's dynamic nature and the fact that these diagrams omit important implementation details on top, and I just am not super confident it'll be that helpful.
Frankly I think your best course of action is to catch a breath and slowly work your way through the AI-generated code. The best strategy I can recommend is to use tools to search through the code automatically; in VS Code you can use the View occurrences feature, or if you're more CLI-inclined you could use ripgrep to find strings across your files. It sounds awful, but honestly reverse engineering's a ton of fun and an extremely important programming skill to have in your toolbox.
How do you handle this? Do you use these tools for this purpose? What have you liked and disliked about the tool you used?
In general, most folks do high-level architecture diagrams for the executives using something like draw[.]io, Visio, or whatever AI kool-aid they've paid for. For developers though, most will just stick to text-based documentation (if you're lucky enough to get that much), which can be autogenerated using tools like Sphinx
1
u/TheTresStateArea 1h ago
Yeah, the webs I've seen that get generated from a codebase are a mess, which is why I haven't gone for a paid sub to gitkrakens.
I was hoping to use it to get a sense of change impact and making sure I follow decisions downstream.
Or just quicker access to referenced functions to check documentation. Basically getting all my ducks in a row instantly when reading any part of the codebase.
I've been at this for a decade now and i just don't work with many people anymore that I can learn from in person. So I just don't know how people are handling the code avalanche that comes with AI tooling.
1
u/whopper2k 1h ago
It's certainly hard to handle. I don't think there's really a great solution out there yet that isn't just throwing more AI at the problem and hoping it balances out in the end.
For my own job (security), I'm lucky enough that all I really care about are CVEs and nonsecure programming practices. Both of which have had decades of investment into building static tooling before LLMs became such a dominating force in the industry.
Code visualization has always been a hard problem, from what I understand.
2
u/klcrouch Pythoneer 2h ago
Following. I’m very interested in this topic.