Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

Using Graphify and NetworkX to Map Python Codebase Structure with God Nodes, Communities, and Architecture Visualizations

MarkTechPost 3 min read

Using Graphify and NetworkX to Map Python Codebase Structure with God Nodes, Communities, and Architecture Visualizations

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. . Cookie settings ACCEPT News Hub PREMIUM CONTENT Read our exclusive articles

Home Open Source/Weights AI Agents Tutorials Voice AI Robotics Newsletter → PARTNER WITH US Search Home Open Source/Weights AI Agents Tutorials Voice AI Robotics Newsletter → Partner with Us Home Editors Pick Agentic AI Using Graphify and NetworkX to Map Python Codebase Structure with God Nodes,... Editors PickAgentic AISoftware EngineeringStaffTutorials Using Graphify and NetworkX to Map Python Codebase Structure with God Nodes, Communities, and Architecture Visualizations By Sana Hassan - June 24, 2026 Add as a preferred source on Google

In this tutorial, we build a fully offline Graphify workflow that turns a realistic multi-module Python application into a knowledge graph. We start by installing Graphify and supporting graph libraries, then generate a small but connected sample application with configuration, database, authentication, service, API, cache, model, and SQL layers. We extract the graph locally using Graphify’s tree-sitter-based analysis, so we do not need an API key or any LLM backend. After loading the generated graph.json into NetworkX, we analyze the codebase’s structure using file types, relationship types, centrality scores, community detection, and shortest paths among important symbols. Also, we create both static and interactive visualizations, making it easier to understand how modules, classes, functions, and database objects connect across the project.

Installing Graphify and NetworkX COPY CODE import subprocess, sys def pip(*pkgs): subprocess.run([sys.executable, "-m", "pip", "install", "-q", *pkgs], check=False) pip("graphifyy[sql]", "pyvis", "networkx", "matplotlib") import os, json, glob, textwrap, warnings import networkx as nx import matplotlib.pyplot as plt warnings.filterwarnings("ignore")

We install Graphify along with the graph analysis and visualization libraries needed for the tutorial. We import the required Python modules, including NetworkX for graph processing and Matplotlib for static plotting. We also suppress unnecessary warnings so the notebook output stays clean and focused.

Building the Sample Codebase COPY CODE ROOT = "sample_app" os.makedirs(ROOT, exist_ok=True) FILES = { "config.py": '''

Central settings object — used everywhere (expect this to be a "god node").

class Settings: def init(self): self.db_dsn = "postgresql://localhost/app" self.jwt_secret = "change-me" self.rate_limit = 100 settings = Settings() ''', "database.py": ''' from config import settings class DatabasePool: """Connection pool. WHY: reuse sockets instead of reconnecting per query.""" def init(self, dsn): self.dsn = dsn self._conns = [] def acquire(self): return {"dsn": self.dsn} pool = DatabasePool(settings.db_dsn) def get_connection(): return pool.acquire() ''', "models.py": ''' class User: def init(self, user_id, email): self.user_id = user_id self.email = email class Session: def init(self, user, token): self.user = user self.token = token ''', "cache.py": ''' from config import settings class RateLimiter:

NOTE: naive in-memory limiter; swap for Redis in prod.

def init(self, limit): self.limit = limit self.hits = {} def allow(self, key): self.hits[key] = self.hits.get(key, 0) + 1 return self.hits[key] <= self.limit limiter = RateLimiter(settings.rate_limit) ''', "auth.py": ''' from config import settings from database import get_connection from models import User, Session def hash_password(raw): return f"hashed::{raw}" def verify_password(raw, hashed): return hash_password(raw) == hashed class AuthService: def init(self): self.secret = settings.jwt_secret def login(self, email, password): conn = get_connection() user = User(user_id=1, email=email) return Session(user=user, token=self.secret + email) ''', "services.py": ''' from database import get_connection from models import User from auth import AuthService class UserService: def init(self): self.auth = AuthService() def register(self, email, password): conn = get_connection() return User(user_id=2, email=email) def authenticate(self, email, password): return self.auth.login(email, password) ''', "api.py": ''' from cache import limiter from services import UserService from auth import verify_password svc = UserService() def signup_route(email, password): if not limiter.allow(email): return {"error": "rate limited"} return svc.register(email, password) def login_route(email, password): if not limiter.allow(email): return {"error": "rate limited"} return svc.authenticate(email, password) ''', "main.py": ''' from api import signup_route, login_route from database import pool def run(): signup_route("a@x.com", "pw") return login_route("a@x.com", "pw") if name == "main": run() ''', "schema.sql": ''' CREATE TABLE users ( user_id SERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL ); CREATE TABLE sessions ( token TEXT PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES users(user_id) ); CREATE VIEW active_sessions AS SELECT s.token, u.email FROM sessions s JOIN users u ON s.user_id = u.user_id; ''', } for name, body in FILES.items(): with open(os.path.join(ROOT, name), "w") as f: f.write(textwrap.dedent(body).lstrip()) print(f"Wrote {len(FILES)} files to ./{ROOT}/")

