# nxpatterns/gitnexus architecture

> Architecture diagram of the GitHub repository nxpatterns/gitnexus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nxpatterns/gitnexus
- Repository: https://github.com/nxpatterns/gitnexus

## Overview

1. **Repository shape**
   - This is a multi-package monorepo centered on the `gitnexus` CLI and MCP server, plus a separate `gitnexus-web` browser app.
   - The core architectural idea is the same across both: index a codebase into a knowledge graph, persist it, and expose higher-level queries for agents and humans.

2. **Primary product boundary: CLI vs Web**
   - `gitnexus/` is the local, Node.js-based product for indexing repos, storing graph state, serving MCP tools, and generating docs.
   - `gitnexus-web/` is the browser UI for visual exploration and chat, using WebAssembly versions of the parser/database stack.
   - Both share the same conceptual pipeline and graph model, but differ in runtime and storage: native Node/KuzuDB for CLI, in-browser WASM for the web app.

3. **Indexing pipeline is the central subsystem**
   - The core graph is built in phases under `src/core/ingestion/` in both packages.
   - The pipeline walks the filesystem, parses code with Tree-sitter, resolves imports/calls, enriches symbol metadata, detects frameworks, clusters related symbols, and derives execution processes.
   - This is the main data-production flow: source files in, structured graph and derived relationships out.

4. **Language parsing and AST handling**
   - Tree-sitter is the parsing boundary.
   - Native bindings are used in the CLI; WASM parsers live under `gitnexus-web/public/wasm/`.
   - Parsing output feeds symbol tables, import resolution, call graph extraction, and structural metadata; it is the foundation for all downstream graph features.

5. **Graph persistence layer**
   - The persistent graph store is KuzuDB.
   - In the CLI, KuzuDB is native and stored per repo under `.gitnexus/`.
   - In the web app, KuzuDB runs as WASM and is session-scoped in browser memory.
   - This layer is the canonical source for graph queries, symbol context, cluster membership, and process traces.

6. **Embeddings and hybrid search**
   - `src/core/embeddings/` builds text embeddings for code and metadata, and `src/core/search/` combines BM25 lexical retrieval with semantic search.
   - Search is not just keyword-based; it is designed to return process-grouped and graph-aware results.
   - This subsystem is what powers the `query` tool and the browser search experience.

7. **Graph intelligence features**
   - Higher-level analysis lives in modules such as clustering, community detection, heritage, process extraction, entry-point scoring, and impact analysis.
   - These features transform raw code relationships into actionable summaries like “what depends on this symbol,” “what execution flow does this belong to,” and “which cluster does it fit in.”
   - This is the main differentiation from a plain code indexer: relationships are precomputed so tools can answer in one call.

8. **CLI orchestration and local repo storage**
   - The CLI entrypoints under `src/cli/` orchestrate indexing, status checks, cleanup, server startup, MCP registration, augmentation, and wiki generation.
   - Repo-local state lives in `.gitnexus/`, while a global registry under `~/.gitnexus/` tracks all indexed repos for multi-repo access.
   - `src/storage/` manages filesystem and git-aware repo handling; this is the boundary between codebase contents and GitNexus metadata.

9. **MCP server and agent-facing tools**
   - `src/mcp/` turns the indexed graph into MCP resources and tools.
   - The exposed capabilities include repository listing, hybrid query, symbol context, impact analysis, change detection, rename planning, and raw Cypher access.
   - This is the main integration boundary for external AI agents such as Claude Code, Cursor, Windsurf, and OpenCode.

10. **Hooks, skills, and editor integration**
   - The repo includes packaged skills and hook scripts for Claude and Cursor integrations.
   - Claude-specific hooks can augment tool use automatically, while skills provide guided workflows for exploring, debugging, impact analysis, and refactoring.
   - These are thin integration layers around the MCP/core system; they do not own the graph, but improve how agents consume it.

11. **Web app architecture**
   - `gitnexus-web/` is a React + TypeScript + Vite frontend with Sigma.js/Graphology for graph visualization.
   - It includes panels for file trees, clusters, processes, code references, settings, and an LLM chat/agent experience.
   - Its ingestion and analysis logic mirrors the CLI, but runs in browser workers and WASM to keep everything local to the session.

12. **Web backend bridge mode**
   - The web app can run standalone or connect to a local backend started by `gitnexus serve`.
   - In bridge mode, the browser UI does not re-index; it queries the local CLI-backed server for repo data and AI tools.
   - This creates a second data path: browser UI → backend API → local indexed repos.

13. **Evaluation and benchmarking**
   - The `eval/` package is a separate Python-based evaluation harness.
   - It contains agents, prompts, model configs, a Docker environment, and result analysis scripts for comparing modes and models.
   - This subsystem is not part of the product runtime; it exists to benchmark how well the graph-backed context improves agent behavior.

