# pyranthus-hq/mora architecture

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

- Interactive diagram: https://gitdiagram.com/pyranthus-hq/mora
- Repository: https://github.com/pyranthus-hq/mora

## Overview

1. **Top-level shape**
   Mora is a **local-first personal memory system** implemented in Go. The repo is centered around one executable (`cmd/mora`) and a large `internal/mora` orchestration layer that ties together connectors, indexing, retrieval, synthesis, MCP serving, sharing, and background sync.

2. **Primary data boundary: the vault**
   The core architectural boundary is the **vault**, a folder of Markdown files on disk, backed by a **SQLite index** in a separate local data directory. The vault is the durable source of truth; the index is disposable and rebuildable. Configuration, OAuth tokens, and sync watermarks live in separate per-user config/state directories.

3. **Source connectors**
   Ingestion starts from source-specific adapters under `internal/google`, `internal/imessage`, `internal/applecal`, and the local-file/memory path in `internal/memory`. These connectors read from external systems such as Gmail, Google Calendar, iMessage chat databases, Apple Calendar, and filesystem documents, then normalize source records into Mora’s internal model.

4. **Normalization and mapping**
   Each connector has its own mapping layer that converts source-native IDs, timestamps, identities, and thread/event structures into Mora’s canonical objects. This is where cross-source consistency is established: the same person, thread, or event can be linked across mail, messages, and calendar items before anything is written to the vault.

5. **Ingest pipeline**
   The ingest path turns connector output into Markdown artifacts and updates the SQLite index. This is an important write boundary: the system fetches read-only from external sources, but all durable memory creation happens locally in the vault/index pair. The ingest code also handles incremental sync via per-source watermarks so only new or changed items are reprocessed.

6. **Search and retrieval**
   Retrieval is hybrid. The index supports **keyword search (BM25)**, and optional local semantic search can be enabled through an Ollama embedder. Query handling combines lexical search, embeddings, and graph expansion, then re-ranks results for recall and citation quality. This is the main read path used by the CLI and MCP tools.

7. **Entity graph**
   Mora builds a deterministic **entity graph** over people, addresses, threads, chats, meetings, and tasks. The graph layer is used to unify identity across sources and to answer questions like “what do we know about this person?” The graph is not a separate database; it is derived from indexed vault content and metadata.

8. **Synthesis features**
   Higher-level outputs such as `think`, `brief`, `digest`, `meeting prep`, and salience ranking are built on top of retrieval and the entity graph. These features do not replace search; they package retrieved evidence into task-oriented views with explicit citations and “gap” detection, so the agent can reason from source-backed memory rather than free-form generation.

9. **Interface surfaces: CLI and MCP**
   The repository exposes the same capabilities through two entry points:
   - a **CLI** for direct shell use
   - an **MCP server** (`mora mcp serve`) for Claude Code, Codex, Gemini CLI, Cursor, and other clients  
   The MCP layer is just a local stdio service; it does not proxy to a remote backend. This keeps the agent integration boundary entirely on-device.

10. **Background operation and freshness**
   Mora includes scheduling and loop/hook machinery for recurring sync and freshness maintenance. The architecture treats freshness as a first-class concern: search results and synthesis output can report how current each source is, and scheduled jobs keep the vault updated without requiring a resident server.

11. **Sharing and export paths**
   There are two explicit egress mechanisms:
   - **git sync** for backing up the vault to a private repository
   - **encrypted sharing** for publishing selected authored memories to a separate remote, with per-recipient encryption and a required preview of what leaves  
   These flows are intentionally separate from normal retrieval and ingest so the default operating mode remains zero-egress.

12. **Platform boundaries**
   The repo is mostly cross-platform Go, but some connectors and integrations are platform-specific: iMessage, Apple Calendar, and Address Book depend on macOS; Windows has its own install/uninstall and Task Scheduler support; Linux/macOS/Windows all support the Google and filesystem-based paths. The codebase includes OS-specific files to keep these boundaries clean.

