# burttwang/mempalace architecture

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

- Interactive diagram: https://gitdiagram.com/burttwang/mempalace
- Repository: https://github.com/burttwang/mempalace

## Overview

1. **This is a local-first Python memory system.**  
   The core package is `mempalace/`, exposed as both a CLI (`cli.py`, `__main__.py`) and an MCP server (`mcp_server.py`). The architecture is centered on ingesting local data, organizing it into a “palace” model, and retrieving it later through search or AI tools.

2. **There are two main ingest paths: projects and conversations.**  
   `miner.py` handles project/file ingestion, while `convo_miner.py` handles conversation exports and chunks them into exchange-based memory units. `normalize.py` standardizes multiple chat formats into a common transcript shape, and `split_mega_files.py` preprocesses concatenated transcript exports into per-session files.

3. **The storage layer is split between verbatim memory and structured metadata.**  
   The README makes the primary store explicit: raw memories are kept in ChromaDB as “drawers” with no default summarization. Wing/room metadata acts as an organization layer on top of that raw content. Configuration and user identity live locally in files under `~/.mempalace/`.

4. **Search is semantic, filtered, and local.**  
   `searcher.py` is the retrieval entry point, likely querying ChromaDB and applying optional wing/room constraints. The retrieval model is not just keyword search; it uses the palace taxonomy to narrow scope before semantic matching.

5. **The “palace” graph is the main navigation abstraction.**  
   `palace_graph.py` models the structural relationships described in the README: wings, rooms, halls, and tunnels. This graph is used for taxonomy, connectivity, traversal, and cross-wing discovery rather than as the primary content store.

6. **There is a separate temporal knowledge graph for facts.**  
   `knowledge_graph.py` stores entity relationships with validity windows, and the README says it uses SQLite locally. This graph supports time-aware queries, invalidation of obsolete facts, and timeline reconstruction. `entity_registry.py` and `entity_detector.py` support entity normalization and extraction around this graph.

7. **AAAK is a compression/representation layer, not the base store.**  
   `dialect.py` and `layers.py` define the “memory stack” and the AAAK dialect used for compact context loading or diary-style output. The key architectural boundary is that AAAK is separate from raw storage: it is used to compress or present memory, not to replace the verbatim source data.

8. **Onboarding and configuration shape the whole system.**  
   `onboarding.py` generates the initial palace setup, wing mappings, and identity bootstrap. `config.py` centralizes global settings such as palace path, collection name, and people/project mappings. This config is what lets the same ingestion/search pipeline adapt to different local datasets.

9. **The MCP server is the integration boundary to external AI clients.**  
   `mcp_server.py` exposes the memory system as tools for Claude, Cursor, Gemini, and other MCP-compatible clients. The tool surface covers read operations, write operations, graph queries, traversal, and agent diary access. Architecturally, this is the “AI-facing API” over the local storage and graph subsystems.

10. **There is automation around capture, not just retrieval.**  
   The shell hooks in `hooks/` are designed to save memory automatically during AI work sessions, including a pre-compact save. This makes memory capture event-driven: messages or context pressure trigger writes into the palace instead of relying on manual ingestion only.

11. **Benchmarks, examples, and tests are first-class support systems.**  
   `benchmarks/` contains reproducible runners for LongMemEval, LoCoMo, and related evaluations. `examples/` shows mining, MCP setup, and integration patterns. `tests/` covers config, normalization, search, graph behavior, mining, MCP server behavior, and version consistency, indicating the main architectural seams are intentionally unit-tested.

12. **The repo is packaged as a standard Python distribution.**  
   `pyproject.toml`, `uv.lock`, and `py.typed` show this is a typed Python package intended for installation as a CLI/library. The surrounding docs, issue templates, and CI workflow support that packaging model rather than a monolithic application deployment.

13. **A useful way to diagram it is as three planes:**  
   - **Ingest plane:** files/transcripts → normalization/splitting → mining  
   - **Memory plane:** ChromaDB drawers + palace graph + knowledge graph + AAAK/layers  
   - **Access plane:** CLI, search API, MCP server, hooks, and benchmark/test harnesses  
   Those are the main architectural boundaries that matter most when drawing the system.

