# gentleman-programming/engram architecture

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

- Interactive diagram: https://gitdiagram.com/gentleman-programming/engram
- Repository: https://github.com/gentleman-programming/engram

## Overview

1. **What the repo is**
   - Engram is a **single Go binary** for persistent AI-agent memory.
   - The architectural center is a **local SQLite database with FTS5**, usually under `~/.engram/engram.db`.
   - Everything else is a surface over that same memory core: CLI, MCP server, HTTP API, and TUI.

2. **Top-level runtime shape**
   - `cmd/engram/main.go` is the entrypoint and command dispatcher.
   - The binary exposes multiple operational modes: `serve`, `mcp`, `tui`, `search`, `save`, `sync`, `setup`, `export/import`, and project utilities.
   - This is not a multi-service system; it is a **single-process, multi-interface tool**.

3. **Core persistence boundary**
   - `internal/store` is the storage boundary around SQLite and the full-text index.
   - This layer is the shared backend for memory creation, retrieval, updates, deletion, stats, and import/export.
   - From an architecture-diagram perspective, this is the main shared datastore that every interface eventually reaches.

4. **Memory domain / note model**
   - `internal/obsidian` contains the domain logic for memory records and graph-like organization: exporting, markdown shaping, slugs, hub/state management, and file watching.
   - The naming reflects the “brain” metaphor and the beta Obsidian export path, but it also appears to host the internal representation used for graph-oriented memory handling.
   - The `graph.json` file suggests a structured, persisted graph/schema definition used by that subsystem.

5. **MCP integration path**
   - `internal/mcp` implements the **MCP server** and the tool surface used by agents.
   - The readme’s 15 tools map here: save/update/delete, search/context/timeline, session lifecycle, stats, passive capture, project merge, etc.
   - Data flow is: **agent → MCP stdio → Engram tool handlers → store/domain logic → SQLite**.

6. **HTTP API boundary**
   - `internal/server` exposes the same memory system over HTTP.
   - It is a separate transport, but not a separate domain: it should be drawn as another ingress into the same service core and store.
   - The repo’s architecture is therefore “multi-transport, single-memory backend.”

7. **Interactive terminal UI**
   - `internal/tui` is the user-facing local dashboard for browsing, searching, drilling into items, and navigating sessions/observations.
   - It is a separate presentation layer with its own model/update/view structure, but it reads from the same memory/store layer.
   - Architecturally, it is best shown as a local client of the core data model rather than as its own subsystem.

8. **Agent setup and plugin distribution**
   - `internal/setup` generates agent-specific config and install artifacts.
   - The `plugin/` tree contains packaged integrations for Claude Code, OpenCode, and related toolchains, including plugin manifests, MCP wiring, hooks, and scripts.
   - These pieces do not store memory themselves; they configure external agents to talk back to Engram.

9. **Project identity and consolidation**
   - `internal/project` handles project detection and similarity logic.
   - This supports grouping memories by repository/project and reducing duplicates or inconsistent project names.
   - In a diagram, this is a support subsystem attached to memory creation/search and project management commands.

10. **Git sync and portable sharing**
    - `internal/sync` provides the export/import flow for sharing memories across machines via compressed chunks.
    - The readme indicates sync artifacts live under `.engram/` and are meant to be committed to git.
    - This is an offline portability layer, distinct from live MCP/HTTP access.

11. **Versioning and release management**
    - `internal/version` checks for new versions, while `.goreleaser.yaml` and GitHub Actions handle packaging and release automation.
    - This is operational infrastructure, not part of the core runtime path, but it matters for how the binary is distributed.

12. **Documentation and specification boundary**
    - `docs/` and `openspec/` describe intended behavior, architecture, and change specs.
    - The `openspec` archive shows the project uses spec-driven changes, especially around Obsidian export and plugin behavior.
    - For architecture diagrams, these are governance/spec artifacts, not runtime components.

