How to Export the Code-Review Graph to Neo4j, GraphML, or Obsidian
The code-review-graph CLI exports internal dependency graphs to Neo4j Cypher scripts, GraphML XML files, or Obsidian vaults using the visualize sub-command with the --format flag.
The code-review-graph repository provides a Python-based tool for analyzing code dependencies and review patterns. Once the internal graph is built, you can export it to multiple portable formats to visualize in external tools like Neo4j Browser, Gephi, or Obsidian. All export logic resides in code_review_graph/exports.py and is exposed through the visualize command defined in code_review_graph/cli.py.
How the Export Pipeline Works
The export process follows a structured pipeline that gathers graph data and dispatches it to format-specific serializers.
-
Gather graph data – The function
export_graph_data(store)(defined ingraph.py) returns a dictionary containingnodes,edges, and optionalcommunities. -
Parse format choice – The CLI accepts a
--formatargument with specific choices. According tocode_review_graph/cli.pyaround line 790, valid choices are:choices=["html", "json", "graphml", "cypher", "obsidian", "svg"] -
Dispatch to formatter – Based on the format value, the CLI calls the matching export function (lines 1668‑1676 in
cli.py):elif fmt == "graphml": out = export_graphml(store, out_path) elif fmt == "cypher": out = export_neo4j_cypher(store, out_path) elif fmt == "obsidian": out = export_obsidian_vault(store, out_dir) -
Atomic write – Each exporter writes output to a temporary file before renaming it to the final destination, ensuring data integrity.
Exporting to GraphML
The GraphML export generates a standards-compliant XML document suitable for import into Gephi, yEd, or Cytoscape.
The export_graphml() function constructs the XML header and defines <key> elements for node properties (kind, file, language, community) and edge properties (edge_kind). It iterates over the node and edge dictionaries to emit <node> and <edge> elements, escaping XML-unsafe characters to prevent document corruption.
Example XML structure generated:
<node id="my.package.Class">
<data key="kind">Class</data>
<data key="file">src/my/package/Class.java</data>
<data key="language">java</data>
<data key="community">1</data>
</node>
Implementation details are located in code_review_graph/exports.py at lines 58‑67 and 85‑110.
Exporting to Neo4j Cypher
The Neo4j Cypher export produces a text file containing Cypher CREATE statements that can be executed directly in the Neo4j Browser or via cypher-shell.
The export_neo4j_cypher() function generates:
- A
CREATE (:<Kind> {...})statement for every node, using the node kind as the label and including properties likequalified_name,file, andlanguage. - A
MATCH (a {qualified_name: "..."}), (b {qualified_name: "..."}) CREATE (a)-[:<Kind>]->(b)pattern for every edge.
Property values are escaped using an internal _cypher_escape() helper to handle special characters in Cypher literals. The implementation spans lines 124‑166 in code_review_graph/exports.py.
Exporting to Obsidian Vault
The Obsidian export creates a local folder structure compatible with the Obsidian knowledge base application, transforming graph nodes into linked markdown notes.
The export_obsidian_vault() function performs the following:
- Creates one
.mdfile per node using a filesystem-safe slug generated by_obsidian_slug(). - Prepends YAML front-matter to each file containing
kind,file,language,community, andtags. - Adds a "Connections" section with wikilinks (e.g.,
[[slug|Name]]) pointing to neighboring nodes. - Generates community overview pages named
_COMMUNITY_<id>.mdand a global_INDEX.mdfor navigation.
This implementation is found in code_review_graph/exports.py at lines 95‑143 (slug generation and file setup) and lines 191‑438 (vault structure and markdown generation).
CLI Usage Examples
Run these commands from your project root after installing code-review-graph.
Export to GraphML
code-review-graph visualize --format graphml \
--output /tmp/myproject.graphml
Open /tmp/myproject.graphml in Gephi or yEd to visualize the dependency structure.
Export to Neo4j Cypher
code-review-graph visualize --format cypher \
--output ./import.cypher
Execute the script against a running Neo4j instance:
cat import.cypher | cypher-shell -u neo4j -p password
Export to Obsidian Vault
code-review-graph visualize --format obsidian \
--output ./my-obsidian-vault
Open the my-obsidian-vault folder as a vault in Obsidian. Use the _INDEX.md file to browse the graph topology through linked notes.
Summary
- GraphML export (
export_graphml()) creates portable XML for desktop graph visualization tools. - Neo4j export (
export_neo4j_cypher()) generates executable Cypher scripts with proper literal escaping for property values. - Obsidian export (
export_obsidian_vault()) builds a markdown-based knowledge graph with YAML front-matter and wikilinks. - All exporters reside in
code_review_graph/exports.pyand are invoked via thevisualize --formatCLI interface defined incode_review_graph/cli.py.
Frequently Asked Questions
What tools are compatible with the GraphML export?
The GraphML file generated by export_graphml() follows the GraphML XML standard and imports directly into Gephi, yEd, Cytoscape, and any other tool supporting the GraphML 1.0 specification. The export includes typed data keys for node properties like kind, file, and community.
How do I import the Cypher export into a Neo4j database?
You can pipe the generated .cypher file directly into cypher-shell using the command cat filename.cypher | cypher-shell -u <username> -p <password>, or copy-paste the contents into the Neo4j Browser query window. The script uses CREATE constraints and is idempotent if run against an empty database.
What is the file structure of the Obsidian vault export?
The Obsidian export creates a root folder containing individual markdown files for each code element (slugified via _obsidian_slug()), community overview pages (_COMMUNITY_<id>.md), and a central _INDEX.md. Each node file contains YAML front-matter with metadata and a "Connections" section populated with wikilinks to related nodes.
Can I export the graph without installing Neo4j or Obsidian locally?
Yes. The GraphML and Cypher formats produce standalone files that you can share or import into cloud-hosted instances. The Obsidian vault is a static folder of markdown files that requires no running server; you can zip the output folder and open it on any machine with Obsidian installed.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →