kogral/docs/book/architecture/overview.html
2026-01-23 16:11:07 +00:00

668 lines
28 KiB
HTML

<!DOCTYPE HTML>
<html lang="en" class="rust sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>System Overview - KOGRAL Documentation</title>
<!-- Custom HTML head -->
<meta name="description" content="Complete documentation for KOGRAL - Git-native knowledge graphs for developer teams">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../favicon.svg">
<link rel="shortcut icon" href="../favicon.png">
<link rel="stylesheet" href="../css/variables.css">
<link rel="stylesheet" href="../css/general.css">
<link rel="stylesheet" href="../css/chrome.css">
<link rel="stylesheet" href="../css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="../highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css">
<!-- Custom theme stylesheets -->
<!-- Provide site root and default themes to javascript -->
<script>
const path_to_root = "../";
const default_light_theme = "rust";
const default_dark_theme = "navy";
</script>
<!-- Start loading toc.js asap -->
<script src="../toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('rust')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">KOGRAL Documentation</h1>
<div class="right-buttons">
<a href="../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/your-org/knowledge-base" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://github.com/your-org/knowledge-base/edit/main/docs/./architecture/overview.md" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="system-architecture"><a class="header" href="#system-architecture">System Architecture</a></h1>
<p>Comprehensive overview of the KOGRAL architecture.</p>
<h2 id="high-level-architecture"><a class="header" href="#high-level-architecture">High-Level Architecture</a></h2>
<p><img src="../diagrams/architecture-overview.svg" alt="Architecture Overview" /></p>
<p>The KOGRAL consists of three main layers:</p>
<ol>
<li><strong>User Interfaces</strong>: kb-cli (terminal), kb-mcp (AI integration), NuShell scripts (automation)</li>
<li><strong>Core Library (kb-core)</strong>: Rust library with graph engine, storage abstraction, embeddings, query engine</li>
<li><strong>Storage Backends</strong>: Filesystem (git-friendly), SurrealDB (scalable), In-Memory (cache/testing)</li>
</ol>
<h2 id="component-details"><a class="header" href="#component-details">Component Details</a></h2>
<h3 id="kb-cli-command-line-interface"><a class="header" href="#kb-cli-command-line-interface">kb-cli (Command-Line Interface)</a></h3>
<p><strong>Purpose</strong>: Primary user interface for local knowledge management.</p>
<p><strong>Commands</strong> (13 total):</p>
<ul>
<li><code>init</code>: Initialize <code>.kogral/</code> directory</li>
<li><code>add</code>: Create nodes (note, decision, guideline, pattern, journal)</li>
<li><code>search</code>: Text and semantic search</li>
<li><code>link</code>: Create relationships between nodes</li>
<li><code>list</code>: List all nodes</li>
<li><code>show</code>: Display node details</li>
<li><code>delete</code>: Remove nodes</li>
<li><code>graph</code>: Visualize knowledge graph</li>
<li><code>sync</code>: Sync filesystem ↔ SurrealDB</li>
<li><code>serve</code>: Start MCP server</li>
<li><code>import</code>: Import from Logseq</li>
<li><code>export</code>: Export to Logseq/JSON</li>
<li><code>config</code>: Manage configuration</li>
</ul>
<p><strong>Technology</strong>: Rust + clap (derive API)</p>
<p><strong>Features</strong>:</p>
<ul>
<li>Colored terminal output</li>
<li>Interactive prompts</li>
<li>Dry-run modes</li>
<li>Validation before operations</li>
</ul>
<h3 id="kb-mcp-mcp-server"><a class="header" href="#kb-mcp-mcp-server">kb-mcp (MCP Server)</a></h3>
<p><strong>Purpose</strong>: AI integration via Model Context Protocol.</p>
<p><strong>Protocol</strong>: JSON-RPC 2.0 over stdio</p>
<p><strong>Components</strong>:</p>
<ol>
<li>
<p><strong>Tools</strong> (7):</p>
<ul>
<li><code>kogral/search</code>: Query knowledge base</li>
<li><code>kb/add_note</code>: Create notes</li>
<li><code>kb/add_decision</code>: Create ADRs</li>
<li><code>kb/link</code>: Create relationships</li>
<li><code>kb/get_guidelines</code>: Retrieve guidelines with inheritance</li>
<li><code>kb/list_graphs</code>: List available graphs</li>
<li><code>kb/export</code>: Export to formats</li>
</ul>
</li>
<li>
<p><strong>Resources</strong> (6 URIs):</p>
<ul>
<li><code>kogral://project/notes</code></li>
<li><code>kogral://project/decisions</code></li>
<li><code>kogral://project/guidelines</code></li>
<li><code>kogral://project/patterns</code></li>
<li><code>kogral://shared/guidelines</code></li>
<li><code>kogral://shared/patterns</code></li>
</ul>
</li>
<li>
<p><strong>Prompts</strong> (2):</p>
<ul>
<li><code>kb/summarize_project</code>: Generate project summary</li>
<li><code>kb/find_related</code>: Find related nodes</li>
</ul>
</li>
</ol>
<p><strong>Integration</strong>: Claude Code via <code>~/.config/claude/config.json</code></p>
<h3 id="nushell-scripts"><a class="header" href="#nushell-scripts">NuShell Scripts</a></h3>
<p><strong>Purpose</strong>: Automation and maintenance tasks.</p>
<p><strong>Scripts</strong> (6):</p>
<ul>
<li><code>kb-sync.nu</code>: Filesystem ↔ SurrealDB sync</li>
<li><code>kb-backup.nu</code>: Archive knowledge base</li>
<li><code>kb-reindex.nu</code>: Rebuild embeddings</li>
<li><code>kb-import-logseq.nu</code>: Import from Logseq</li>
<li><code>kb-export-logseq.nu</code>: Export to Logseq</li>
<li><code>kb-stats.nu</code>: Graph statistics</li>
</ul>
<p><strong>Features</strong>:</p>
<ul>
<li>Colored output</li>
<li>Dry-run modes</li>
<li>Progress indicators</li>
<li>Error handling</li>
</ul>
<h2 id="core-library-kb-core"><a class="header" href="#core-library-kb-core">Core Library (kb-core)</a></h2>
<h3 id="models"><a class="header" href="#models">Models</a></h3>
<p><strong>Graph</strong>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Graph {
pub name: String,
pub version: String,
pub nodes: HashMap&lt;String, Node&gt;, // ID → Node
pub edges: Vec&lt;Edge&gt;,
pub metadata: HashMap&lt;String, Value&gt;,
}
<span class="boring">}</span></code></pre></pre>
<p><strong>Node</strong>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Node {
pub id: String,
pub node_type: NodeType,
pub title: String,
pub content: String,
pub tags: Vec&lt;String&gt;,
pub status: NodeStatus,
pub created: DateTime&lt;Utc&gt;,
pub modified: DateTime&lt;Utc&gt;,
// ... relationships, metadata
}
<span class="boring">}</span></code></pre></pre>
<p><strong>Edge</strong>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Edge {
pub from: String,
pub to: String,
pub relation: EdgeType,
pub strength: f32,
pub created: DateTime&lt;Utc&gt;,
}
<span class="boring">}</span></code></pre></pre>
<h3 id="storage-trait"><a class="header" href="#storage-trait">Storage Trait</a></h3>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>#[async_trait]
pub trait Storage: Send + Sync {
async fn save_graph(&amp;self, graph: &amp;Graph) -&gt; Result&lt;()&gt;;
async fn load_graph(&amp;self, name: &amp;str) -&gt; Result&lt;Graph&gt;;
async fn delete_graph(&amp;self, name: &amp;str) -&gt; Result&lt;()&gt;;
async fn list_graphs(&amp;self) -&gt; Result&lt;Vec&lt;String&gt;&gt;;
}
<span class="boring">}</span></code></pre></pre>
<p><strong>Implementations</strong>:</p>
<ol>
<li><code>FilesystemStorage</code>: Git-friendly markdown files</li>
<li><code>MemoryStorage</code>: In-memory with DashMap</li>
<li><code>SurrealDbStorage</code>: Scalable graph database</li>
</ol>
<h3 id="embedding-provider-trait"><a class="header" href="#embedding-provider-trait">Embedding Provider Trait</a></h3>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>#[async_trait]
pub trait EmbeddingProvider: Send + Sync {
async fn embed(&amp;self, texts: Vec&lt;String&gt;) -&gt; Result&lt;Vec&lt;Vec&lt;f32&gt;&gt;&gt;;
fn dimensions(&amp;self) -&gt; usize;
fn model_name(&amp;self) -&gt; &amp;str;
}
<span class="boring">}</span></code></pre></pre>
<p><strong>Implementations</strong>:</p>
<ol>
<li><code>FastEmbedProvider</code>: Local fastembed</li>
<li><code>RigEmbeddingProvider</code>: OpenAI, Claude, Ollama (via rig-core)</li>
</ol>
<h3 id="parser"><a class="header" href="#parser">Parser</a></h3>
<p><strong>Input</strong>: Markdown file with YAML frontmatter</p>
<p><strong>Output</strong>: <code>Node</code> struct</p>
<p><strong>Features</strong>:</p>
<ul>
<li>YAML frontmatter extraction</li>
<li>Markdown body parsing</li>
<li>Wikilink detection (<code>[[linked-note]]</code>)</li>
<li>Code reference parsing (<code>@file.rs:42</code>)</li>
</ul>
<p><strong>Example</strong>:</p>
<pre><code class="language-markdown">---
id: note-123
type: note
title: My Note
tags: [rust, async]
---
# My Note
Content with [[other-note]] and @src/main.rs:10
</code></pre>
<p></p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>Node {
id: "note-123",
node_type: NodeType::Note,
title: "My Note",
content: "Content with [[other-note]] and @src/main.rs:10",
tags: vec!["rust", "async"],
// ... parsed wikilinks, code refs
}
<span class="boring">}</span></code></pre></pre>
<h2 id="configuration-system"><a class="header" href="#configuration-system">Configuration System</a></h2>
<h3 id="nickel-schema"><a class="header" href="#nickel-schema">Nickel Schema</a></h3>
<pre><code class="language-nickel"># schemas/kb-config.ncl
{
KbConfig = {
graph | GraphConfig,
storage | StorageConfig,
embeddings | EmbeddingConfig,
templates | TemplateConfig,
query | QueryConfig,
mcp | McpConfig,
sync | SyncConfig,
},
}
</code></pre>
<h3 id="loading-process"><a class="header" href="#loading-process">Loading Process</a></h3>
<pre><code>User writes: .kogral/config.ncl
↓ [nickel export --format json]
JSON intermediate
↓ [serde_json::from_str]
KbConfig struct (Rust)
Runtime behavior
</code></pre>
<p><strong>Double Validation</strong>:</p>
<ol>
<li>Nickel contracts: Type-safe, enum validation</li>
<li>Serde deserialization: Rust type checking</li>
</ol>
<p><strong>Benefits</strong>:</p>
<ul>
<li>Errors caught at export time</li>
<li>Runtime guaranteed valid config</li>
<li>Self-documenting schemas</li>
</ul>
<h2 id="storage-architecture"><a class="header" href="#storage-architecture">Storage Architecture</a></h2>
<h3 id="hybrid-strategy"><a class="header" href="#hybrid-strategy">Hybrid Strategy</a></h3>
<p><strong>Local Graph</strong> (per project):</p>
<ul>
<li>Storage: Filesystem (<code>.kogral/</code> directory)</li>
<li>Format: Markdown + YAML frontmatter</li>
<li>Version control: Git</li>
<li>Scope: Project-specific knowledge</li>
</ul>
<p><strong>Shared Graph</strong> (organization):</p>
<ul>
<li>Storage: SurrealDB (or synced filesystem)</li>
<li>Format: Same markdown (for compatibility)</li>
<li>Version control: Optional</li>
<li>Scope: Organization-wide guidelines</li>
</ul>
<p><strong>Sync</strong>:</p>
<pre><code>Filesystem (.kogral/)
↕ [bidirectional sync]
SurrealDB (central)
</code></pre>
<h3 id="file-layout"><a class="header" href="#file-layout">File Layout</a></h3>
<pre><code>.kogral/
├── config.toml # Graph metadata
├── notes/
│ ├── async-patterns.md # Individual note
│ └── error-handling.md
├── decisions/
│ ├── 0001-use-rust.md # ADR format
│ └── 0002-surrealdb.md
├── guidelines/
│ ├── rust-errors.md # Project guideline
│ └── testing.md
├── patterns/
│ └── repository.md
└── journal/
├── 2026-01-17.md # Daily journal
└── 2026-01-18.md
</code></pre>
<h2 id="query-engine"><a class="header" href="#query-engine">Query Engine</a></h2>
<h3 id="text-search"><a class="header" href="#text-search">Text Search</a></h3>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let results = graph.nodes.values()
.filter(|node| {
node.title.contains(&amp;query) ||
node.content.contains(&amp;query) ||
node.tags.iter().any(|tag| tag.contains(&amp;query))
})
.collect();
<span class="boring">}</span></code></pre></pre>
<h3 id="semantic-search"><a class="header" href="#semantic-search">Semantic Search</a></h3>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let query_embedding = embeddings.embed(vec![query]).await?;
let mut scored: Vec&lt;_&gt; = graph.nodes.values()
.filter_map(|node| {
let node_embedding = node.embedding.as_ref()?;
let similarity = cosine_similarity(&amp;query_embedding[0], node_embedding);
(similarity &gt;= threshold).then_some((node, similarity))
})
.collect();
scored.sort_by(|a, b| b.1.partial_cmp(&amp;a.1).unwrap());
<span class="boring">}</span></code></pre></pre>
<h3 id="cross-graph-query"><a class="header" href="#cross-graph-query">Cross-Graph Query</a></h3>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Query both project and shared graphs
let project_results = project_graph.search(&amp;query).await?;
let shared_results = shared_graph.search(&amp;query).await?;
// Merge with deduplication
let combined = merge_results(project_results, shared_results);
<span class="boring">}</span></code></pre></pre>
<h2 id="mcp-protocol-flow"><a class="header" href="#mcp-protocol-flow">MCP Protocol Flow</a></h2>
<pre><code>Claude Code kb-mcp kb-core
│ │ │
├─ JSON-RPC request ───→ │ │
│ kb/search │ │
│ {"query": "rust"} │ │
│ ├─ search() ──────────→ │
│ │ │
│ │ Query engine
│ │ Text + semantic
│ │ │
│ │ ←──── results ─────────┤
│ │ │
│ ←─ JSON-RPC response ──┤ │
│ {"results": [...]} │ │
</code></pre>
<h2 id="template-system"><a class="header" href="#template-system">Template System</a></h2>
<p><strong>Engine</strong>: Tera (Jinja2-like)</p>
<p><strong>Templates</strong>:</p>
<ol>
<li>
<p><strong>Document Templates</strong> (6):</p>
<ul>
<li><code>note.md.tera</code></li>
<li><code>decision.md.tera</code></li>
<li><code>guideline.md.tera</code></li>
<li><code>pattern.md.tera</code></li>
<li><code>journal.md.tera</code></li>
<li><code>execution.md.tera</code></li>
</ul>
</li>
<li>
<p><strong>Export Templates</strong> (4):</p>
<ul>
<li><code>logseq-page.md.tera</code></li>
<li><code>logseq-journal.md.tera</code></li>
<li><code>summary.md.tera</code></li>
<li><code>graph.json.tera</code></li>
</ul>
</li>
</ol>
<p><strong>Usage</strong>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let mut tera = Tera::new("templates/**/*.tera")?;
let rendered = tera.render("note.md.tera", &amp;context)?;
<span class="boring">}</span></code></pre></pre>
<h2 id="error-handling"><a class="header" href="#error-handling">Error Handling</a></h2>
<p><strong>Strategy</strong>: <code>thiserror</code> for structured errors</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>#[derive(Error, Debug)]
pub enum KbError {
#[error("Storage error: {0}")]
Storage(String),
#[error("Node not found: {0}")]
NodeNotFound(String),
#[error("Configuration error: {0}")]
Config(String),
#[error("Parse error: {0}")]
Parse(String),
#[error("Embedding error: {0}")]
Embedding(String),
}
<span class="boring">}</span></code></pre></pre>
<p><strong>Propagation</strong>: <code>?</code> operator throughout</p>
<h2 id="testing-strategy"><a class="header" href="#testing-strategy">Testing Strategy</a></h2>
<p><strong>Unit Tests</strong>: Per module (models, parser, storage)</p>
<p><strong>Integration Tests</strong>: Full workflow (add → save → load → query)</p>
<p><strong>Test Coverage</strong>:</p>
<ul>
<li>kb-core: 48 tests</li>
<li>kb-mcp: 5 tests</li>
<li>Total: 56 tests</li>
</ul>
<p><strong>Test Data</strong>: Fixtures in <code>tests/fixtures/</code></p>
<h2 id="performance-considerations"><a class="header" href="#performance-considerations">Performance Considerations</a></h2>
<p><strong>Node Lookup</strong>: O(1) via HashMap</p>
<p><strong>Semantic Search</strong>: O(n) with early termination (threshold filter)</p>
<p><strong>Storage</strong>:</p>
<ul>
<li>Filesystem: Lazy loading (load on demand)</li>
<li>Memory: Full graph in RAM</li>
<li>SurrealDB: Query optimization (indexes)</li>
</ul>
<p><strong>Embeddings</strong>:</p>
<ul>
<li>Cache embeddings in node metadata</li>
<li>Batch processing (configurable batch size)</li>
<li>Async generation (non-blocking)</li>
</ul>
<h2 id="security"><a class="header" href="#security">Security</a></h2>
<p><strong>No unsafe code</strong>: <code>#![forbid(unsafe_code)]</code></p>
<p><strong>Input validation</strong>:</p>
<ul>
<li>Nickel contracts validate config</li>
<li>serde validates JSON</li>
<li>Custom validation for user input</li>
</ul>
<p><strong>File operations</strong>:</p>
<ul>
<li>Path sanitization (no <code>../</code> traversal)</li>
<li>Permissions checking</li>
<li>Atomic writes (temp file + rename)</li>
</ul>
<h2 id="scalability"><a class="header" href="#scalability">Scalability</a></h2>
<p><strong>Small Projects</strong> (&lt; 1000 nodes):</p>
<ul>
<li>Filesystem storage</li>
<li>In-memory search</li>
<li>Local embeddings (fastembed)</li>
</ul>
<p><strong>Medium Projects</strong> (1000-10,000 nodes):</p>
<ul>
<li>Filesystem + SurrealDB sync</li>
<li>Semantic search with caching</li>
<li>Cloud embeddings (OpenAI/Claude)</li>
</ul>
<p><strong>Large Organizations</strong> (&gt; 10,000 nodes):</p>
<ul>
<li>SurrealDB primary</li>
<li>Distributed embeddings</li>
<li>Multi-graph federation</li>
</ul>
<h2 id="next-steps"><a class="header" href="#next-steps">Next Steps</a></h2>
<ul>
<li><strong>Graph Model Details</strong>: <a href="graph-model.html">Graph Model</a></li>
<li><strong>Storage Deep Dive</strong>: <a href="storage-architecture.html">Storage Architecture</a></li>
<li><strong>ADRs</strong>: <a href="adrs/001-nickel-vs-toml.html">Architectural Decisions</a></li>
<li><strong>Implementation</strong>: <a href="../contributing/development.html">Development Guide</a></li>
</ul>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../guides/best-practices.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../architecture/graph-model.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../guides/best-practices.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../architecture/graph-model.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="../elasticlunr.min.js"></script>
<script src="../mark.min.js"></script>
<script src="../searcher.js"></script>
<script src="../clipboard.min.js"></script>
<script src="../highlight.js"></script>
<script src="../book.js"></script>
<!-- Custom JS scripts -->
</div>
</body>
</html>