We create a realistic sample application with multiple Python modules and one SQL schema file. We design the files to include meaningful cross-module relationships, such as imports, function calls, service dependencies, authentication logic, database access, and rate limiting. We then write all these files to a local sample_app directory, giving Graphify a complete mini-codebase to analyze.

Extracting the Knowledge Graph COPY CODE res = subprocess.run( [sys.executable, "-m", "graphify", "extract", ROOT, "--no-cluster"], capture_output=True, text=True ) print(res.stdout[-1500:] or res.stderr[-1500:]) graph_paths = glob.glob("**/graph.json", recursive=True) assert graph_paths, "graph.json not found — check the extract output above." GRAPH_JSON = sorted(graph_paths, key=os.path.getmtime)[-1] print("Graph file:", GRAPH_JSON) def load_graphify(path): data = json.load(open(path)) ekey = "links" if "links" in data else ("edges" if "edges" in data else None) G = nx.DiGraph() if data.get("directed") else nx.Graph() for n in data.get("nodes", []): nid = n.get("id") G.add_node(nid, **{k: v for k, v in n.items() if k != "id"}) for e in data.get(ekey or "links", []): G.add_edge(e.get("source"), e.get("target"), **{k: v for k, v in e.items() if k not in ("source", "target")}) G.graph.update(data.get("graph", {})) return G G = load_graphify(GRAPH_JSON) UG = G.to_undirected() print(f"\nGraph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges") def label(n): return G.nodes[n].get("label", str(n))

We run Graphify locally on the generated application and extract the project knowledge graph without using any API key or LLM backend. We locate the generated graph.json file and load it into NetworkX using a version-proof node-link loader. We then convert the graph into an undirected form for easier structural analysis and define a helper function to display readable node labels.

Analyzing Centrality and Communities COPY CODE from collections import Counter ftypes = Counter(d.get("file_type", "?") for , d in G.nodes(data=True)) rels = Counter(d.get("relation", "?") for * , d in G.edges(data=True)) conf = Counter(d.get("confidence", "?") for *_ , d in G.edges(data=True)) print("\nNodes by file_type :", dict(ftypes)) print("Edges by relation :", dict(rels)) print("Edges by confidence:", dict(conf)) deg = nx.degree_centrality(UG) btw = nx.betweenness_centrality(UG) print("\nTop 'god nodes' by degree centrality:") for n, c in sorted(deg.items(), key=lambda x: -x[1])[:8]: print(f" {label(n):<22} deg={c:.3f} betweenness={btw.get(n,0):.3f}") try: communities = nx.community.louvain_communities(UG, seed=42) except Exception: communities = list(nx.community.greedy_modularity_communities(UG)) node_comm = {n: i for i, com in enumerate(communities) for n in com} print(f"\nDetected {len(communities)} communities:") for i, com in enumerate(communities): members = ", ".join(sorted(label(n) for n in com))[:90] print(f" Community {i}: {members}") def find(substr): for n in G.nodes: if substr.lower() in label(n).lower(): return n return None a, b = find("api"), find("DatabasePool") if a and b and nx.has_path(UG, a, b): path = nx.shortest_path(UG, a, b) print(f"\nPath {label(a)} -> {label(b)}:") print(" " + " → ".join(label(p) for p in path))

We analyze the extracted graph by summarizing node types, edge relationships, and confidence levels. We compute degree centrality and betweenness centrality to identify important “god nodes” that connect many parts of the application. We also detect communities in the graph and trace a shortest path between key components to understand how parts of the codebase are connected.