13. **Operational and distribution layer**
   Packaging is handled by release tooling (`goreleaser`, GitHub Actions, install scripts). These are not runtime dependencies, but they shape how the binary is distributed and self-updated. The project is intentionally “pure Go, no CGO,” which simplifies cross-platform deployment and local-only operation.

14. **Testing and evaluation as architecture support**
   The large test surface is part of the design: there are connector tests, retrieval tests, graph tests, MCP tests, and evaluation/sweep artifacts. This indicates the architecture is optimized around correctness of ingestion, ranking, freshness, and citation quality rather than around a single monolithic app flow.

Main entry points: [`internal/mora/ingest.go`](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/ingest.go) (Ingest), [`internal/mora/search.go`](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/search.go) (Search), [`internal/mora/usage.go`](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/usage.go) (CLI commands), [`internal/mora/mcp.go`](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/mcp.go) (MCP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_entry["Entry points"]
  node_n_cmd["mora CLI<br/>Go command<br/>[main.go]"]
  node_n_mcp["MCP server<br/>stdio tools<br/>[mcp.go]"]
  node_n_cli["CLI commands<br/>command layer<br/>[usage.go]"]
end

subgraph group_grp_core["Core memory"]
  node_n_setup["Setup<br/>config/bootstrap<br/>[setup.go]"]
  node_n_vault[("Vault ops<br/>storage boundary<br/>[vaultops.go]")]
  node_n_index[("SQLite index<br/>search index<br/>[index.go]")]
  node_n_ingest["Ingest<br/>pipeline<br/>[ingest.go]"]
  node_n_search["Search<br/>query router<br/>[search.go]"]
  node_n_hybrid["Hybrid rank<br/>retrieval fusion<br/>[hybrid.go]"]
  node_n_graph{{"Entity graph<br/>derived graph<br/>[graph.go]"}}
  node_n_entities["Entities<br/>identity model<br/>[entities.go]"]
  node_n_think["Think<br/>synthesis<br/>[think.go]"]
  node_n_digest["Digest<br/>synthesis<br/>[digest.go]"]
end

subgraph group_grp_sources["Connectors"]
  node_n_google["Google<br/>connector<br/>[gmail.go]"]
  node_n_imessage["iMessage<br/>connector<br/>[chatdb.go]"]
  node_n_applecal["Apple Cal<br/>connector<br/>[applecal.go]"]
  node_n_memory["Memory files<br/>connector<br/>[ingest.go]"]
end

subgraph group_grp_ops["Operations"]
  node_n_schedule["Scheduler<br/>freshness loop<br/>[schedule.go]"]
  node_n_share["Sharing<br/>egress<br/>[share.go]"]
  node_n_gitsync["Git sync<br/>backup<br/>[gitsync.go]"]
  node_n_release["Release ops<br/>distribution<br/>[build-release.sh]"]
end

node_n_cmd -->|"bootstraps"| node_n_setup
node_n_cmd -->|"exposes"| node_n_cli
node_n_cmd -->|"serves"| node_n_mcp
node_n_setup -->|"opens"| node_n_vault
node_n_setup -->|"opens"| node_n_index
node_n_cli -->|"invokes"| node_n_ingest
node_n_cli -->|"queries"| node_n_search
node_n_cli -->|"runs"| node_n_think
node_n_cli -->|"runs"| node_n_digest
node_n_mcp -->|"tools"| node_n_search
node_n_mcp -->|"tools"| node_n_think
node_n_mcp -->|"tools"| node_n_digest
node_n_google -->|"feeds"| node_n_ingest
node_n_imessage -->|"feeds"| node_n_ingest
node_n_applecal -->|"feeds"| node_n_ingest
node_n_memory -->|"feeds"| node_n_ingest
node_n_ingest -->|"writes"| node_n_vault
node_n_ingest -->|"updates"| node_n_index
node_n_search -->|"reads"| node_n_index
node_n_search -->|"routes"| node_n_hybrid
node_n_hybrid -->|"expands"| node_n_graph
node_n_graph -->|"derives from"| node_n_entities
node_n_think -->|"depends on"| node_n_search
node_n_digest -->|"depends on"| node_n_search
node_n_digest -->|"uses"| node_n_graph
node_n_schedule -->|"triggers"| node_n_ingest
node_n_schedule -->|"annotates"| node_n_search
node_n_share -->|"exports"| node_n_vault
node_n_gitsync -->|"backs up"| node_n_vault
node_n_release -.->|"packages"| node_n_cmd

click node_n_cmd "https://github.com/pyranthus-hq/mora/blob/main/cmd/mora/main.go"
click node_n_mcp "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/mcp.go"
click node_n_cli "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/usage.go"
click node_n_setup "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/setup.go"
click node_n_vault "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/vaultops.go"
click node_n_index "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/index.go"
click node_n_ingest "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/ingest.go"
click node_n_search "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/search.go"
click node_n_hybrid "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/hybrid.go"
click node_n_graph "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/graph.go"
click node_n_entities "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/entities.go"
click node_n_think "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/think.go"
click node_n_digest "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/digest.go"
click node_n_google "https://github.com/pyranthus-hq/mora/blob/main/internal/google/gmail.go"
click node_n_imessage "https://github.com/pyranthus-hq/mora/blob/main/internal/imessage/chatdb.go"
click node_n_applecal "https://github.com/pyranthus-hq/mora/blob/main/internal/applecal/applecal.go"
click node_n_memory "https://github.com/pyranthus-hq/mora/blob/main/internal/memory/ingest.go"
click node_n_schedule "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/schedule.go"
click node_n_share "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/share.go"
click node_n_gitsync "https://github.com/pyranthus-hq/mora/blob/main/internal/mora/gitsync.go"
click node_n_release "https://github.com/pyranthus-hq/mora/blob/main/scripts/build-release.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_n_cmd,node_n_mcp,node_n_cli toneBlue
class node_n_setup,node_n_vault,node_n_index,node_n_ingest,node_n_search,node_n_hybrid,node_n_graph,node_n_entities,node_n_think,node_n_digest toneAmber
class node_n_google,node_n_imessage,node_n_applecal,node_n_memory toneMint
class node_n_schedule,node_n_share,node_n_gitsync,node_n_release toneRose
```

## Components

### Entry points

Executable and external interfaces

- [mora CLI](https://github.com/pyranthus-hq/mora/blob/main/cmd/mora/main.go): Go command · Primary executable entrypoint. · `cmd/mora/main.go`
- [MCP server](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/mcp.go): stdio tools · Local agent-facing tool server. · `internal/mora/mcp.go`
- [CLI commands](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/usage.go): command layer · Shell-facing subcommands and UX routing. · `internal/mora/usage.go`

### Core memory

Orchestration, storage, retrieval, and synthesis

- [Setup](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/setup.go): config/bootstrap · Config, vault, and runtime initialization. · `internal/mora/setup.go`
- [Vault ops](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/vaultops.go): storage boundary · Local Markdown vault and filesystem writes. · `internal/mora/vaultops.go`
- [SQLite index](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/index.go): search index · Persistent local index for lookup and rebuilds. · `internal/mora/index.go`
- [Ingest](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/ingest.go): pipeline · Turns source records into vault artifacts and index updates. · `internal/mora/ingest.go`
- [Search](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/search.go): query router · Hybrid retrieval orchestration across lexical, semantic, and graph signals. · `internal/mora/search.go`
- [Hybrid rank](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/hybrid.go): retrieval fusion · Combines BM25, embeddings, and reranking. · `internal/mora/hybrid.go`
- [Entity graph](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/graph.go): derived graph · Deterministic identity and relationship graph from indexed content. · `internal/mora/graph.go`
- [Entities](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/entities.go): identity model · People, threads, chats, meetings, tasks, and related links. · `internal/mora/entities.go`
- [Think](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/think.go): synthesis · Evidence-backed reasoning and gap-aware answers. · `internal/mora/think.go`
- [Digest](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/digest.go): synthesis · Task-oriented summaries and salience views. · `internal/mora/digest.go`

### Connectors

Source-specific ingestion adapters

- [Google](https://github.com/pyranthus-hq/mora/blob/main/internal/google/gmail.go): connector · Gmail and Calendar ingestion. · `internal/google/gmail.go`
- [iMessage](https://github.com/pyranthus-hq/mora/blob/main/internal/imessage/chatdb.go): connector · macOS Messages and address book ingestion. · `internal/imessage/chatdb.go`
- [Apple Cal](https://github.com/pyranthus-hq/mora/blob/main/internal/applecal/applecal.go): connector · Apple Calendar ingestion. · `internal/applecal/applecal.go`
- [Memory files](https://github.com/pyranthus-hq/mora/blob/main/internal/memory/ingest.go): connector · Filesystem and local memory ingestion path. · `internal/memory/ingest.go`

### Operations

Sync, sharing, distribution, and maintenance

- [Scheduler](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/schedule.go): freshness loop · Recurring sync, hooks, and freshness maintenance. · `internal/mora/schedule.go`
- [Sharing](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/share.go): egress · Vault export, manifests, and encrypted publishing. · `internal/mora/share.go`
- [Git sync](https://github.com/pyranthus-hq/mora/blob/main/internal/mora/gitsync.go): backup · Backs up the vault to a git repository. · `internal/mora/gitsync.go`
- [Release ops](https://github.com/pyranthus-hq/mora/blob/main/scripts/build-release.sh): distribution · Packaging and install/uninstall tooling for distribution. · `scripts/build-release.sh`

## Connections

- mora CLI → Setup: bootstraps · Initializes config, vault, and runtime state.
- mora CLI → CLI commands: exposes · Routes shell commands through the CLI layer.
- mora CLI → MCP server: serves · Starts the local MCP stdio service.
- Setup → Vault ops: opens · Locates and prepares the local vault boundary.
- Setup → SQLite index: opens · Initializes or validates the SQLite index.
- CLI commands → Ingest: invokes · Triggers ingestion and reingest flows.
- CLI commands → Search: queries · Uses the retrieval path for user search.
- CLI commands → Think: runs · Exposes synthesis-oriented commands.
- CLI commands → Digest: runs · Exposes summary and digest commands.
- MCP server → Search: tools · Agent tools are backed by the search pipeline.
- MCP server → Think: tools · Agent-facing reasoning tools use synthesis.
- MCP server → Digest: tools · Digest and briefing tools are served over MCP.
- Google → Ingest: feeds · Normalized records enter the ingest pipeline.
- iMessage → Ingest: feeds · Messages and address book data are normalized for ingest.
- Apple Cal → Ingest: feeds · Calendar events are normalized for ingest.
- Memory files → Ingest: feeds · Local files and memory content are ingested.
- Ingest → Vault ops: writes · Materializes Markdown artifacts in the vault.
- Ingest → SQLite index: updates · Upserts local index entries after ingest.
- Search → SQLite index: reads · Primary lexical and metadata lookup source.
- Search → Hybrid rank: routes · Delegates ranking and fusion to hybrid retrieval.
- Hybrid rank → Entity graph: expands · Uses graph traversal and related entities to broaden recall.
- Entity graph → Entities: derives from · Graph structure is built from entity and relation metadata.
- Think → Search: depends on · Reasoning packages retrieved evidence.
- Digest → Search: depends on · Digest generation starts from retrieval.
- Digest → Entity graph: uses · Salience and entity context inform digests.
- Scheduler → Ingest: triggers · Recurring freshness jobs drive sync and ingest.
- Scheduler → Search: annotates · Freshness metadata influences read results.
- Sharing → Vault ops: exports · Selects authored memories from the local vault.
- Git sync → Vault ops: backs up · Pushes the vault to git for backup and sync.
- Release ops → mora CLI: packages · Distribution tooling builds and installs the binary.
