How to Export the Code-Review Graph to Neo4j, GraphML, or Obsidian
Export the knowledge graph to Neo4j Cypher, GraphML, or Obsidian Vault using the GraphStore API and CLI commands provided by the code-review-graph project.
The code-review-graph project provides multiple export formats for its knowledge base, enabling integration with graph databases, visualization tools, and personal knowledge management systems. All formats build on the same low-level data representation returned by export_graph_data(store), which extracts nodes, edges, and community structures from the central GraphStore object.
Export Formats Overview
The project supports four distinct export targets:
- Neo4j (Cypher) — Generates executable Cypher statements for Neo4j graph database import
- GraphML — Standard XML-based graph format compatible with Gephi, yEd, and NetworkX
- Obsidian Vault — Markdown-based knowledge base with WikiLinks for interactive exploration
- JSON/SVG — Additional programmatic and visualization formats
Each format is implemented in code_review_graph/exports.py and accessible via both Python API and CLI.
Exporting to Neo4j (Cypher)
The Neo4j exporter produces a self-contained Cypher script that recreates the entire graph in a Neo4j instance.
How It Works
The export_neo4j_cypher() function in [code_review_graph/exports.py](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py) performs two main operations:
-
Node creation — Each node becomes a Cypher
CREATEstatement with:- Label derived from the node's
kindfield (Class, Function, Module, etc.) - Properties formatted by
_cypher_props()includingqualified_name,name,file_path,language, and optionalcommunity_id
- Label derived from the node's
-
Edge creation — For every relationship, a
MATCH-CREATEpair links nodes by their escapedqualified_namevalues using_cypher_escape()
Programmatic Export
from pathlib import Path
from code_review_graph.graph import GraphStore
from code_review_graph.exports import export_neo4j_cypher
# Load an existing GraphStore
store = GraphStore.load(Path("path/to/data_dir"))
out_file = Path("graph.cypher")
export_neo4j_cypher(store, out_file)
The resulting graph.cypher contains statements like:
CREATE (:Class {qualified_name: 'my_pkg.MyClass', name: 'MyClass',
file_path: 'my_pkg.py', language: 'python'});
MATCH (a {qualified_name: 'my_pkg.MyClass'}),
(b {qualified_name: 'my_pkg.helper'})
CREATE (a)-[:CALLS]->(b);
Import into Neo4j using:
cat graph.cypher | cypher-shell -u neo4j -p <password>
CLI Command
code-review-graph export --format cypher
This writes graph.cypher to the default data directory and prints the full path.
Exporting to GraphML
The GraphML exporter generates standard XML that preserves all node/edge properties and community assignments for external graph analysis tools.
Key Implementation Details
- Located in [
code_review_graph/exports.py](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py) alongside other format handlers - Uses the same
export_graph_data(store)foundation as Neo4j and Obsidian exports - Compatible with Gephi, Cytoscape, yEd, and NetworkX
Usage
from code_review_graph.exports import export_graphml
export_graphml(store, Path("graph.graphml"))
code-review-graph export --format graphml
Exporting to Obsidian Vault
The Obsidian exporter materializes the knowledge graph as a navigable Markdown-based vault where relationships become bidirectional WikiLinks.
How It Works
The export_obsidian_vault() function performs five transformation steps:
-
Slug generation — Node names are normalized to filesystem-safe identifiers via
_obsidian_slug()(exports.py:46-49) -
Adjacency collection — Both incoming and outgoing edges are gathered for each node's "Connections" section
-
Markdown composition — Each node becomes
slug.mdcontaining:- YAML front-matter (
kind,file,language,community,tags) - Human-readable heading
## Connectionssection with[[wikilink|DisplayName]]entries
- YAML front-matter (
-
Community summaries —
_COMMUNITY_<id>.mdfiles document each community's size, cohesion, and dominant language -
Index generation —
_INDEX.mdprovides global statistics and navigation
Programmatic Export
from pathlib import Path
from code_review_graph.graph import GraphStore
from code_review_graph.exports import export_obsidian_vault
store = GraphStore.load(Path("path/to/data_dir"))
vault_dir = Path("my-obsidian-vault")
export_obsidian_vault(store, vault_dir)
Resulting vault structure:
my-obsidian-vault/
├── my-class.md # Individual node pages
├── my-function.md
├── _COMMUNITY_1.md # Community overview
├── _INDEX.md # Global navigation
└── .obsidian/ # (create manually if needed)
Open the directory in Obsidian to use Graph view and Backlinks for interactive exploration.
CLI Command
code-review-graph export --format obsidian
Common Export Pipeline
All formats share a unified data extraction flow:
from code_review_graph.visualization import export_graph_data
# Core extraction used by every exporter
data = export_graph_data(store)
# → {"nodes": [...], "edges": [...], "communities": [...]}
The GraphStore in [code_review_graph/graph.py](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py) persists this structure to disk, while format-specific functions in [code_review_graph/exports.py](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py) handle serialization.
CLI Reference
| Command | Purpose | Output |
|---|---|---|
code-review-graph export --format cypher |
Neo4j import script | graph.cypher |
code-review-graph export --format graphml |
Standard graph XML | graph.graphml |
code-review-graph export --format obsidian |
Markdown vault directory | obsidian_vault/ |
code-review-graph export --format json |
Raw JSON serialization | graph.json |
code-review-graph export --format svg |
Static vector visualization | graph.svg |
The export dispatch logic resides in [code_review_graph/cli.py](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/cli.py#L1915-L1925).
Summary
- All exports build on
export_graph_data()— The unified extraction invisualization.pyensures consistency across formats - Neo4j export generates executable Cypher — Node creation followed by
MATCH-CREATEedge statements with proper escaping - Obsidian export creates navigable Markdown — WikiLinks preserve graph topology for PKM workflows
- GraphML provides tool interoperability — Standard XML for Gephi, NetworkX, and other analysis platforms
- Both API and CLI access — Use
export_neo4j_cypher(),export_obsidian_vault(),export_graphml()directly, or invoke viacode-review-graph export --format <name>
Frequently Asked Questions
Does the tool support batch exporting multiple formats at once?
No. As implemented in code_review_graph/cli.py, the export command accepts a single --format argument. Run the command multiple times with different format values to generate all desired outputs, or call the programmatic API functions in sequence within a Python script.
Can I customize the Cypher output for existing Neo4j schemas?
The current export_neo4j_cypher() implementation in exports.py generates standalone CREATE statements with hardcoded property names. For schema customization, post-process the output or modify the _cypher_props() helper at lines 73-88 to inject additional labels or transform property keys before emission.
What Obsidian plugins work best with the exported vault?
The generated vault is optimized for Graph view (core plugin) and Backlinks panel. Enable Tags pane to filter by language or community front-matter fields. Community plugins like Dataview can query the YAML metadata for advanced filtering, though the base export requires no plugins.
How are qualified names escaped in Cypher to handle special characters?
The _cypher_escape() function at lines 73-77 of exports.py handles escaping by processing backslashes and quotes in node identifiers. This ensures that qualified names containing dots, brackets, or other Cypher-sensitive characters parse correctly when imported.
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 →