Visualizing the Code Graph COPY CODE plt.figure(figsize=(13, 9)) pos = nx.spring_layout(UG, k=0.7, seed=42) nx.draw_networkx_edges(UG, pos, alpha=0.25) nx.draw_networkx_nodes( UG, pos, node_color=[node_comm.get(n, 0) for n in UG.nodes], node_size=[300 + 4000 * deg.get(n, 0) for n in UG.nodes], cmap=plt.cm.tab20, alpha=0.9, ) top = {n for n, _ in sorted(deg.items(), key=lambda x: -x[1])[:14]} nx.draw_networkx_labels(UG, pos, {n: label(n) for n in top}, font_size=8) plt.title("Graphify knowledge graph — size=centrality, color=community") plt.axis("off"); plt.tight_layout() plt.savefig("graph_static.png", dpi=130); plt.show() try: from pyvis.network import Network net = Network(height="650px", width="100%", bgcolor="#111", font_color="white", notebook=True, cdn_resources="in_line", directed=G.is_directed()) palette = ["#e6194B","#3cb44b","#4363d8","#f58231","#911eb4", "#42d4f4","#f032e6","#bfef45","#fabed4","#469990"] for n, d in G.nodes(data=True): c = node_comm.get(n, 0) net.add_node(n, label=label(n), title=f"{d.get('file_type','?')} · {d.get('source_file','')}", color=palette[c % len(palette)], size=12 + 60 * deg.get(n, 0)) for s, t, d in G.edges(data=True): net.add_edge(s, t, title=d.get("relation", "")) net.save_graph("graph_interactive.html") print("\nSaved interactive graph -> graph_interactive.html") from IPython.display import HTML, display display(HTML(open("graph_interactive.html").read())) except Exception as e: print("Interactive viz skipped:", e) for cmd in ( ["query", "what connects auth to the database?", "--graph", GRAPH_JSON], ["path", "AuthService", "DatabasePool", "--graph", GRAPH_JSON], ["explain", "RateLimiter", "--graph", GRAPH_JSON], ): print("\n$ graphify " + " ".join(cmd)) r = subprocess.run([sys.executable, "-m", "graphify", *cmd], capture_output=True, text=True) print((r.stdout or r.stderr)[:1200]) print("\nDone. Artifacts: graph_static.png, graph_interactive.html,", "and graphify-out/ (graph.json, GRAPH_REPORT.md).")

We visualize the knowledge graph using both static and interactive methods. We first create a Matplotlib graph where node size represents centrality and node color represents community membership. We then build an interactive Pyvis visualization and run Graphify’s CLI commands to query the graph, find paths, and explain selected symbols.

Conclusion

In conclusion, we have a complete local pipeline for converting source code into a useful knowledge graph and studying it with graph analytics. We saw how Graphify extracts meaningful relationships from a Python and SQL codebase, and we use NetworkX to identify central “god nodes,” detect communities, and trace paths between components such as authentication and database logic. We also generated visual outputs that help us inspect the architecture from both a high-level and interactive perspective. This workflow gives us a pathway to reason about code structure, dependency flow, architectural hotspots, and cross-file connections without relying on external APIs, making it useful for codebase exploration, documentation, refactoring, and software architecture analysis.

Check out the Full Codes here. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

Sana Hassan

  • posts

Sana Hassan, a consulting intern at Marktechpost and dual-degree student at IIT Madras, is passionate about applying technology and AI to address real-world challenges. With a keen interest in solving practical problems, he brings a fresh perspective to the intersection of AI and real-life solutions.

