# felixsim/bonsai-memory architecture

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

- Interactive diagram: https://gitdiagram.com/felixsim/bonsai-memory
- Repository: https://github.com/felixsim/bonsai-memory

## Overview

Bonsai Memory is a skill and set of shell commands for turning an agent’s flat persistent memory into a compact, progressively loaded hierarchy. The documented workflow starts with an agent using the skill to migrate memory: sections are extracted, classified into domains, written as topic files, and summarized in branch and root indexes. The repository also names commands for reflection, reindexing, status, and purge. Their implementations were not provided, so those branches are shown without asserted call relationships.

Main entry points: [`scripts/bonsai-migrate.sh`](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-migrate.sh) (Migration), [`SKILL.md`](https://github.com/felixsim/bonsai-memory/blob/main/SKILL.md) (Bonsai skill), [`scripts/bonsai-reflect.sh`](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reflect.sh) (Reflection), [`scripts/bonsai-reindex.sh`](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reindex.sh) (Reindex)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Memory workflow"]
  node_skill["Bonsai skill<br/>[SKILL.md]"]
  node_migration["Migration<br/>[bonsai-migrate.sh]"]
  node_extraction["Section extraction"]
  node_classification["Domain classification"]
end

subgraph group_commands["Memory commands"]
  node_reflection["Reflection<br/>[bonsai-reflect.sh]"]
  node_reindex["Reindex<br/>[bonsai-reindex.sh]"]
  node_status["Status<br/>[bonsai-status.sh]"]
  node_purge["Purge<br/>[bonsai-purge.sh]"]
end

subgraph group_memory["Memory structure"]
  node_flatmemory["Flat memory"]
  node_topicfiles["Domain topic files"]
  node_branchindex["Branch indexes"]
  node_rootindex["Root index"]
end

node_user(("Agent user"))
node_agent(("AI agent"))

node_user -->|"requests install"| node_agent
node_agent -->|"reviews and installs"| node_skill
node_agent -.->|"runs migration"| node_migration
node_migration -.->|"reads"| node_flatmemory
node_agent -->|"parses sections"| node_flatmemory
node_flatmemory -->|"splits sections"| node_extraction
node_extraction -->|"classifies headings"| node_classification
node_classification -->|"writes sections"| node_topicfiles
node_topicfiles -->|"summarized in"| node_branchindex
node_branchindex -->|"indexed into"| node_rootindex
node_agent -->|"loads on boot"| node_rootindex
node_agent -->|"loads on demand"| node_branchindex
node_agent -->|"loads on demand"| node_topicfiles
node_agent -.->|"uses command"| node_reflection
node_agent -.->|"uses command"| node_reindex
node_agent -.->|"uses command"| node_status
node_agent -.->|"uses command"| node_purge

click node_skill "https://github.com/felixsim/bonsai-memory/blob/main/SKILL.md"
click node_migration "https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-migrate.sh"
click node_reflection "https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reflect.sh"
click node_reindex "https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reindex.sh"
click node_status "https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-status.sh"
click node_purge "https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-purge.sh"

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_skill,node_migration,node_extraction,node_classification,node_user toneBlue
class node_reflection,node_reindex,node_status,node_purge toneAmber
class node_flatmemory,node_topicfiles,node_branchindex,node_rootindex toneMint
class node_agent toneIndigo
```

## Components

### Memory workflow

- [Bonsai skill](https://github.com/felixsim/bonsai-memory/blob/main/SKILL.md): `SKILL.md`
- [Migration](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-migrate.sh): `scripts/bonsai-migrate.sh`
- **Section extraction**
- **Domain classification**

### Memory commands

- [Reflection](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reflect.sh): `scripts/bonsai-reflect.sh`
- [Reindex](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-reindex.sh): `scripts/bonsai-reindex.sh`
- [Status](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-status.sh): `scripts/bonsai-status.sh`
- [Purge](https://github.com/felixsim/bonsai-memory/blob/main/scripts/bonsai-purge.sh): `scripts/bonsai-purge.sh`

### Memory structure

- **Flat memory**
- **Domain topic files**
- **Branch indexes**
- **Root index**

### Other components

- **Agent user**
- **AI agent**

## Connections

- Agent user → AI agent: requests install (evidence: `README.md`)
- AI agent → Bonsai skill: reviews and installs (evidence: `README.md`)
- AI agent → Migration: runs migration
- Migration → Flat memory: reads
- AI agent → Flat memory: parses sections (evidence: `README.md`)
- Flat memory → Section extraction: splits sections (evidence: `README.md`)
- Section extraction → Domain classification: classifies headings (evidence: `README.md`)
- Domain classification → Domain topic files: writes sections (evidence: `README.md`)
- Domain topic files → Branch indexes: summarized in (evidence: `README.md`)
- Branch indexes → Root index: indexed into (evidence: `README.md`)
- AI agent → Root index: loads on boot (evidence: `README.md`)
- AI agent → Branch indexes: loads on demand (evidence: `README.md`)
- AI agent → Domain topic files: loads on demand (evidence: `README.md`)
- AI agent → Reflection: uses command
- AI agent → Reindex: uses command
- AI agent → Status: uses command
- AI agent → Purge: uses command
