How gentleman-programming/engram works
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: store.go SQLite store · hub.go Hub state · main.go Engram CLI · mcp.go MCP server
Components 17
Runtime
Single Go binary and user-facing entry points
- Engram CLI · Main command dispatcher for all binary modes
cmd/engram/main.go
Core memory
Shared persistence and domain logic
- SQLite store · Shared SQLite + FTS5 memory backend
internal/store/store.go - Memory graph · Structured memory model and persisted graph schema
internal/obsidian/graph.go - Hub state · Memory organization, state, and graph-oriented coordination
internal/obsidian/hub.go - Export writer · Markdown shaping and export to Obsidian-style artifacts
internal/obsidian/exporter.go - Project ID · Project detection and similarity logic for grouping memories
internal/project/detect.go - Sync pack · Compressed export/import flow for sharing memories
internal/sync/sync.go
Integrations
Agent, API, and local client surfaces
- MCP server · Agent-facing tool server over MCP stdio
internal/mcp/mcp.go - HTTP API · HTTP surface over the same memory backend
internal/server/server.go - TUI dashboard · Local terminal UI for browsing, search, and drill-down
internal/tui/model.go
Distribution
Setup and packaged plugin assets
- Setup tools · Generates agent-specific config and install artifacts
internal/setup/setup.go - Claude plugin · Packaged Claude Code integration, hooks, and MCP wiring
plugin/claude-code/.claude-plugin/plugin.json - OpenCode plugin · Packaged OpenCode integration wrapper for Engram
plugin/opencode/engram.ts - Obsidian plugin · Obsidian client plugin for syncing and local integration
plugin/obsidian/src/main.ts
Governance
Docs, specs, and release tooling
- Version check · Update checking and release awareness
internal/version/check.go - Docs/specs · Architecture docs and OpenSpec change specifications
docs/ARCHITECTURE.md - Release tooling · GoReleaser and CI workflows for packaging and distribution
.goreleaser.yaml
Connections 26
- 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