TINYFISH.AI OPEN SOURCE BigSet Describe your ideal dataset in plain English, and BigSet builds it. DATASET.BUILD() AUTO·REFRESH ✓ ✓ ✓ ✓ Explore on GitHub → Previous article Nous Research Adds /learn to Hermes Agent’s Skills System, Capturing Workflows as Slash Commands Without Hand-Writing SKILL.md RELATED ARTICLESMORE FROM AUTHOR Nous Research Adds /learn to Hermes Agent’s Skills System, Capturing Workflows as Slash Commands Without Hand-Writing SKILL.md 16 Best Generative AI Coding Tools in 2026 Compared: Features, and Best Fit DFlash Speculative Decoding Drafts Whole Token Blocks in Parallel for Up to 15x Higher Throughput on NVIDIA Blackwell Mistral OCR 4 Brings Citation-Ready Structured Output to RAG, Agentic, and Enterprise Search Pipelines Datalab Releases lift: A 9B Open-Weights Vision Model That Extracts Structured JSON From PDFs Using Schemas How to Use NVIDIA Canary-1B-v2 for ASR, Translation, and Automatic SRT Subtitle Export in Python Nous Research Adds /learn to Hermes Agent’s Skills System, Capturing Workflows as Slash Commands... Asif Razzaq - June 24, 2026 0 Nous Research has added /learn to the Hermes Agent Skills System. The command authors a standards-compliant SKILL.md from a local directory, a doc URL, a past conversation, or pasted notes. The live agent sources the material with its own tools, then writes the skill — no hand-writing and no separate ingestion engine. Here is how it works, where it fits, and what to review before trusting the output. 16 Best Generative AI Coding Tools in 2026 Compared: Features, and Best Fit Michal Sutter - June 24, 2026 0 Generative AI has reshaped how software gets built. What began as line-by-line autocomplete now spans full application generation, multi-agent build pipelines, and natural-language interfaces... DFlash Speculative Decoding Drafts Whole Token Blocks in Parallel for Up to 15x Higher... Asif Razzaq - June 24, 2026 0 UC San Diego's DFlash replaces autoregressive drafting with a lightweight block diffusion model for speculative decoding. It drafts whole token blocks in a single forward pass and conditions on target hidden features through KV injection. The paper reports up to 6.08x lossless speedup on Qwen3-8B, while NVIDIA reports up to 15x throughput on Blackwell at fixed interactivity. DFlash ships 20 checkpoints and supports SGLang, vLLM, and TensorRT-LLM. Mistral OCR 4 Brings Citation-Ready Structured Output to RAG, Agentic, and Enterprise Search Pipelines Asif Razzaq - June 23, 2026 0 Mistral AI released OCR 4 on June 23, 2026, moving from clean text extraction to structured document output. Each block returns a bounding box, a typed classification, and per-page and per-word confidence scores. The model supports 170 languages, runs in a single self-hosted container, and feeds citation-ready inputs into RAG, agentic, and enterprise search pipelines through one API endpoint. Datalab Releases lift: A 9B Open-Weights Vision Model That Extracts Structured JSON From PDFs... Asif Razzaq - June 23, 2026 0 Datalab released lift, a 9B open-weights vision model that turns PDFs and images into schema-matching JSON. It uses schema-constrained decoding for valid structure and trained abstention to return null instead of hallucinating absent fields, scoring 90.2% field accuracy on a 225-document benchmark. How to Use NVIDIA Canary-1B-v2 for ASR, Translation, and Automatic SRT Subtitle Export in... Sana Hassan - June 23, 2026 0 In this tutorial, we build a multilingual ASR and speech translation pipeline with NVIDIA Canary-1B-v2. We load the model on a GPU-enabled runtime, prepare audio into 16 kHz mono, and run English ASR. We then translate speech into French, German, Spanish, and Italian, and extract word and segment timestamps. We export translated subtitles as an SRT file, test long-form transcription, run batch processing, and benchmark inference speed. Prime Intellect Releases prime-rl 0.6.0 to Train Trillion-Parameter MoE Models on Agentic RL Workloads Asif Razzaq - June 23, 2026 0 Prime Intellect has released prime-rl 0.6.0, an open framework for asynchronous reinforcement learning on trillion-parameter Mixture-of-Experts models. It trained GLM-5 on SWE tasks at up to 131k sequence length, with sub-5-minute step times and 256 rollouts, on 28 H200 nodes. This breakdown covers the inference and training optimizations behind those numbers — FP8 inference, Wide Expert Parallelism, prefill/decode disaggregation, router replay, and 3-D parallelism (FSDP, EP, CP). GLM-5.2 OpenAI-Compatible API: A Hands-On Guide to Reasoning Effort, Function Calling, and Long-Context Retrieval Sana Hassan - June 22, 2026 0 We build a practical GLM-5.2 workflow using its hosted, OpenAI-compatible API instead of running the model locally. We set up multiple providers, load the API key securely, and create a reusable chat wrapper. We then test thinking-effort control, streamed reasoning, function calling, a tool-using agent, structured JSON output, and long-context retrieval. We close with token and cost accounting so every demo stays measurable. xAI Launches /goal in Grok Build, Adding Long-Running Autonomous Execution With Built-In Verification for... Michal Sutter - June 22, 2026 0 xAI introduced /goal in Grok Build, a mode for long-running, autonomous task execution. You hand off one objective, and the agent plans an approach, executes a progress checklist, and verifies the result until the goal completes. Sakana AI Launches Sakana Fugu: An Orchestration Model That Routes Tasks Across a Swappable... Asif Razzaq - June 22, 2026 0 Fugu and Fugu Ultra route tasks across a swappable model pool, leading most coding, reasoning, and agentic benchmarks. TINYFISH.AI OPEN SOURCE BigSet Describe your ideal dataset in plain English, and BigSet builds it. DATASET.BUILD() AUTO·REFRESH ✓ ✓ ✓ ✓ Explore on GitHub →

miniCON Event 2025 Download Privacy & TC Cookie Policy Newsletter Partnership and Promotion © Copyright Reserved @2025 Marktechpost AI Media Inc

React