# shoaibrayeen/memdex architecture

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

- Interactive diagram: https://gitdiagram.com/shoaibrayeen/memdex
- Repository: https://github.com/shoaibrayeen/memdex

## Overview

Memdex is a local-first memory optimizer for AI coding assistants. Its main workflow discovers project memory, parses it into units, optimizes and organizes those units, writes a compact MEMORY.md index and focused files, then embeds and indexes them for semantic search. The CLI also exposes maintenance, bootstrap, refresh, history, restore, and dashboard features. The graph follows documented capabilities and source-index references; unsampled implementation details are not treated as inspected, so uncertain connections are omitted.

Main entry points: [`src/memdex/pipeline.py`](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/pipeline.py) (Run orchestration), [`src/memdex/cli.py`](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/cli.py) (Memdex CLI), [`src/memdex/ui/server.py`](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/ui/server.py) (Local dashboard), [`src/memdex/store.py`](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/store.py) (Local vector store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_cli["Memdex CLI<br/>[cli.py]"]
  node_config["Project configuration<br/>[config.py]"]
end

subgraph group_process["Memory processing"]
  node_discovery["Memory discovery<br/>[discovery.py]"]
  node_parsing["Markdown parsing<br/>[parsing.py]"]
  node_optimization["Memory optimization<br/>[deterministic.py]"]
  node_llmopt["Optional LLM refinement<br/>[llm.py]"]
  node_identity["Stable identity<br/>[identity.py]"]
  node_layout["Memory file layout<br/>[layout.py]"]
  node_pipeline["Run orchestration<br/>[pipeline.py]"]
end

subgraph group_indexing["Search and persistence"]
  node_indexdoc["Index generation<br/>[indexdoc.py]"]
  node_embed["Embedding providers<br/>[local.py]"]
  node_vectorstore[("Local vector store<br/>[store.py]")]
end

subgraph group_operations["Project operations"]
  node_refresh["Memory refresh<br/>[refresh.py]"]
  node_bootstrap["Memory bootstrap<br/>[bootstrap.py]"]
  node_backup["Backup and restore<br/>[backup.py]"]
  node_audit["Activity audit<br/>[audit.py]"]
end

subgraph group_presentation["Reporting and dashboard"]
  node_tokens["Token counting<br/>[tokens.py]"]
  node_output["CLI reporting<br/>[output.py]"]
  node_dashboard["Local dashboard<br/>[server.py]"]
end

node_user(("Project user"))
node_assistant(("AI coding assistant"))
node_llmservice(("OpenAI-compatible LLM"))

node_user -->|"runs commands"| node_cli
node_cli -->|"runs workflow"| node_pipeline
node_cli -->|"loads settings"| node_config
node_pipeline -->|"discovers sources"| node_discovery
node_pipeline -->|"parses memory"| node_parsing
node_pipeline -->|"optimizes units"| node_optimization
node_optimization -.->|"may refine"| node_llmopt
node_pipeline -->|"adopts IDs"| node_identity
node_pipeline -->|"plans files"| node_layout
node_pipeline -->|"generates index"| node_indexdoc
node_pipeline -->|"creates embeddings"| node_embed
node_pipeline -->|"syncs vectors"| node_vectorstore
node_cli -->|"searches memories"| node_vectorstore
node_assistant -->|"reads compact index"| node_indexdoc
node_assistant -->|"requests semantic search"| node_cli
node_cli -->|"runs refresh"| node_refresh
node_cli -->|"runs bootstrap"| node_bootstrap
node_cli -->|"restores backups"| node_backup
node_pipeline -->|"backs up changes"| node_backup
node_pipeline -->|"records activity"| node_audit
node_cli -->|"counts tokens"| node_tokens
node_cli -->|"renders results"| node_output
node_cli -->|"serves dashboard"| node_dashboard
node_dashboard -->|"runs workflow"| node_pipeline
node_dashboard -->|"reads search data"| node_vectorstore
node_llmopt -.->|"requests refinement"| node_llmservice

click node_cli "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/cli.py"
click node_config "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/config.py"
click node_discovery "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/discovery.py"
click node_parsing "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/parsing.py"
click node_optimization "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/optimize/deterministic.py"
click node_llmopt "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/optimize/llm.py"
click node_identity "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/identity.py"
click node_layout "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/layout.py"
click node_pipeline "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/pipeline.py"
click node_indexdoc "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/indexdoc.py"
click node_embed "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/embed/local.py"
click node_vectorstore "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/store.py"
click node_refresh "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/refresh.py"
click node_bootstrap "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/bootstrap.py"
click node_backup "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/backup.py"
click node_audit "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/audit.py"
click node_tokens "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/tokens.py"
click node_output "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/output.py"
click node_dashboard "https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/ui/server.py"

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_cli,node_config,node_user toneBlue
class node_discovery,node_parsing,node_optimization,node_llmopt,node_identity,node_layout,node_pipeline toneAmber
class node_indexdoc,node_embed,node_vectorstore toneMint
class node_refresh,node_bootstrap,node_backup,node_audit toneRose
class node_tokens,node_output,node_dashboard,node_assistant,node_llmservice toneIndigo
```

## Components

### User entry points

- [Memdex CLI](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/cli.py): `src/memdex/cli.py`
- [Project configuration](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/config.py): `src/memdex/config.py`

### Memory processing

- [Memory discovery](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/discovery.py): `src/memdex/discovery.py`
- [Markdown parsing](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/parsing.py): `src/memdex/parsing.py`
- [Memory optimization](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/optimize/deterministic.py): `src/memdex/optimize/deterministic.py`
- [Optional LLM refinement](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/optimize/llm.py): `src/memdex/optimize/llm.py`
- [Stable identity](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/identity.py): `src/memdex/identity.py`
- [Memory file layout](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/layout.py): `src/memdex/layout.py`
- [Run orchestration](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/pipeline.py): `src/memdex/pipeline.py`

### Search and persistence

- [Index generation](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/indexdoc.py): `src/memdex/indexdoc.py`
- [Embedding providers](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/embed/local.py): `src/memdex/embed/local.py`
- [Local vector store](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/store.py): `src/memdex/store.py`

### Project operations

- [Memory refresh](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/refresh.py): `src/memdex/refresh.py`
- [Memory bootstrap](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/bootstrap.py): `src/memdex/bootstrap.py`
- [Backup and restore](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/backup.py): `src/memdex/backup.py`
- [Activity audit](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/audit.py): `src/memdex/audit.py`

### Reporting and dashboard

- [Token counting](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/tokens.py): `src/memdex/tokens.py`
- [CLI reporting](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/output.py): `src/memdex/output.py`
- [Local dashboard](https://github.com/shoaibrayeen/memdex/blob/main/src/memdex/ui/server.py): `src/memdex/ui/server.py`

### Other components

- **Project user**
- **AI coding assistant**
- **OpenAI-compatible LLM**

## Connections

- Project user → Memdex CLI: runs commands (evidence: `README.md`)
- Memdex CLI → Run orchestration: runs workflow (evidence: `src/memdex/cli.py`)
- Memdex CLI → Project configuration: loads settings (evidence: `src/memdex/cli.py`)
- Run orchestration → Memory discovery: discovers sources (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Markdown parsing: parses memory (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Memory optimization: optimizes units (evidence: `src/memdex/pipeline.py`)
- Memory optimization → Optional LLM refinement: may refine (evidence: `src/memdex/optimize/base.py`)
- Run orchestration → Stable identity: adopts IDs (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Memory file layout: plans files (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Index generation: generates index (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Embedding providers: creates embeddings (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Local vector store: syncs vectors (evidence: `src/memdex/pipeline.py`)
- Memdex CLI → Local vector store: searches memories (evidence: `src/memdex/cli.py`)
- AI coding assistant → Index generation: reads compact index (evidence: `README.md`)
- AI coding assistant → Memdex CLI: requests semantic search (evidence: `README.md`)
- Memdex CLI → Memory refresh: runs refresh (evidence: `src/memdex/cli.py`)
- Memdex CLI → Memory bootstrap: runs bootstrap (evidence: `src/memdex/cli.py`)
- Memdex CLI → Backup and restore: restores backups (evidence: `src/memdex/cli.py`)
- Run orchestration → Backup and restore: backs up changes (evidence: `src/memdex/pipeline.py`)
- Run orchestration → Activity audit: records activity (evidence: `src/memdex/pipeline.py`)
- Memdex CLI → Token counting: counts tokens (evidence: `src/memdex/cli.py`)
- Memdex CLI → CLI reporting: renders results (evidence: `src/memdex/cli.py`)
- Memdex CLI → Local dashboard: serves dashboard (evidence: `src/memdex/cli.py`)
- Local dashboard → Run orchestration: runs workflow (evidence: `src/memdex/ui/server.py`)
- Local dashboard → Local vector store: reads search data (evidence: `src/memdex/ui/server.py`)
- Optional LLM refinement → OpenAI-compatible LLM: requests refinement
