kogral/docs/book/diagrams/storage-architecture.svg

138 lines
7.8 KiB
XML
Raw Normal View History

2026-01-23 16:11:07 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<svg width="900" height="650" xmlns="http://www.w3.org/2000/svg">
<defs>
<style>
.filesystem-box { fill: #fff3e0; stroke: #f57c00; stroke-width: 2; }
.surrealdb-box { fill: #e1f5fe; stroke: #0277bd; stroke-width: 2; }
.memory-box { fill: #f3e5f5; stroke: #7b1fa2; stroke-width: 2; }
.sync-box { fill: #fff9c4; stroke: #f57f17; stroke-width: 2; }
.graph-box { fill: #e8f5e9; stroke: #388e3c; stroke-width: 2; }
.text { font-family: Arial, sans-serif; font-size: 13px; fill: #333; }
.title { font-family: Arial, sans-serif; font-size: 16px; font-weight: bold; fill: #333; }
.small-text { font-family: Arial, sans-serif; font-size: 11px; fill: #666; }
.code { font-family: 'Courier New', monospace; font-size: 11px; fill: #333; }
.arrow { stroke: #666; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
.bidirectional { stroke: #f57f17; stroke-width: 3; fill: none; marker-end: url(#orangearrow); marker-start: url(#orangearrow-start); }
</style>
<marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#666" />
</marker>
<marker id="orangearrow" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#f57f17" />
</marker>
<marker id="orangearrow-start" markerWidth="10" markerHeight="10" refX="1" refY="3" orient="auto">
<polygon points="10 0, 0 3, 10 6" fill="#f57f17" />
</marker>
</defs>
<!-- Title -->
<text x="450" y="30" class="title" text-anchor="middle" font-size="20">Hybrid Storage Architecture</text>
<text x="450" y="52" class="small-text" text-anchor="middle">Filesystem (git-friendly) + SurrealDB (scalable) + In-Memory (cache)</text>
<!-- Graph Engine (Top Center) -->
<rect x="300" y="80" width="300" height="100" class="graph-box" rx="8"/>
<text x="450" y="105" class="title" text-anchor="middle">Graph Engine (kogral-core)</text>
<text x="450" y="128" class="text" text-anchor="middle">Unified API: add_node, get_node, query</text>
<text x="450" y="145" class="small-text" text-anchor="middle">HashMap&lt;String, Node&gt; for O(1) access</text>
<text x="450" y="162" class="small-text" text-anchor="middle">Multi-graph: local (project) + shared (central)</text>
<!-- Storage Trait Interface -->
<rect x="250" y="200" width="400" height="60" fill="#eeeeee" stroke="#999" stroke-width="2" rx="6"/>
<text x="450" y="220" class="title" text-anchor="middle">Storage Trait</text>
<text x="450" y="238" class="code" text-anchor="middle">trait Storage: save(), load(), delete(), list(), search()</text>
<text x="450" y="252" class="small-text" text-anchor="middle">Abstraction for all backends</text>
<!-- Arrows from Graph Engine to Storage Trait -->
<path d="M 450 180 L 450 200" class="arrow"/>
<!-- Three Storage Backends -->
<!-- Filesystem Storage (Left) -->
<rect x="50" y="300" width="220" height="300" class="filesystem-box" rx="8"/>
<text x="160" y="325" class="title" text-anchor="middle">Filesystem Storage</text>
<text x="60" y="350" class="text" font-weight="bold">Purpose:</text>
<text x="60" y="368" class="small-text">• Git-friendly</text>
<text x="60" y="383" class="small-text">• Human-readable</text>
<text x="60" y="398" class="small-text">• Logseq compatible</text>
<text x="60" y="420" class="text" font-weight="bold">Format:</text>
<text x="60" y="438" class="code">.kogral/notes/2026-01-17-topic.md</text>
<text x="60" y="453" class="code">---</text>
<text x="60" y="468" class="code">id: note-123</text>
<text x="60" y="483" class="code">type: note</text>
<text x="60" y="498" class="code">tags: [rust, architecture]</text>
<text x="60" y="513" class="code">---</text>
<text x="60" y="528" class="code"># Title</text>
<text x="60" y="543" class="code">Content with [[wikilinks]]</text>
<text x="60" y="565" class="text" font-weight="bold">Watch:</text>
<text x="60" y="583" class="small-text">notify crate (file system events)</text>
<!-- SurrealDB Storage (Center) -->
<rect x="310" y="300" width="280" height="300" class="surrealdb-box" rx="8"/>
<text x="450" y="325" class="title" text-anchor="middle">SurrealDB Storage</text>
<text x="320" y="350" class="text" font-weight="bold">Purpose:</text>
<text x="320" y="368" class="small-text">• Scalable queries</text>
<text x="320" y="383" class="small-text">• Advanced graph operations</text>
<text x="320" y="398" class="small-text">• Shared organizational knowledge</text>
<text x="320" y="420" class="text" font-weight="bold">Schema:</text>
<text x="320" y="438" class="code">DEFINE TABLE node SCHEMAFULL;</text>
<text x="320" y="453" class="code">DEFINE FIELD id ON node TYPE string;</text>
<text x="320" y="468" class="code">DEFINE FIELD type ON node TYPE string;</text>
<text x="320" y="483" class="code">DEFINE FIELD embedding ON node</text>
<text x="320" y="498" class="code"> TYPE array&lt;number&gt;;</text>
<text x="320" y="520" class="text" font-weight="bold">Features:</text>
<text x="320" y="538" class="small-text">• Graph queries (RELATE)</text>
<text x="320" y="553" class="small-text">• Vector search (embeddings)</text>
<text x="320" y="568" class="small-text">• Full-text search</text>
<text x="320" y="583" class="small-text">• Multi-tenancy (namespace/db)</text>
<!-- In-Memory Storage (Right) -->
<rect x="630" y="300" width="220" height="300" class="memory-box" rx="8"/>
<text x="740" y="325" class="title" text-anchor="middle">In-Memory Storage</text>
<text x="640" y="350" class="text" font-weight="bold">Purpose:</text>
<text x="640" y="368" class="small-text">• Fast development</text>
<text x="640" y="383" class="small-text">• Testing (ephemeral)</text>
<text x="640" y="398" class="small-text">• Cache layer</text>
<text x="640" y="420" class="text" font-weight="bold">Implementation:</text>
<text x="640" y="438" class="code">DashMap&lt;String, Node&gt;</text>
<text x="640" y="453" class="small-text">Concurrent HashMap</text>
<text x="640" y="475" class="text" font-weight="bold">Features:</text>
<text x="640" y="493" class="small-text">• O(1) access</text>
<text x="640" y="508" class="small-text">• No persistence</text>
<text x="640" y="523" class="small-text">• Thread-safe</text>
<text x="640" y="538" class="small-text">• No setup required</text>
<text x="640" y="560" class="text" font-weight="bold">Use Cases:</text>
<text x="640" y="578" class="small-text">• cargo test (test mode)</text>
<text x="640" y="593" class="small-text">• Session cache</text>
<!-- Arrows from Storage Trait to backends -->
<path d="M 300 230 L 160 300" class="arrow"/>
<path d="M 450 260 L 450 300" class="arrow"/>
<path d="M 600 230 L 740 300" class="arrow"/>
<!-- Sync Mechanism -->
<rect x="80" y="430" width="180" height="80" class="sync-box" rx="6"/>
<text x="170" y="450" class="text" text-anchor="middle" font-weight="bold">Sync Mechanism</text>
<text x="170" y="468" class="small-text" text-anchor="middle">Bidirectional sync</text>
<text x="90" y="486" class="small-text">• File change → SurrealDB</text>
<text x="90" y="501" class="small-text">• SurrealDB update → File</text>
<!-- Bidirectional arrow between Filesystem and SurrealDB -->
<path d="M 270 450 L 310 450" class="bidirectional"/>
<text x="290" y="445" class="small-text" fill="#f57f17">sync</text>
<!-- Configuration note -->
<rect x="50" y="620" width="800" height="20" fill="#e3f2fd" stroke="#1976d2" stroke-width="1" rx="4"/>
<text x="450" y="635" class="small-text" text-anchor="middle">💡 Configured via .kogral-config/core/kogral.ncl: primary storage + optional secondary (SurrealDB) + sync settings</text>
</svg>