14. **Net architecture summary**
   - At a high level, GitNexus is a pipeline from source code to graph database to agent/human interfaces.
   - The key boundaries are: filesystem/codebase ingestion, graph persistence, retrieval/analysis, agent protocol exposure, and UI/visualization.
   - The central design choice is precomputing code relationships so downstream tools can retrieve architectural context directly instead of reconstructing it live.

Main entry points: [`gitnexus/src/mcp/server.ts`](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/mcp/server.ts) (MCP server), [`gitnexus/src/cli/index.ts`](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/cli/index.ts) (CLI), [`gitnexus-web/src/App.tsx`](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/App.tsx) (Web shell), [`gitnexus/src/core/ingestion/pipeline.ts`](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/pipeline.ts) (Ingest pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI product"]
  node_cli_entry["CLI<br/>entrypoint<br/>[index.ts]"]
  node_repo_store[("Repo store<br/>storage<br/>[repo-manager.ts]")]
  node_cli_ingest["Ingest pipeline<br/>orchestration<br/>[pipeline.ts]"]
  node_parse_workers["Parse workers<br/>concurrency<br/>[worker-pool.ts]"]
  node_mcp_server["MCP server<br/>agent gateway<br/>[server.ts]"]
  node_local_api["Local API<br/>http bridge<br/>[api.ts]"]
  node_wiki_gen["Wiki docs<br/>docs generator<br/>[generator.ts]"]
end

subgraph group_web["Web app"]
  node_web_shell["Web shell<br/>frontend<br/>[App.tsx]"]
  node_graph_canvas(("Graph canvas<br/>visualization<br/>[GraphCanvas.tsx]"))
  node_web_ingest["Browser ingest<br/>pipeline<br/>[pipeline.ts]"]
  node_wasm_stack[("WASM stack<br/>runtime<br/>[kuzu-wasm.wasm]")]
  node_web_search["Web search<br/>retrieval<br/>[hybrid-search.ts]"]
  node_web_llm["Chat agent<br/>llm orchestration<br/>[agent.ts]"]
end

subgraph group_core["Shared core"]
  node_graph_model{{"Graph model<br/>schema<br/>[graph.ts]"}}
  node_tree_sitter["Tree-sitter<br/>parser boundary<br/>[parser-loader.ts]"]
  node_symbol_analysis["Symbol analysis<br/>ingestion<br/>[symbol-table.ts]"]
  node_graph_intel["Graph intelligence<br/>analysis"]
  node_kuzu_store[("KuzuDB<br/>graph database<br/>[kuzu-adapter.ts]")]
  node_embeddings["Embeddings<br/>vectorization"]
  node_hybrid_search["Hybrid search<br/>retrieval<br/>[hybrid-search.ts]"]
  node_mcp_tools["MCP tools<br/>tooling<br/>[tools.ts]"]
end

subgraph group_integration["Agent integrations"]
  node_agents_skills["Hooks & skills<br/>integration<br/>[gitnexus-hook.js]"]
end

subgraph group_eval["Evaluation"]
  node_eval_harness["Eval harness<br/>benchmarking<br/>[run_eval.py]"]
end

node_cli_entry -->|"manage repos"| node_repo_store
node_cli_entry -->|"index"| node_cli_ingest
node_cli_ingest -->|"parallel parse"| node_parse_workers
node_cli_ingest -->|"parse code"| node_tree_sitter
node_cli_ingest -->|"extract facts"| node_symbol_analysis
node_symbol_analysis -->|"enrich"| node_graph_intel
node_graph_intel -->|"materialize"| node_graph_model
node_graph_model -->|"persist"| node_kuzu_store
node_embeddings -->|"semantic input"| node_hybrid_search
node_graph_model -->|"graph-aware lookup"| node_hybrid_search
node_kuzu_store -->|"query"| node_hybrid_search
node_kuzu_store -->|"serve context"| node_mcp_tools
node_mcp_server -->|"expose tools"| node_mcp_tools
node_local_api -->|"bridge"| node_mcp_server
node_cli_entry -->|"start"| node_mcp_server
node_cli_entry -->|"generate docs"| node_wiki_gen
node_web_shell -->|"render graph"| node_graph_canvas
node_web_shell -->|"ingest locally"| node_web_ingest
node_web_ingest -->|"parse code"| node_tree_sitter
node_web_ingest -->|"use wasm"| node_wasm_stack
node_web_search -->|"query session"| node_wasm_stack
node_web_shell -->|"search"| node_web_search
node_web_shell -->|"chat"| node_web_llm
node_agents_skills -->|"guide usage"| node_mcp_server
node_eval_harness -->|"benchmark"| node_mcp_server
node_eval_harness -->|"compare modes"| node_web_llm

click node_cli_entry "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/cli/index.ts"
click node_repo_store "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/storage/repo-manager.ts"
click node_cli_ingest "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/pipeline.ts"
click node_parse_workers "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/workers/worker-pool.ts"
click node_mcp_server "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/mcp/server.ts"
click node_local_api "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/server/api.ts"
click node_wiki_gen "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/wiki/generator.ts"
click node_graph_model "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/graph/graph.ts"
click node_tree_sitter "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/tree-sitter/parser-loader.ts"
click node_symbol_analysis "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/symbol-table.ts"
click node_graph_intel "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/cluster-enricher.ts"
click node_kuzu_store "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/kuzu/kuzu-adapter.ts"
click node_embeddings "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/embeddings/embedding-pipeline.ts"
click node_hybrid_search "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/search/hybrid-search.ts"
click node_mcp_tools "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/mcp/tools.ts"
click node_web_shell "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/App.tsx"
click node_graph_canvas "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/components/GraphCanvas.tsx"
click node_web_ingest "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/ingestion/pipeline.ts"
click node_wasm_stack "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/public/wasm/kuzu-wasm.wasm"
click node_web_search "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/search/hybrid-search.ts"
click node_web_llm "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/llm/agent.ts"
click node_agents_skills "https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-claude-plugin/hooks/gitnexus-hook.js"
click node_eval_harness "https://github.com/nxpatterns/gitnexus/blob/main/eval/run_eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_entry,node_repo_store,node_cli_ingest,node_parse_workers,node_mcp_server,node_local_api,node_wiki_gen toneBlue
class node_web_shell,node_graph_canvas,node_web_ingest,node_wasm_stack,node_web_search,node_web_llm toneAmber
class node_graph_model,node_tree_sitter,node_symbol_analysis,node_graph_intel,node_kuzu_store,node_embeddings,node_hybrid_search,node_mcp_tools toneMint
class node_agents_skills toneRose
class node_eval_harness toneIndigo
```

## Components

### CLI product

Local Node.js product for indexing, serving, and repo management.

- [CLI](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/cli/index.ts): entrypoint · Command surface for indexing, serving, status, cleanup, wiki generation, and MCP setup. · `gitnexus/src/cli/index.ts`
- [Repo store](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/storage/repo-manager.ts): storage · Filesystem and git-aware repository management plus local/global GitNexus state. · `gitnexus/src/storage/repo-manager.ts`
- [Ingest pipeline](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/pipeline.ts): orchestration · Coordinates filesystem walking, parsing, and graph enrichment for local repos. · `gitnexus/src/core/ingestion/pipeline.ts`
- [Parse workers](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/workers/worker-pool.ts): concurrency · Worker pool and parse worker used to parallelize AST extraction in the CLI. · `gitnexus/src/core/ingestion/workers/worker-pool.ts`
- [MCP server](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/mcp/server.ts): agent gateway · Exposes indexed graph capabilities as MCP resources and tools. · `gitnexus/src/mcp/server.ts`
- [Local API](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/server/api.ts): http bridge · Backend API and local backend bridge used by server and web integration modes. · `gitnexus/src/server/api.ts`
- [Wiki docs](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/wiki/generator.ts): docs generator · Generates repository documentation and HTML views from graph queries. · `gitnexus/src/core/wiki/generator.ts`

### Web app

Browser UI and in-session graph stack.

- [Web shell](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/App.tsx): frontend · React/Vite application shell for local exploration, chat, and graph visualization. · `gitnexus-web/src/App.tsx`
- [Graph canvas](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/components/GraphCanvas.tsx): visualization · Sigma.js/Graphology-based graph exploration and rendering surface. · `gitnexus-web/src/components/GraphCanvas.tsx`
- [Browser ingest](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/ingestion/pipeline.ts): pipeline · Browser-side ingestion pipeline running in workers and WASM. · `gitnexus-web/src/core/ingestion/pipeline.ts`
- [WASM stack](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/public/wasm/kuzu-wasm.wasm): runtime · WebAssembly parsers and Kuzu database used for in-browser local processing. · `gitnexus-web/public/wasm/kuzu-wasm.wasm`
- [Web search](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/search/hybrid-search.ts): retrieval · Browser hybrid search over local session data and graph state. · `gitnexus-web/src/core/search/hybrid-search.ts`
- [Chat agent](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-web/src/core/llm/agent.ts): llm orchestration · Browser LLM context builder, tools, and agent experience. · `gitnexus-web/src/core/llm/agent.ts`

### Shared core

Architecture shared across runtimes: ingestion, graph, search, embeddings, and persistence.

- [Graph model](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/graph/graph.ts): schema · Canonical graph entities and relationships used by ingestion, search, MCP, and UI. · `gitnexus/src/core/graph/graph.ts`
- [Tree-sitter](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/tree-sitter/parser-loader.ts): parser boundary · Language parsing boundary and parser loader for syntax-aware analysis. · `gitnexus/src/core/tree-sitter/parser-loader.ts`
- [Symbol analysis](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/symbol-table.ts): ingestion · AST cache, symbol table, imports, calls, structure, heritage, and framework detection. · `gitnexus/src/core/ingestion/symbol-table.ts`
- [Graph intelligence](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/ingestion/cluster-enricher.ts): analysis · Clustering, community detection, entry-point scoring, process extraction, and impact-oriented summaries. · `gitnexus/src/core/ingestion/cluster-enricher.ts`
- [KuzuDB](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/kuzu/kuzu-adapter.ts): graph database · Persistent graph store used as the canonical query layer for symbols, clusters, and processes. · `gitnexus/src/core/kuzu/kuzu-adapter.ts`
- [Embeddings](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/embeddings/embedding-pipeline.ts): vectorization · Builds embeddings from code and metadata for semantic retrieval. · `gitnexus/src/core/embeddings/embedding-pipeline.ts`
- [Hybrid search](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/core/search/hybrid-search.ts): retrieval · Combines BM25 lexical search with semantic search and graph-aware result shaping. · `gitnexus/src/core/search/hybrid-search.ts`
- [MCP tools](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus/src/mcp/tools.ts): tooling · Repository listing, hybrid query, symbol context, impact analysis, change detection, rename planning, and raw Cypher access. · `gitnexus/src/mcp/tools.ts`

### Agent integrations

Hooks and skills that wrap GitNexus for external agents and editors.

- [Hooks & skills](https://github.com/nxpatterns/gitnexus/blob/main/gitnexus-claude-plugin/hooks/gitnexus-hook.js): integration · Claude and Cursor hooks plus packaged workflows for exploring, debugging, impact analysis, and refactoring. · `gitnexus-claude-plugin/hooks/gitnexus-hook.js`

### Evaluation

Benchmarking harness for agent performance and modes.

- [Eval harness](https://github.com/nxpatterns/gitnexus/blob/main/eval/run_eval.py): benchmarking · Python-based evaluation environment, prompts, agents, and result analysis. · `eval/run_eval.py`

## Connections

- CLI → Repo store: manage repos · CLI commands read and update indexed repository state.
- CLI → Ingest pipeline: index · CLI starts the repository ingestion pipeline.
- Ingest pipeline → Parse workers: parallel parse · The ingestion pipeline offloads AST parsing to workers.
- Ingest pipeline → Tree-sitter: parse code · Source files are parsed through Tree-sitter.
- Ingest pipeline → Symbol analysis: extract facts · Ingestion derives symbols, imports, calls, and structure.
- Symbol analysis → Graph intelligence: enrich · Derived symbols feed clustering, community, and process analysis.
- Graph intelligence → Graph model: materialize · Higher-level relationships are written into the canonical graph model.
- Graph model → KuzuDB: persist · Graph data is stored in KuzuDB as the authoritative query layer.
- Embeddings → Hybrid search: semantic input · Embeddings power semantic ranking within hybrid retrieval.
- Graph model → Hybrid search: graph-aware lookup · Search combines lexical/semantic retrieval with graph context.
- KuzuDB → Hybrid search: query · Retrieval consults the persisted graph database.
- KuzuDB → MCP tools: serve context · MCP tools query the graph store for agent-facing answers.
- MCP server → MCP tools: expose tools · The server publishes the tool surface to external agents.
- Local API → MCP server: bridge · Local backend mode routes UI requests through the CLI-backed server.
- CLI → MCP server: start · CLI entrypoints can launch MCP serving.
- CLI → Wiki docs: generate docs · Wiki generation uses graph queries and LLM-assisted rendering.
- Web shell → Graph canvas: render graph · The frontend delegates visual exploration to the graph canvas.
- Web shell → Browser ingest: ingest locally · The browser app can build a session-local graph in workers.
- Browser ingest → Tree-sitter: parse code · Browser ingestion uses the same parsing boundary conceptually.
- Browser ingest → WASM stack: use wasm · Browser-side parsing and storage run on WebAssembly.
- Web search → WASM stack: query session · Search operates over the browser-local graph database.
- Web shell → Web search: search · The UI surfaces hybrid search to users.
- Web shell → Chat agent: chat · The frontend connects chat, context building, and tool calls.
- Hooks & skills → MCP server: guide usage · Skills and hooks sit on top of the MCP/core system.
- Eval harness → MCP server: benchmark · Evaluation drives the agent-facing backend through scripted runs.
- Eval harness → Chat agent: compare modes · Evaluation can also assess different prompting and agent modes.
