# mem0ai/mem0 architecture

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

- Interactive diagram: https://gitdiagram.com/mem0ai/mem0
- Repository: https://github.com/mem0ai/mem0

## Overview

Mem0 is a memory layer for AI applications, delivered as Python/TypeScript SDKs, a self-hosted API and dashboard, command-line tools, and agent-framework integrations. The central workflow is to submit conversational content, extract and embed memories, store them, then retrieve relevant context for an agent. The graph preserves documented product branches and sampled internal layers; some subsystem wiring is based on README claims because their implementation was not sampled.

Main entry points: [`server/main.py`](https://github.com/mem0ai/mem0/blob/main/server/main.py) (API application), [`mem0/memory/main.py`](https://github.com/mem0ai/mem0/blob/main/mem0/memory/main.py) (Memory engine), [`mem0/client/main.py`](https://github.com/mem0ai/mem0/blob/main/mem0/client/main.py) (SDK clients), [`mem0/utils/factory.py`](https://github.com/mem0ai/mem0/blob/main/mem0/utils/factory.py) (Provider factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_memory["Memory SDK"]
  node_sdk["SDK clients<br/>[main.py]"]
  node_engine["Memory engine<br/>[main.py]"]
  node_setup["Provider setup<br/>[setup.py]"]
  node_factory["Provider factory<br/>[factory.py]"]
  node_llmconfig["LLM configuration<br/>[base.py]"]
  node_prompts["Memory prompts<br/>[prompts.py]"]
  node_reranking["Result reranking<br/>[base.py]"]
  node_memorydata[("Memory storage<br/>[storage.py]")]
  node_llmprovider["LLM providers<br/>[openai.py]"]
  node_embedding["Embedding providers"]
  node_vector[("Vector stores")]
end

subgraph group_service["Self-hosted Service"]
  node_server["API application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_routes["API routes"]
  node_db[("Service database<br/>[db.py]")]
  node_models["Service models<br/>[models.py]"]
  node_dashboard["Management dashboard"]
  node_servertelemetry["Server telemetry<br/>[telemetry.py]"]
end

subgraph group_cli["Command-line Tools"]
  node_cli["CLI commands<br/>[app.py]"]
  node_clibackend["Platform backend<br/>[platform.py]"]
end

subgraph group_integrations["Agent Integrations"]
  node_plugin["Agent plugins<br/>[memory_core.py]"]
  node_openclaw["OpenClaw integration<br/>[index.ts]"]
  node_integrations["SDK integrations"]
end

node_developer(("Developer or agent"))

node_developer -->|"submits content"| node_sdk
node_sdk -->|"uses local memory"| node_engine
node_sdk -.->|"calls API"| node_server
node_engine -->|"initializes"| node_setup
node_engine -->|"selects providers"| node_factory
node_factory -->|"builds providers"| node_llmconfig
node_engine -->|"uses prompts"| node_prompts
node_engine -->|"stores history"| node_memorydata
node_engine -->|"uses vector store"| node_vector
node_engine -.->|"supports reranking"| node_reranking
node_factory -->|"constructs LLM"| node_llmprovider
node_setup -.->|"configures embedder"| node_embedding
node_server -->|"uses auth"| node_auth
node_server -->|"registers routes"| node_routes
node_routes -->|"uses database"| node_db
node_routes -->|"uses models"| node_models
node_dashboard -.->|"manages service"| node_server
node_server -->|"reports events"| node_servertelemetry
node_developer -->|"runs commands"| node_cli
node_cli -->|"uses platform backend"| node_clibackend
node_clibackend -.->|"calls API"| node_server
node_developer -->|"uses agent plugin"| node_plugin
node_plugin -.->|"sends and searches memories"| node_server
node_developer -->|"uses agent integration"| node_openclaw
node_openclaw -.->|"recalls memories"| node_server
node_developer -->|"uses SDK integrations"| node_integrations
node_integrations -.->|"connects SDKs"| node_sdk

click node_sdk "https://github.com/mem0ai/mem0/blob/main/mem0/client/main.py"
click node_engine "https://github.com/mem0ai/mem0/blob/main/mem0/memory/main.py"
click node_setup "https://github.com/mem0ai/mem0/blob/main/mem0/memory/setup.py"
click node_factory "https://github.com/mem0ai/mem0/blob/main/mem0/utils/factory.py"
click node_llmconfig "https://github.com/mem0ai/mem0/blob/main/mem0/configs/llms/base.py"
click node_prompts "https://github.com/mem0ai/mem0/blob/main/mem0/configs/prompts.py"
click node_reranking "https://github.com/mem0ai/mem0/blob/main/mem0/configs/rerankers/base.py"
click node_memorydata "https://github.com/mem0ai/mem0/blob/main/mem0/memory/storage.py"
click node_llmprovider "https://github.com/mem0ai/mem0/blob/main/mem0/llms/openai.py"
click node_embedding "https://github.com/mem0ai/mem0/tree/main/mem0/embeddings"
click node_vector "https://github.com/mem0ai/mem0/tree/main/mem0/vector_stores"
click node_server "https://github.com/mem0ai/mem0/blob/main/server/main.py"
click node_auth "https://github.com/mem0ai/mem0/blob/main/server/auth.py"
click node_routes "https://github.com/mem0ai/mem0/tree/main/server/routers"
click node_db "https://github.com/mem0ai/mem0/blob/main/server/db.py"
click node_models "https://github.com/mem0ai/mem0/blob/main/server/models.py"
click node_dashboard "https://github.com/mem0ai/mem0/tree/main/server/dashboard/src/app/(root)/dashboard"
click node_servertelemetry "https://github.com/mem0ai/mem0/blob/main/server/telemetry.py"
click node_cli "https://github.com/mem0ai/mem0/blob/main/cli/python/src/mem0_cli/app.py"
click node_clibackend "https://github.com/mem0ai/mem0/blob/main/cli/python/src/mem0_cli/backend/platform.py"
click node_plugin "https://github.com/mem0ai/mem0/blob/main/integrations/kimi-plugin/core/memory_core.py"
click node_openclaw "https://github.com/mem0ai/mem0/blob/main/integrations/openclaw/index.ts"
click node_integrations "https://github.com/mem0ai/mem0/tree/main/integrations"

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_sdk,node_engine,node_setup,node_factory,node_llmconfig,node_prompts,node_reranking,node_memorydata,node_llmprovider,node_embedding,node_vector toneBlue
class node_server,node_auth,node_routes,node_db,node_models,node_dashboard,node_servertelemetry toneAmber
class node_cli,node_clibackend toneMint
class node_plugin,node_openclaw,node_integrations toneRose
class node_developer toneIndigo
```

## Components

### Memory SDK

- [SDK clients](https://github.com/mem0ai/mem0/blob/main/mem0/client/main.py): `mem0/client/main.py`
- [Memory engine](https://github.com/mem0ai/mem0/blob/main/mem0/memory/main.py): `mem0/memory/main.py`
- [Provider setup](https://github.com/mem0ai/mem0/blob/main/mem0/memory/setup.py): `mem0/memory/setup.py`
- [Provider factory](https://github.com/mem0ai/mem0/blob/main/mem0/utils/factory.py): `mem0/utils/factory.py`
- [LLM configuration](https://github.com/mem0ai/mem0/blob/main/mem0/configs/llms/base.py): `mem0/configs/llms/base.py`
- [Memory prompts](https://github.com/mem0ai/mem0/blob/main/mem0/configs/prompts.py): `mem0/configs/prompts.py`
- [Result reranking](https://github.com/mem0ai/mem0/blob/main/mem0/configs/rerankers/base.py): `mem0/configs/rerankers/base.py`
- [Memory storage](https://github.com/mem0ai/mem0/blob/main/mem0/memory/storage.py): `mem0/memory/storage.py`
- [LLM providers](https://github.com/mem0ai/mem0/blob/main/mem0/llms/openai.py): `mem0/llms/openai.py`
- [Embedding providers](https://github.com/mem0ai/mem0/tree/main/mem0/embeddings): `mem0/embeddings`
- [Vector stores](https://github.com/mem0ai/mem0/tree/main/mem0/vector_stores): `mem0/vector_stores`

### Self-hosted Service

- [API application](https://github.com/mem0ai/mem0/blob/main/server/main.py): `server/main.py`
- [Authentication](https://github.com/mem0ai/mem0/blob/main/server/auth.py): `server/auth.py`
- [API routes](https://github.com/mem0ai/mem0/tree/main/server/routers): `server/routers`
- [Service database](https://github.com/mem0ai/mem0/blob/main/server/db.py): `server/db.py`
- [Service models](https://github.com/mem0ai/mem0/blob/main/server/models.py): `server/models.py`
- [Management dashboard](https://github.com/mem0ai/mem0/tree/main/server/dashboard/src/app/(root)/dashboard): `server/dashboard/src/app/(root)/dashboard`
- [Server telemetry](https://github.com/mem0ai/mem0/blob/main/server/telemetry.py): `server/telemetry.py`

### Command-line Tools

- [CLI commands](https://github.com/mem0ai/mem0/blob/main/cli/python/src/mem0_cli/app.py): `cli/python/src/mem0_cli/app.py`
- [Platform backend](https://github.com/mem0ai/mem0/blob/main/cli/python/src/mem0_cli/backend/platform.py): `cli/python/src/mem0_cli/backend/platform.py`

### Agent Integrations

- [Agent plugins](https://github.com/mem0ai/mem0/blob/main/integrations/kimi-plugin/core/memory_core.py): `integrations/kimi-plugin/core/memory_core.py`
- [OpenClaw integration](https://github.com/mem0ai/mem0/blob/main/integrations/openclaw/index.ts): `integrations/openclaw/index.ts`
- [SDK integrations](https://github.com/mem0ai/mem0/tree/main/integrations): `integrations`

### Other components

- **Developer or agent**

## Connections

- Developer or agent → SDK clients: submits content (evidence: `README.md`)
- SDK clients → Memory engine: uses local memory (evidence: `mem0/__init__.py`)
- SDK clients → API application: calls API
- Memory engine → Provider setup: initializes (evidence: `mem0/memory/main.py`)
- Memory engine → Provider factory: selects providers (evidence: `mem0/memory/main.py`)
- Provider factory → LLM configuration: builds providers (evidence: `mem0/utils/factory.py`)
- Memory engine → Memory prompts: uses prompts (evidence: `mem0/memory/main.py`)
- Memory engine → Memory storage: stores history (evidence: `mem0/memory/main.py`)
- Memory engine → Vector stores: uses vector store (evidence: `mem0/memory/main.py`)
- Memory engine → Result reranking: supports reranking
- Provider factory → LLM providers: constructs LLM (evidence: `mem0/utils/factory.py`)
- Provider setup → Embedding providers: configures embedder
- API application → Authentication: uses auth (evidence: `server/main.py`)
- API application → API routes: registers routes (evidence: `server/main.py`)
- API routes → Service database: uses database (evidence: `server/routers/auth.py`)
- API routes → Service models: uses models (evidence: `server/routers/auth.py`)
- Management dashboard → API application: manages service
- API application → Server telemetry: reports events (evidence: `server/main.py`)
- Developer or agent → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Platform backend: uses platform backend (evidence: `cli/python/src/mem0_cli/app.py`)
- Platform backend → API application: calls API
- Developer or agent → Agent plugins: uses agent plugin (evidence: `README.md`)
- Agent plugins → API application: sends and searches memories
- Developer or agent → OpenClaw integration: uses agent integration (evidence: `README.md`)
- OpenClaw integration → API application: recalls memories
- Developer or agent → SDK integrations: uses SDK integrations (evidence: `README.md`)
- SDK integrations → SDK clients: connects SDKs