13. **External dependencies that matter**
    - The only major runtime dependency that materially shapes the architecture is **SQLite with FTS5**.
    - Agent integrations rely on **MCP**, and some setups use vendor-specific plugin scaffolding, but the product is intentionally agent-agnostic.
    - Release/build tooling includes GoReleaser and GitHub Actions, but those are build-time concerns.

14. **Recommended diagram framing**
    - Draw a central **Engram core** containing storage, memory domain logic, project logic, sync, and export/import.
    - Surround it with four ingress layers: **CLI**, **MCP**, **HTTP API**, and **TUI**.
    - Show a separate **setup/plugin distribution** lane that configures external agents to reach the MCP interface.
    - Add an optional **Obsidian export / graph** lane and a **git sync** lane as secondary data-sharing paths.

Main entry points: [`internal/store/store.go`](https://github.com/gentleman-programming/engram/blob/main/internal/store/store.go) (SQLite store), [`internal/obsidian/hub.go`](https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/hub.go) (Hub state), [`cmd/engram/main.go`](https://github.com/gentleman-programming/engram/blob/main/cmd/engram/main.go) (Engram CLI), [`internal/mcp/mcp.go`](https://github.com/gentleman-programming/engram/blob/main/internal/mcp/mcp.go) (MCP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Runtime"]
  node_cmd_engram["Engram CLI<br/>entrypoint/dispatcher<br/>[main.go]"]
end

subgraph group_grp_core["Core memory"]
  node_store[("SQLite store<br/>persistence/fts5<br/>[store.go]")]
  node_obsidian_graph["Memory graph<br/>domain/schema<br/>[graph.go]"]
  node_obsidian_hub(("Hub state<br/>domain/state<br/>[hub.go]"))
  node_obsidian_exporter["Export writer<br/>domain/export<br/>[exporter.go]"]
  node_project{{"Project ID<br/>support/detection<br/>[detect.go]"}}
  node_sync["Sync pack<br/>portability/import-export<br/>[sync.go]"]
end

subgraph group_grp_integrations["Integrations"]
  node_mcp["MCP server<br/>transport/mcp<br/>[mcp.go]"]
  node_server["HTTP API<br/>transport/http<br/>[server.go]"]
  node_tui["TUI dashboard<br/>presentation/terminal<br/>[model.go]"]
end

subgraph group_grp_distribution["Distribution"]
  node_setup["Setup tools<br/>bootstrap/install<br/>[setup.go]"]
  node_claude_plugin["Claude plugin<br/>package/integration<br/>[plugin.json]"]
  node_opencode_plugin["OpenCode plugin<br/>package/integration<br/>[engram.ts]"]
  node_obsidian_plugin["Obsidian plugin<br/>package/integration<br/>[main.ts]"]
end

subgraph group_grp_governance["Governance"]
  node_version{{"Version check<br/>ops/release<br/>[check.go]"}}
  node_docs["Docs/specs<br/>governance/spec<br/>[ARCHITECTURE.md]"]
  node_release["Release tooling<br/>build/release<br/>[.goreleaser.yaml]"]
end

node_cmd_engram -->|"mcp mode"| node_mcp
node_cmd_engram -->|"serve mode"| node_server
node_cmd_engram -->|"tui mode"| node_tui
node_cmd_engram -->|"memory ops"| node_store
node_cmd_engram -->|"domain ops"| node_obsidian_hub
node_mcp -->|"tools"| node_store
node_mcp -->|"records"| node_obsidian_hub
node_server -->|"api"| node_store
node_server -->|"memory model"| node_obsidian_hub
node_tui -->|"browse/search"| node_store
node_tui -->|"grouping"| node_project
node_obsidian_hub -->|"schema"| node_obsidian_graph
node_obsidian_hub -->|"export"| node_obsidian_exporter
node_obsidian_hub -->|"persist"| node_store
node_project -.->|"search context"| node_store
node_sync -->|"pack/unpack"| node_store
node_sync -.->|"shared export"| node_obsidian_exporter
node_setup -->|"generate"| node_claude_plugin
node_setup -->|"generate"| node_opencode_plugin
node_setup -->|"generate"| node_obsidian_plugin
node_claude_plugin -->|"agent bridge"| node_mcp
node_opencode_plugin -->|"agent bridge"| node_mcp
node_obsidian_plugin -->|"local sync"| node_sync
node_version -.->|"updates"| node_release
node_docs -.->|"specifies"| node_obsidian_exporter
node_docs -.->|"guides"| node_setup

click node_cmd_engram "https://github.com/gentleman-programming/engram/blob/main/cmd/engram/main.go"
click node_store "https://github.com/gentleman-programming/engram/blob/main/internal/store/store.go"
click node_obsidian_graph "https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/graph.go"
click node_obsidian_hub "https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/hub.go"
click node_obsidian_exporter "https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/exporter.go"
click node_project "https://github.com/gentleman-programming/engram/blob/main/internal/project/detect.go"
click node_sync "https://github.com/gentleman-programming/engram/blob/main/internal/sync/sync.go"
click node_mcp "https://github.com/gentleman-programming/engram/blob/main/internal/mcp/mcp.go"
click node_server "https://github.com/gentleman-programming/engram/blob/main/internal/server/server.go"
click node_tui "https://github.com/gentleman-programming/engram/blob/main/internal/tui/model.go"
click node_setup "https://github.com/gentleman-programming/engram/blob/main/internal/setup/setup.go"
click node_claude_plugin "https://github.com/gentleman-programming/engram/blob/main/plugin/claude-code/.claude-plugin/plugin.json"
click node_opencode_plugin "https://github.com/gentleman-programming/engram/blob/main/plugin/opencode/engram.ts"
click node_obsidian_plugin "https://github.com/gentleman-programming/engram/blob/main/plugin/obsidian/src/main.ts"
click node_version "https://github.com/gentleman-programming/engram/blob/main/internal/version/check.go"
click node_docs "https://github.com/gentleman-programming/engram/blob/main/docs/ARCHITECTURE.md"
click node_release "https://github.com/gentleman-programming/engram/blob/main/.goreleaser.yaml"

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_cmd_engram toneBlue
class node_store,node_obsidian_graph,node_obsidian_hub,node_obsidian_exporter,node_project,node_sync toneAmber
class node_mcp,node_server,node_tui toneMint
class node_setup,node_claude_plugin,node_opencode_plugin,node_obsidian_plugin toneRose
class node_version,node_docs,node_release toneIndigo
```

## Components

### Runtime

Single Go binary and user-facing entry points

- [Engram CLI](https://github.com/gentleman-programming/engram/blob/main/cmd/engram/main.go): entrypoint/dispatcher · Main command dispatcher for all binary modes · `cmd/engram/main.go`

### Core memory

Shared persistence and domain logic

- [SQLite store](https://github.com/gentleman-programming/engram/blob/main/internal/store/store.go): persistence/fts5 · Shared SQLite + FTS5 memory backend · `internal/store/store.go`
- [Memory graph](https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/graph.go): domain/schema · Structured memory model and persisted graph schema · `internal/obsidian/graph.go`
- [Hub state](https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/hub.go): domain/state · Memory organization, state, and graph-oriented coordination · `internal/obsidian/hub.go`
- [Export writer](https://github.com/gentleman-programming/engram/blob/main/internal/obsidian/exporter.go): domain/export · Markdown shaping and export to Obsidian-style artifacts · `internal/obsidian/exporter.go`
- [Project ID](https://github.com/gentleman-programming/engram/blob/main/internal/project/detect.go): support/detection · Project detection and similarity logic for grouping memories · `internal/project/detect.go`
- [Sync pack](https://github.com/gentleman-programming/engram/blob/main/internal/sync/sync.go): portability/import-export · Compressed export/import flow for sharing memories · `internal/sync/sync.go`

### Integrations

Agent, API, and local client surfaces

- [MCP server](https://github.com/gentleman-programming/engram/blob/main/internal/mcp/mcp.go): transport/mcp · Agent-facing tool server over MCP stdio · `internal/mcp/mcp.go`
- [HTTP API](https://github.com/gentleman-programming/engram/blob/main/internal/server/server.go): transport/http · HTTP surface over the same memory backend · `internal/server/server.go`
- [TUI dashboard](https://github.com/gentleman-programming/engram/blob/main/internal/tui/model.go): presentation/terminal · Local terminal UI for browsing, search, and drill-down · `internal/tui/model.go`

### Distribution

Setup and packaged plugin assets

- [Setup tools](https://github.com/gentleman-programming/engram/blob/main/internal/setup/setup.go): bootstrap/install · Generates agent-specific config and install artifacts · `internal/setup/setup.go`
- [Claude plugin](https://github.com/gentleman-programming/engram/blob/main/plugin/claude-code/.claude-plugin/plugin.json): package/integration · Packaged Claude Code integration, hooks, and MCP wiring · `plugin/claude-code/.claude-plugin/plugin.json`
- [OpenCode plugin](https://github.com/gentleman-programming/engram/blob/main/plugin/opencode/engram.ts): package/integration · Packaged OpenCode integration wrapper for Engram · `plugin/opencode/engram.ts`
- [Obsidian plugin](https://github.com/gentleman-programming/engram/blob/main/plugin/obsidian/src/main.ts): package/integration · Obsidian client plugin for syncing and local integration · `plugin/obsidian/src/main.ts`

### Governance

Docs, specs, and release tooling

- [Version check](https://github.com/gentleman-programming/engram/blob/main/internal/version/check.go): ops/release · Update checking and release awareness · `internal/version/check.go`
- [Docs/specs](https://github.com/gentleman-programming/engram/blob/main/docs/ARCHITECTURE.md): governance/spec · Architecture docs and OpenSpec change specifications · `docs/ARCHITECTURE.md`
- [Release tooling](https://github.com/gentleman-programming/engram/blob/main/.goreleaser.yaml): build/release · GoReleaser and CI workflows for packaging and distribution · `.goreleaser.yaml`

## Connections

- Engram CLI → MCP server: mcp mode · Dispatches the MCP runtime
- Engram CLI → HTTP API: serve mode · Starts the HTTP API
- Engram CLI → TUI dashboard: tui mode · Launches the terminal UI
- Engram CLI → SQLite store: memory ops · Routes CLI commands to shared storage
- Engram CLI → Hub state: domain ops · Uses memory domain logic for save, search, export, and project flows
- MCP server → SQLite store: tools · MCP handlers persist and query memory
- MCP server → Hub state: records · Tool handlers use the shared memory model
- HTTP API → SQLite store: api · HTTP endpoints read and write the same store
- HTTP API → Hub state: memory model · HTTP routes share domain logic with other interfaces
- TUI dashboard → SQLite store: browse/search · TUI reads from the shared backend
- TUI dashboard → Project ID: grouping · Uses project identity to organize views
- Hub state → Memory graph: schema · Coordinates structured memory graph state
- Hub state → Export writer: export · Produces markdown and Obsidian exports
- Hub state → SQLite store: persist · Writes and reads memory records through the store
- Project ID → SQLite store: search context · Project identity informs memory operations
- Sync pack → SQLite store: pack/unpack · Serializes and restores portable memory bundles
- Sync pack → Export writer: shared export · Reuses export-shaped output for portable sharing
- Setup tools → Claude plugin: generate · Builds Claude Code integration artifacts
- Setup tools → OpenCode plugin: generate · Builds OpenCode integration artifacts
- Setup tools → Obsidian plugin: generate · Builds Obsidian integration artifacts
- Claude plugin → MCP server: agent bridge · Configures external agents to reach MCP
- OpenCode plugin → MCP server: agent bridge · Configures external agents to reach MCP
- Obsidian plugin → Sync pack: local sync · Uses portable sync flows for Obsidian integration
- Version check → Release tooling: updates · Supports release and update management
- Docs/specs → Export writer: specifies · Documents export and plugin behavior
- Docs/specs → Setup tools: guides · Documents installation and agent setup
