Egonex-AI Knowledge Base Analyzer: Wiki Parsing and Graph Construction Explained
The Egonex-AI knowledge base analyzer transforms code repositories into structured knowledge graphs by extracting wiki links from Markdown files, storing them in knowledgeMeta.wikilinks, and validating the structure through Zod schemas to power interactive documentation dashboards.
The Understand-Anything repository implements a full-stack analyzer that converts source repositories into navigable knowledge graphs capturing entities, relationships, and wiki-style documentation links. According to the Egonex-AI source code, the system processes files through a five-stage pipeline—discovery, parsing, graph building, normalization, and consumption—to generate LLM-ready knowledge representations and automated onboarding guides.
How the Knowledge Base Analyzer Pipeline Works
The analyzer follows a strict transformation pipeline defined in the core package architecture.
File Discovery and Language Detection
The pipeline begins in packages/core/src/plugins/discovery.ts, where the system scans the repository root to identify all files and their respective languages. This plugin-driven approach determines which specialized parser handles each file type, ensuring Markdown documents route to the wiki-capable parser.
Markdown Parsing and Wiki Link Extraction
For Markdown files, the analyzer invokes packages/core/src/plugins/parsers/markdown-parser.ts. This parser performs two critical operations:
- Section extraction: The
extractSectionsmethod (lines 41-70) walks the file line-by-line, skips fenced code blocks, and records ATX headings (#through######) with their name, level, and line range. - Reference extraction: The
extractReferencesmethod (lines 23-38) uses regex to identify local file links ([]()) and image references (![]()), filtering out external URLs (those starting withhttp). It returns aReferenceResolution[]array containing source path, target path, reference type, and line number.
Graph Construction and Validation
The packages/core/src/analyzer/graph-builder.ts consumes the parser output. When processing Markdown references, the builder:
- Creates a node of type
"article"(or"concept"based on heuristics) - Populates
knowledgeMeta.wikilinkswith resolved target paths - Adds reciprocal edges (
cites,referenced_by) when targets contain backlinks
Before final output, packages/core/src/schema.ts validates the graph using Zod schemas. The KnowledgeMetaSchema (lines 61-66) enforces the structure of wiki-specific fields, while autoFixGraph (lines 96-248) normalizes aliases like wiki_page → article and ensures missing wikilinks fields default to undefined.
Wiki Parsing Capabilities: From Markdown to Knowledge Graph
The wiki parsing system transforms static Markdown documentation into a queryable graph structure.
Extracting Document Structure
The extractSections function in markdown-parser.ts computes precise line ranges for each heading level. This creates a hierarchical view of the document, enabling the dashboard to render collapsible sections and establishing anchor points for internal navigation.
Resolving Local References
The extractReferences function specifically targets local file links—those pointing to other files in the repository rather than external URLs. When it encounters [Configuration](./Config.md), it records the target as a candidate for a wiki link. The graph builder later resolves these relative paths into canonical node IDs, ensuring cross-document links remain valid even when files move.
Storing Wiki Links in Graph Nodes
Wiki connectivity lives in the knowledgeMeta object defined in schema.ts. The GraphNodeSchema includes this metadata structure at lines 61-66, containing:
wikilinks: Array of target node IDs this article referencesbacklinks: Array of node IDs referencing this articlecategory: Optional classification for wiki organizationcontent: Raw or processed text content
This schema guarantees that any node representing a knowledge artifact maintains a predictable structure for downstream consumers.
Code Examples: Implementing Wiki Parsing
Direct Markdown Parser Usage
You can invoke the Markdown parser directly to extract structure and references before full graph construction:
import { MarkdownParser } from "@understand-anything/core/src/plugins/parsers/markdown-parser";
const parser = new MarkdownParser();
const content = await Deno.readTextFile("docs/GettingStarted.md");
// Extract document sections (headings)
const sections = parser["extractSections"](content);
// Extract local file references
const refs = parser.extractReferences("docs/GettingStarted.md", content);
console.log(sections);
/*
[
{ name: "Getting Started", level: 1, lineRange: [1, 5] },
{ name: "Installation", level: 2, lineRange: [6, 9] }
]
*/
console.log(refs);
/*
[
{
source: "docs/GettingStarted.md",
target: "./Config.md",
referenceType: "file",
line: 8
}
]
*/
Building and Validating the Knowledge Graph
To process an entire repository and generate the validated graph:
import { buildGraph } from "@understand-anything/core/src/analyzer/graph-builder";
import { validateGraph } from "@understand-anything/core/src/schema";
import { buildOnboardingGuide } from "@understand-anything/plugin/src/onboard-builder";
(async () => {
const rawGraph = await buildGraph({ root: "./my-project" });
const { success, data, issues } = validateGraph(rawGraph);
if (!success) {
console.error("Graph validation failed:", issues);
return;
}
// data is a fully typed KnowledgeGraph with wikilinks populated
const guide = buildOnboardingGuide(data);
await Deno.writeTextFile("ONBOARDING.md", guide);
})();
Rendering Wiki Links in Applications
When consuming the graph in a React dashboard, access the wikilinks array from knowledgeMeta:
function WikiNode({ node }: { node: GraphNode }) {
const links = node.knowledgeMeta?.wikilinks ?? [];
return (
<div className="wiki-node">
<h3>{node.name}</h3>
<p>{node.summary}</p>
{links.length > 0 && (
<ul>
{links.map((link) => (
<li key={link}>
<a href={`#node-${link}`}>🔗 {link}</a>
</li>
))}
</ul>
)}
</div>
);
}
Key Source Files and Architecture
| Feature | File Path | Purpose |
|---|---|---|
| Markdown Parsing | packages/core/src/plugins/parsers/markdown-parser.ts |
Extracts sections and local references using extractSections and extractReferences |
| Schema Definition | packages/core/src/schema.ts (lines 61-66) |
Defines KnowledgeMetaSchema with wikilinks and backlinks fields |
| Alias Normalization | packages/core/src/schema.ts (lines 16-38) |
Maps wiki_page → article and other node type aliases |
| Graph Construction | packages/core/src/analyzer/graph-builder.ts |
Creates article nodes and populates knowledgeMeta.wikilinks |
| Validation | packages/core/src/schema.ts |
Contains validateGraph, autoFixGraph, and sanitizeGraph functions |
| Onboarding Generation | src/onboard-builder.ts |
Generates markdown wiki guides from the validated graph |
Summary
- The Egonex-AI knowledge base analyzer processes repositories through discovery, parsing, building, normalization, and consumption stages.
- The Markdown parser in
markdown-parser.tsextracts document structure viaextractSectionsand local file references viaextractReferences. - Wiki links are stored in the graph schema within
knowledgeMeta.wikilinks, validated by Zod schemas inschema.tsat lines 61-66. - The graph builder creates
"article"nodes for Markdown files and resolves relative paths into canonical wiki link targets. - Alias mapping normalizes node types (e.g.,
wiki_page→article) before validation to ensure graph consistency. - Output generators like
onboard-builder.tstransform the validated graph into human-readable documentation and interactive dashboards.
Frequently Asked Questions
What is the Egonex-AI knowledge base analyzer?
The Understand-Anything analyzer is a full-stack system that converts code repositories into structured knowledge graphs. It captures entities like files, classes, and documentation articles, along with relationships such as imports, calls, and wiki-style cross-references, enabling automated onboarding documentation and LLM-powered code understanding.
How does the Markdown parser handle wiki links?
The parser in packages/core/src/plugins/parsers/markdown-parser.ts uses the extractReferences method (lines 23-38) to identify local file links while excluding external URLs. It captures the source file, target path, and line number, returning a ReferenceResolution[] array that the graph builder converts into wikilinks entries during node creation.
Where are wiki links stored in the graph structure?
Wiki links reside in the knowledgeMeta object of each graph node, specifically within the wikilinks array. According to packages/core/src/schema.ts (lines 61-66), the KnowledgeMetaSchema defines this field alongside backlinks, category, and content, ensuring all knowledge artifacts maintain a predictable structure for validation and consumption.
How does the analyzer validate the knowledge graph?
Validation occurs in packages/core/src/schema.ts using Zod schemas. The validateGraph function checks nodes against GraphNodeSchema and KnowledgeMetaSchema, while autoFixGraph (lines 96-248) normalizes node types using alias maps and inserts default values for optional fields like wikilinks. This ensures the output graph conforms to the expected TypeScript interfaces before dashboard consumption.
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 →