Main entry points: [`mempalace/mcp_server.py`](https://github.com/burttwang/mempalace/blob/main/mempalace/mcp_server.py) (MCP server), [`mempalace/searcher.py`](https://github.com/burttwang/mempalace/blob/main/mempalace/searcher.py) (Search), [`mempalace/knowledge_graph.py`](https://github.com/burttwang/mempalace/blob/main/mempalace/knowledge_graph.py) (Knowledge graph), [`tests/test_mcp_server.py`](https://github.com/burttwang/mempalace/blob/main/tests/test_mcp_server.py) (Tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingest plane"]
  node_normalize["Normalize<br/>[normalize.py]"]
  node_split_mega_files["Split exports<br/>export splitter"]
  node_convo_miner["Conversation miner<br/>conversation ingest<br/>[convo_miner.py]"]
  node_miner["Project miner<br/>project ingest<br/>[miner.py]"]
end

subgraph group_memory["Memory plane"]
  node_chroma_drawers[("Drawers<br/>vector store")]
  node_palace_graph{{"Palace graph<br/>taxonomy graph<br/>[palace_graph.py]"}}
  node_knowledge_graph[("Knowledge graph<br/>temporal graph<br/>[knowledge_graph.py]")]
  node_entity_registry["Entity registry<br/>entity normalization<br/>[entity_registry.py]"]
  node_entity_detector["Entity detector<br/>entity extraction<br/>[entity_detector.py]"]
  node_layers{{"Memory layers<br/>compression layer<br/>[layers.py]"}}
  node_dialect["AAAK dialect<br/>presentation format<br/>[dialect.py]"]
end

subgraph group_access["Access plane"]
  node_searcher["Search<br/>semantic retrieval<br/>[searcher.py]"]
  node_mcp_server["MCP server<br/>ai tool API<br/>[mcp_server.py]"]
  node_cli["CLI<br/>command interface<br/>[cli.py]"]
end

subgraph group_support["Support plane"]
  node_onboarding["Onboarding<br/>bootstrap setup<br/>[onboarding.py]"]
  node_config["Config<br/>local settings<br/>[config.py]"]
  node_hooks["Shell hooks<br/>automation"]
  node_benchmarks["Benchmarks<br/>evaluation suite<br/>[README.md]"]
  node_tests["Tests<br/>verification suite<br/>[test_mcp_server.py]"]
  node_package["Package<br/>python dist<br/>[pyproject.toml]"]
end

node_split_mega_files -->|"prepares"| node_normalize
node_normalize -->|"feeds"| node_convo_miner
node_convo_miner -->|"stores"| node_chroma_drawers
node_miner -->|"stores"| node_chroma_drawers
node_miner -->|"organizes"| node_palace_graph
node_entity_detector -->|"normalizes"| node_entity_registry
node_entity_registry -->|"updates"| node_knowledge_graph
node_entity_detector -->|"extracts"| node_knowledge_graph
node_layers -->|"renders"| node_dialect
node_chroma_drawers -->|"queries"| node_searcher
node_palace_graph -->|"filters"| node_searcher
node_knowledge_graph -->|"augments"| node_searcher
node_searcher -->|"exposes"| node_mcp_server
node_palace_graph -->|"traverses"| node_mcp_server
node_knowledge_graph -->|"queries"| node_mcp_server
node_dialect -->|"formats"| node_mcp_server
node_config -->|"configures"| node_cli
node_config -->|"configures"| node_mcp_server
node_onboarding -->|"bootstraps"| node_config
node_hooks -->|"automates"| node_miner
node_benchmarks -->|"evaluates"| node_searcher
node_tests -->|"verifies"| node_normalize
node_tests -->|"verifies"| node_searcher
node_tests -->|"verifies"| node_mcp_server
node_package -->|"packages"| node_cli
node_package -->|"packages"| node_mcp_server

click node_normalize "https://github.com/burttwang/mempalace/blob/main/mempalace/normalize.py"
click node_split_mega_files "https://github.com/burttwang/mempalace/blob/main/mempalace/split_mega_files.py"
click node_convo_miner "https://github.com/burttwang/mempalace/blob/main/mempalace/convo_miner.py"
click node_miner "https://github.com/burttwang/mempalace/blob/main/mempalace/miner.py"
click node_palace_graph "https://github.com/burttwang/mempalace/blob/main/mempalace/palace_graph.py"
click node_knowledge_graph "https://github.com/burttwang/mempalace/blob/main/mempalace/knowledge_graph.py"
click node_entity_registry "https://github.com/burttwang/mempalace/blob/main/mempalace/entity_registry.py"
click node_entity_detector "https://github.com/burttwang/mempalace/blob/main/mempalace/entity_detector.py"
click node_layers "https://github.com/burttwang/mempalace/blob/main/mempalace/layers.py"
click node_dialect "https://github.com/burttwang/mempalace/blob/main/mempalace/dialect.py"
click node_searcher "https://github.com/burttwang/mempalace/blob/main/mempalace/searcher.py"
click node_mcp_server "https://github.com/burttwang/mempalace/blob/main/mempalace/mcp_server.py"
click node_cli "https://github.com/burttwang/mempalace/blob/main/mempalace/cli.py"
click node_onboarding "https://github.com/burttwang/mempalace/blob/main/mempalace/onboarding.py"
click node_config "https://github.com/burttwang/mempalace/blob/main/mempalace/config.py"
click node_hooks "https://github.com/burttwang/mempalace/blob/main/hooks/mempal_save_hook.sh"
click node_benchmarks "https://github.com/burttwang/mempalace/blob/main/benchmarks/README.md"
click node_tests "https://github.com/burttwang/mempalace/blob/main/tests/test_mcp_server.py"
click node_package "https://github.com/burttwang/mempalace/blob/main/pyproject.toml"

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_normalize,node_split_mega_files,node_convo_miner,node_miner toneBlue
class node_chroma_drawers,node_palace_graph,node_knowledge_graph,node_entity_registry,node_entity_detector,node_layers,node_dialect toneAmber
class node_searcher,node_mcp_server,node_cli toneMint
class node_onboarding,node_config,node_hooks,node_benchmarks,node_tests,node_package toneRose
```

## Components

### Ingest plane

Normalize local data, split exports, and mine memories into the system.

- [Normalize](https://github.com/burttwang/mempalace/blob/main/mempalace/normalize.py): transcript normalizer · Converts different chat export formats into a common transcript shape. · `mempalace/normalize.py`
- [Split exports](https://github.com/burttwang/mempalace/blob/main/mempalace/split_mega_files.py): export splitter · Breaks concatenated transcript dumps into per-session files before mining. · `mempalace/split_mega_files.py`
- [Conversation miner](https://github.com/burttwang/mempalace/blob/main/mempalace/convo_miner.py): conversation ingest · Chunks conversation exports into exchange-based memory units. · `mempalace/convo_miner.py`
- [Project miner](https://github.com/burttwang/mempalace/blob/main/mempalace/miner.py): project ingest · Ingests local project and file data into memory drawers. · `mempalace/miner.py`

### Memory plane

Core storage and graph structures for verbatim memories, palace layout, and facts.

- **Drawers**: vector store · Primary verbatim memory store in ChromaDB; keeps raw memories without default summarization.
- [Palace graph](https://github.com/burttwang/mempalace/blob/main/mempalace/palace_graph.py): taxonomy graph · Represents wings, rooms, halls, and tunnels for organization and traversal. · `mempalace/palace_graph.py`
- [Knowledge graph](https://github.com/burttwang/mempalace/blob/main/mempalace/knowledge_graph.py): temporal graph · Stores entity relationships with validity windows in local SQLite. · `mempalace/knowledge_graph.py`
- [Entity registry](https://github.com/burttwang/mempalace/blob/main/mempalace/entity_registry.py): entity normalization · Resolves and normalizes entities used by the temporal knowledge graph. · `mempalace/entity_registry.py`
- [Entity detector](https://github.com/burttwang/mempalace/blob/main/mempalace/entity_detector.py): entity extraction · Extracts entities and relationship signals from local content for the knowledge graph. · `mempalace/entity_detector.py`
- [Memory layers](https://github.com/burttwang/mempalace/blob/main/mempalace/layers.py): compression layer · Defines the memory stack used to assemble compact context views. · `mempalace/layers.py`
- [AAAK dialect](https://github.com/burttwang/mempalace/blob/main/mempalace/dialect.py): presentation format · Encodes compact, diary-style memory representations for loading or display. · `mempalace/dialect.py`

### Access plane

CLI, MCP, and search interfaces that read and write the local memory system.

- [Search](https://github.com/burttwang/mempalace/blob/main/mempalace/searcher.py): semantic retrieval · Queries local memories with optional palace-scope filters. · `mempalace/searcher.py`
- [MCP server](https://github.com/burttwang/mempalace/blob/main/mempalace/mcp_server.py): ai tool API · Exposes read/write, graph traversal, and diary tools to MCP-compatible clients. · `mempalace/mcp_server.py`
- [CLI](https://github.com/burttwang/mempalace/blob/main/mempalace/cli.py): command interface · Local command-line entry point for mining, search, and system operations. · `mempalace/cli.py`

### Support plane

Onboarding, automation, packaging, examples, benchmarks, and tests around the core system.

- [Onboarding](https://github.com/burttwang/mempalace/blob/main/mempalace/onboarding.py): bootstrap setup · Creates the initial palace setup, wing mappings, and identity bootstrap. · `mempalace/onboarding.py`
- [Config](https://github.com/burttwang/mempalace/blob/main/mempalace/config.py): local settings · Centralizes palace path, collection name, and user/project mappings. · `mempalace/config.py`
- [Shell hooks](https://github.com/burttwang/mempalace/blob/main/hooks/mempal_save_hook.sh): automation · Auto-save and pre-compact hooks that capture memory during AI work sessions. · `hooks/mempal_save_hook.sh`
- [Benchmarks](https://github.com/burttwang/mempalace/blob/main/benchmarks/README.md): evaluation suite · Reproducible runners for LongMemEval, LoCoMo, and related evaluations. · `benchmarks/README.md`
- [Tests](https://github.com/burttwang/mempalace/blob/main/tests/test_mcp_server.py): verification suite · Covers config, normalization, search, graphs, mining, MCP, and version consistency. · `tests/test_mcp_server.py`
- [Package](https://github.com/burttwang/mempalace/blob/main/pyproject.toml): python dist · Typed Python package and standard distribution metadata. · `pyproject.toml`

## Connections

- Split exports → Normalize: prepares · Splits large exports into session files before normalization.
- Normalize → Conversation miner: feeds · Standardized transcripts are consumed by conversation mining.
- Conversation miner → Drawers: stores · Writes chunked conversation memories into the raw memory store.
- Project miner → Drawers: stores · Indexes project and file memories as verbatim drawers.
- Project miner → Palace graph: organizes · Assigns mined content into the palace structure for navigation.
- Entity detector → Entity registry: normalizes · Detected entities are resolved through the registry.
- Entity registry → Knowledge graph: updates · Canonical entities anchor temporal relationships in the graph.
- Entity detector → Knowledge graph: extracts · Entity and relationship signals populate the fact graph.
- Memory layers → AAAK dialect: renders · Compression layers produce compact AAAK output.
- Drawers → Search: queries · Semantic retrieval reads from the raw memory store.
- Palace graph → Search: filters · Wing and room scope constrains retrieval.
- Knowledge graph → Search: augments · Temporal facts can support search and reconstruction.
- Search → MCP server: exposes · Retrieval is surfaced as AI tools through the MCP server.
- Palace graph → MCP server: traverses · Graph traversal and navigation tools use the palace model.
- Knowledge graph → MCP server: queries · MCP tools can read time-aware entity facts.
- AAAK dialect → MCP server: formats · Compact memory views are exposed to clients.
- Config → CLI: configures · CLI behavior depends on local settings and mappings.
- Config → MCP server: configures · Server paths and collection settings come from local config.
- Onboarding → Config: bootstraps · Initial setup populates the core local configuration.
- Shell hooks → Project miner: automates · Hooks trigger capture and save flows during AI sessions.
- Benchmarks → Search: evaluates · Benchmark runners measure retrieval behavior.
- Tests → Normalize: verifies · Tests cover transcript normalization behavior.
- Tests → Search: verifies · Tests cover retrieval and filtering behavior.
- Tests → MCP server: verifies · Tests cover the AI-facing tool boundary.
- Package → CLI: packages · The distribution exposes the CLI entry point.
- Package → MCP server: packages · The distribution includes the server runtime.
