digraph flow {
  rankdir="LR";
  newrank=true;
  compound=true;
  nodesep=0.35;
  ranksep=0.55;
  graph [fontname="Helvetica", fontsize=11, labelloc="t"];
  node  [fontname="Helvetica", fontsize=10];
  edge  [fontname="Helvetica", fontsize=9];
  label="Core ↔ Backend cache + component OVERVIEW — two columns, who-calls-who (2026-07-06)
LEFT=CORE (yadgar/, SHIPPED core Cache #164) · RIGHT=BACKEND (yadgar/backend/, recall pipeline + NEW backend Cache) · TWO separate caches (one per service, they never merge) · ONLY 2 signals cross the boundary: recall() HTTP POST (solid) + data_epoch (async dashed)";
  subgraph "cluster_core" {
    label="CORE  (yadgar/, --cpus 1) — MCP tools + forwarder + SHIPPED unified Cache (yadgar/cache.py #164) + data_epoch bus";
    style=filled;
    bgcolor="#eef4fb";
    color="#4a72a8";
    fontcolor="#26456b";
    fontname="Helvetica-Bold";
    "read_tools" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="CORE read tools\nproject_brief · wiki_query · wiki_read\nagent_prompt_prelude"];
    "recall_fwd" [shape="diamond", style="filled", fillcolor="#fdf3c8", label="recall()  — THIN FORWARDER\ntool.recall → _forward_to_backend\n(no pipeline in core)"];
    "write_tools" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="CORE write tools\nmemorize · forget · anchor\nmemory_update(content) · wiki_add"];
    "bg_cycles" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="CORE background cycles\nconsolidation / nightly (merge·dedup·create·delete)\nvacuum (delete) · reembed (embedding change)"];
    "session" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="CORE session / state\ncheckpoint · session SR transition\n(stay in core — no cache, no epoch bump)"];
    "core_cache" [label="Core\ Cache\ —\ yadgar/cache.py\ (ONE\ class,\ SHIPPED\ #164)|<project_brief> project_brief|<wiki_read> wiki_read|<wiki_query> wiki_query|<agent_prompt_prelude> agent_prompt_prelude|<config> config|<branch> branch\ /\ default_branch|<rate_limit> rate_limit|(epoch\ /\ TTL\ invalidation\ —\ stays\ in\ core)", shape="Mrecord", style="filled,dashed", fillcolor="#e7f6e7", color="#3a8f3a"];
    "epoch_bus" [shape="diamond", style="filled", fillcolor="#fdf3c8", label="data_epoch bus\n_recall_shadow.bump_epoch → structural data_epoch++\nbumped by writes AND background cycles\n(pure heat-decay does NOT bump — heat never cached)"];
  }
  subgraph "cluster_backend" {
    label="BACKEND  (yadgar/backend/, --cpus 2) — backend.recall pipeline + NEW unified Cache (yadgar/backend/cache.py) + ML + DB";
    style=filled;
    bgcolor="#fbf0ea";
    color="#b5744a";
    fontcolor="#7a4620";
    fontname="Helvetica-Bold";
    "backend_recall" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="backend.recall  (POST /recall)\nruns the WHOLE pipeline:\nencode_query · vector · fts · fanout/fusion · spreading · ppr\nentities · wiki-candidates · CE passes · build_results · engram_links · db"];
    "backend_cache" [label="Backend\ Cache\ —\ yadgar/backend/cache.py\ (ONE\ class)|<ce> ce\ \ ·\ \ query_sha:text_sha:ckpt\ \ ·\ \ ModelCkpt\ [SHIPPED,\ folds\ in]|<embed> embed\ \ ·\ \ text_sha:ckpt\ \ ·\ \ ModelCkpt\ [SHIPPED,\ folds\ in]|<memory_doc> memory_doc\ \ ·\ \ memory_id:data_epoch\ \ ·\ \ DataEpoch\ [NEW]|<engram_slot> engram_slot\ \ ·\ \ slot_index:data_epoch\ \ ·\ \ DataEpoch\ [NEW]|<graph> graph\ \ ·\ \ entity_id:data_epoch\ \ ·\ \ DataEpoch\ [NEW]", shape="Mrecord", style="filled,dashed", fillcolor="#e7f6e7", color="#3a8f3a"];
    "ml" [shape="box", style="filled", fillcolor="#f5e1f5", label="ML client (LocalMLClient)\nCE model + embed model"];
    "db" [shape="cylinder", style="filled", fillcolor="#fce3d6", label="Storage / DB\nSurrealDB"];
  }
  subgraph "cluster_legend" {
    label="Legend";
    style=filled;
    bgcolor="#f0f0f0";
    color="#888888";
    fontcolor="#555555";
    fontname="Helvetica-Bold";
    "leg_shipped" [shape="box", style="rounded,filled,dashed", fillcolor="#e7f6e7", label="SHIPPED\ncore unified Cache (#164) + backend ce/embed\n(exist today as loose LRUCache)"];
    "leg_new" [shape="diamond", style="filled", fillcolor="#fdf3c8", label="NEW (this train)\nunified backend Cache CLASS itself\n+ memory_doc / engram_slot / graph namespaces\n+ cross-service data_epoch signal"];
    "leg_bound" [shape="box", style="rounded,filled", fillcolor="#dbe9fb", label="TWO caches, one per service — they NEVER merge.\nONLY 2 signals cross core↔backend:\nrecall() HTTP POST (solid) · data_epoch (async dashed)"];
  }
  "read_tools" -> "core_cache" [color="#333333", style="solid", label="consult (project_brief/wiki/prelude)"];
  "write_tools" -> "epoch_bus" [color="#333333", style="solid", label="bump_epoch"];
  "bg_cycles" -> "epoch_bus" [color="#333333", style="solid", label="bump_epoch (structural)"];
  "recall_fwd" -> "backend_recall" [color="#333333", style="solid", label="HTTP POST /recall (traceparent)"];
  "epoch_bus" -> "backend_cache":"memory_doc" [color="#6a8f3a", style="dashed", label="data_epoch on each recall req → in key"];
  "epoch_bus" -> "backend_cache":"engram_slot" [color="#6a8f3a", style="dashed", label="data_epoch → in key"];
  "epoch_bus" -> "backend_cache":"graph" [color="#6a8f3a", style="dashed", label="data_epoch → in key"];
  "backend_recall" -> "backend_cache":"ce" [color="#333333", style="solid", label="CE passes (crossfuse/cross_encoder/multi_passage)"];
  "backend_recall" -> "backend_cache":"embed" [color="#333333", style="solid", label="encode_query"];
  "backend_recall" -> "backend_cache":"memory_doc" [color="#333333", style="solid", label="build_results"];
  "backend_recall" -> "backend_cache":"engram_slot" [color="#333333", style="solid", label="engram_links"];
  "backend_recall" -> "backend_cache":"graph" [color="#333333", style="solid", label="spreading + ppr"];
  "backend_cache":"ce" -> "ml" [color="#333333", style="solid", label="miss → CE model (ckpt_sha busts)"];
  "backend_cache":"embed" -> "ml" [color="#333333", style="solid", label="miss → embed model (ckpt_sha busts)"];
  "backend_cache":"memory_doc" -> "db" [color="#333333", style="solid", label="miss → fetch doc"];
  "backend_cache":"engram_slot" -> "db" [color="#333333", style="solid", label="miss → fetch slot"];
  "backend_cache":"graph" -> "db" [color="#333333", style="solid", label="miss → fetch neighbours"];
  "leg_shipped" -> "leg_new" [color="#999999", style="dashed"];
  "leg_new" -> "leg_bound" [color="#999999", style="dashed"];
}
