Mem0 is a memory layer for AI agents: a Python core library (pyproject.toml) defaulting to Qdrant for vector storage and OpenAI for embeddings and LLM calls, with an optional FastAPI hosted server and Next.js dashboard for teams that want it managed.
- Language
- Python
- Database
- PostgreSQL
- Hosting
- Docker
- License
- Apache-2.0
- Running for
- 1 year 2 months
- Team
- 2-5 people
Why this architecture
Keeping the core library provider-agnostic through optional dependency groups, while the hosted server bundles a fixed set of vector stores, LLM providers, auth, and rate limiting behind its own FastAPI app, lets self-hosters install a minimal footprint without forking the managed-service code path.
Tech stack by layer
8 technologies · audited Sep 17, 2026- Next.jsPowers the standalone dashboard app under server/dashboard.
- ReactComponent layer for the dashboard, on React 19.
- Radix UIAccessible primitives (dialogs, dropdowns, tooltips) used throughout the dashboard.
- Tailwind CSSStyling for the dashboard, extended with the typography plugin and tailwind-merge.
- PythonImplements the core mem0ai memory library published from the repository root.
- FastAPIServes the optional hosted memory API in server/, built on top of the mem0ai package.
- UvicornASGI server that runs the FastAPI app; the Dockerfile starts it directly.
- AlembicManages schema migrations for the hosted server auth and account database.
- QdrantDefault vector store for the core memory library, used unless another backend is configured.
- OpenAIDefault LLM and embedding provider for the core memory library.
- PostgreSQLBacks the hosted server auth and account database via psycopg.
- SQLAlchemyORM used for relational storage in both the core library and the hosted server.
- RedisOptional vector store backend for the core library, alongside Qdrant.
- GitHub ActionsSeparate CI/CD workflows build, test, and release the Python SDK, TypeScript SDK, and integrations.
- AnthropicBundled as a directly supported LLM provider in the hosted server image.
Mem0 architecture diagram
Open SVGDiagram as text
- Your app (Python · TS SDKs) → mem0ai library (extract · retrieve): embedded library
- Your app (Python · TS SDKs) → Memory API (FastAPI · Uvicorn): REST
- Dashboard (Next.js) → Memory API (FastAPI · Uvicorn): REST
- Memory API (FastAPI · Uvicorn) → mem0ai library (extract · retrieve): memory ops
- Memory API (FastAPI · Uvicorn) → PostgreSQL (auth · accounts): SQLAlchemy
- mem0ai library (extract · retrieve) → Vector store (Qdrant (default) · Redis): vectors
- mem0ai library (extract · retrieve) → LLM & embeddings (OpenAI (default) · Anthropic): extract · embed
Key architectural decisions
6 decisions- 01
Core memory library ships with a default vector and LLM stack
pyproject.toml pins qdrant-client and openai as unconditional dependencies of the mem0ai package, so a fresh install has a working vector store and LLM/embedder immediately, while its optional-dependency groups (vector-stores, llms) swap in over a dozen alternative backends.
- 02
Hosted server is layered on the core library, not a fork of it
server/requirements.txt depends on mem0ai itself alongside fastapi and uvicorn, plus its own auth stack (sqlalchemy, alembic, passlib, python-jose) and rate limiting (slowapi), so the hosted API adds a multi-tenant layer on top of the open-source engine.
- 03
The server bundles a fixed set of LLM providers, not the full extras
server/requirements.txt pins anthropic and google-generativeai directly, with a comment noting that adding a provider means rebuilding the image and updating BUNDLED_LLM_PROVIDERS in main.py, instead of installing the broader optional llms dependency group defined in the root pyproject.toml.
- 04
The dashboard is a standalone Next.js app, not server-rendered by the API
server/dashboard/package.json defines its own Next.js 15 project with its own Dockerfile producing a standalone Node build (.next/standalone), so the dashboard is built, containerized, and scaled independently of the FastAPI server it calls.
- 05
PostgreSQL plays two different roles depending on which part is deployed
The root pyproject.toml lists psycopg and psycopg-pool as optional dependencies for using Postgres, via pgvector, as a vector store inside the core library, while server/requirements.txt depends on psycopg unconditionally to back the relational auth and account database used only by the hosted server.
- 06
Telemetry is opt-out by default across the library and the server
Both the root pyproject.toml and server/requirements.txt depend on posthog, and server/requirements.txt documents it directly as anonymous telemetry that is on by default and disabled by setting MEM0_TELEMETRY=false.
How Mem0 is built
How Mem0 is structured
The repository root is the Python mem0ai package (pyproject.toml, built with hatchling), which is the library most self-hosted usage depends on directly. mem0-ts/package.json defines a parallel TypeScript SDK (also published as mem0ai on npm) built with tsup into CJS and ESM outputs. server/ contains an optional, separately deployable hosted API: server/requirements.txt for the FastAPI backend and server/dashboard/package.json for its Next.js admin UI. cli/python and cli/node hold command-line tools, and integrations/ contains a set of adapter packages (vercel-ai-sdk, n8n-nodes-mem0, zapier-mem0, deepseek-plugin, opencode-plugin, pi-agent-plugin, mem0-strands) that connect the core SDKs to specific agent frameworks and automation platforms, each with its own CI workflow pair (*-checks.yml / *-cd.yml) under .github/workflows.
Backend & APIs
The core Python library's direct dependencies in pyproject.toml are deliberately small: qdrant-client, pydantic, openai, httpx, posthog, pytz, and sqlalchemy. Everything else — other vector stores, other LLM providers, langchain, sentence-transformers — is behind optional dependency groups (vector-stores, llms, extras, nlp), so a default pip install mem0ai pulls in only what is needed to talk to Qdrant and OpenAI. The hosted server in server/ is a different application: server/requirements.txt depends on mem0ai as a library plus fastapi and uvicorn for the HTTP layer, and adds its own concerns that the core library does not have — sqlalchemy/alembic for a relational auth schema, passlib[bcrypt] and python-jose[cryptography] for password hashing and JWTs, and slowapi for per-IP rate limiting on auth endpoints. It also pins anthropic and google-generativeai directly as bundled LLM providers, separate from the core library's llms optional group, with a comment in the requirements file explaining that new providers require rebuilding the server image.
Data & persistence
Vector storage defaults to Qdrant in the core library (qdrant-client in pyproject.toml), with the vector-stores optional group covering Chroma, Cassandra, Weaviate, Pinecone, FAISS, Upstash Vector, Azure AI Search, PostgreSQL via psycopg/psycopg-pool (pgvector), MongoDB, MySQL, Redis/Valkey, Elasticsearch, Milvus, and Oracle. sqlalchemy is a core dependency used for relational history/metadata storage independent of whichever vector store is configured. The hosted server has a separate, unconditional PostgreSQL dependency (psycopg) that has nothing to do with vector search — it backs the server's own accounts, API keys, and auth tables, migrated with alembic. The TypeScript SDK (mem0-ts/package.json) lists iovalkey (a Valkey/Redis client) as a development dependency, used for its own test/example infrastructure rather than as a required runtime dependency of the published package.
Frontend
server/dashboard is a self-contained Next.js 15 application (next": "15.5.24", React 19) with its own package.json, unrelated to the SDK packages' build tooling. It uses @reduxjs/toolkit and react-redux for state, @tanstack/react-table for tabular data, a large set of @radix-ui/react-* primitives (accordion, dialog, dropdown-menu, select, tabs, tooltip, and more) for accessible UI components, recharts for charts, framer-motion for animation, and Tailwind CSS (via tailwind-merge, tailwindcss-animate, and the @tailwindcss/typography dev dependency) for styling. It talks to the FastAPI server as a separate backend rather than using Next.js API routes for the core memory functionality, per the NEXT_PUBLIC_API_URL build-time environment variable configured in server/dashboard/Dockerfile.
Build, test & deploy
The Python package builds with hatchling per pyproject.toml's [build-system], and its [tool.hatch.envs.*] sections define per-Python-version (3.10–3.13, based on the dev_py_3_10/dev_py_3_11 env names visible in the manifest) test environments combining the test, vector-stores, llms, and extras feature groups. ruff and isort are the lint/format tools in the dev optional group. The TypeScript SDK's mem0-ts/package.json runs jest for unit and integration tests (separate test:unit and test:integration scripts with different Jest configs) and builds with tsup. CI is split per component: .github/workflows/ci.yml and cd.yml for the core Python/TS release, and dedicated cli-node-ci.yml/cli-node-cd.yml, cli-python-ci.yml/cli-python-cd.yml, ts-sdk-ci.yml/ts-sdk-cd.yml, and one *-checks.yml/*-cd.yml pair per integration package, so each publishable artifact has its own gated release pipeline. server/Dockerfile and server/dashboard/Dockerfile are the deployment artifacts for the hosted product; neither has a corresponding root-level docker-compose.yml in the audited tree, so wiring the two containers and a Postgres instance together is left to the deployer.
Self-hosting notes
Self-hosting the core library only needs a Python environment with mem0ai and a reachable vector store — Qdrant if using the defaults, or another backend from the vector-stores optional group. Self-hosting the full product (API plus dashboard) additionally needs a PostgreSQL database for the server's own auth tables, and requires setting MEM0_TELEMETRY=false in server/requirements.txt's documented environment variable if the default PostHog telemetry should be disabled. server/Dockerfile exposes port 8000 for the API and runs uvicorn main:app --reload, which is a development-style entrypoint (the --reload flag watches for file changes) rather than a hardened production gunicorn/uvicorn workers setup, so operators may want to override the container's CMD for production. server/dashboard/Dockerfile is a standard three-stage Next.js production build (deps, builder, runner) that runs as a non-root nextjs user.
What to copy (and what not to)
Making the core library's non-default integrations opt-in through pyproject.toml optional-dependency groups (vector-stores, llms, extras) while keeping a small, opinionated default (Qdrant plus OpenAI) is a good template for any library that wants to support many backends without forcing every user to install all of them. Layering the hosted, multi-tenant server as a separate application that depends on the open-source library, rather than diverging the library itself, keeps the core package simple and is worth copying when building a managed offering on top of an open-source core. Bundling a fixed, small set of LLM providers directly into the server image (anthropic, google-generativeai) instead of exposing the library's full provider matrix trades flexibility for a smaller, more predictable container — reasonable for an official hosted service, but self-hosters who need a different provider will have to modify and rebuild the image rather than just setting a configuration value.
Sources & repo audit
- Audited
- Sep 17, 2026
- Commit
- f135cb9
- License
- Apache-2.0
- pyproject.toml (core library dependencies: qdrant-client, openai, sqlalchemy)
- server/requirements.txt (FastAPI hosted server: fastapi, uvicorn, anthropic, alembic)
- server/Dockerfile (python:3.12-slim, uvicorn entrypoint)
- server/dashboard/package.json (Next.js dashboard dependencies)
- mem0-ts/package.json (TypeScript SDK build and test setup)
Independent analysis of repository at github.com/mem0ai/mem0. Spotted an inaccuracy? Use the claim form to request a correction.
Show this stack on your README or website
[](https://stackitfast.com/project/mem0)Paste it into your README. It shows your current stack and links to this page.
Scaffold it with your agent
Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Mem0's architecture.
- 1Copy the promptThe full markdown spec, with every layer and decision.
- 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
- 3Paste and scaffoldUse it as the first instruction; review before you ship.
# MISSION: Scaffold "Mem0" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Mem0**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Mem0
- **What It Does**: Mem0 is a memory layer for AI agents: a Python core library (pyproject.toml) defaulting to Qdrant for vector storage and OpenAI for embeddings and LLM calls, with an optional FastAPI hosted server and Next.js dashboard for teams that want it managed.
- **Domain & Category**: AI Memory & Context Engine
- **Production Scale**: 2-5 people
- **Development Mode**: AI-AGENT
- **Architectural Rationale**: Keeping the core library provider-agnostic through optional dependency groups, while the hosted server bundles a fixed set of vector stores, LLM providers, auth, and rate limiting behind its own FastAPI app, lets self-hosters install a minimal footprint without forking the managed-service code path.
- **Live Website Reference**: https://mem0.ai
- **Source Repository**: https://github.com/mem0ai/mem0
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: Python, TypeScript, FastAPI, Qdrant, OpenAI, PostgreSQL, Next.js, Redis
- **Primary Language(s)**: Python, TypeScript
- **License of the reference repo**: Apache-2.0
- **Frontend**: Next.js — Powers the standalone dashboard app under server/dashboard.; React — Component layer for the dashboard, on React 19.; Radix UI — Accessible primitives (dialogs, dropdowns, tooltips) used throughout the dashboard.; Tailwind CSS — Styling for the dashboard, extended with the typography plugin and tailwind-merge.
- **Backend & APIs**: Python — Implements the core mem0ai memory library published from the repository root.; FastAPI — Serves the optional hosted memory API in server/, built on top of the mem0ai package.; Uvicorn — ASGI server that runs the FastAPI app; the Dockerfile starts it directly.; Alembic — Manages schema migrations for the hosted server auth and account database.
- **Data & persistence**: Qdrant — Default vector store for the core memory library, used unless another backend is configured.; OpenAI — Default LLM and embedding provider for the core memory library.; PostgreSQL — Backs the hosted server auth and account database via psycopg.; SQLAlchemy — ORM used for relational storage in both the core library and the hosted server.; Redis — Optional vector store backend for the core library, alongside Qdrant.
- **Infrastructure & deploy**: Docker — Separate Dockerfiles package the FastAPI server and the Next.js dashboard as containers.; PostHog — Anonymous telemetry collector, enabled by default in both the library and the hosted server.
- **Tooling, testing & ops**: GitHub Actions — Separate CI/CD workflows build, test, and release the Python SDK, TypeScript SDK, and integrations.; Anthropic — Bundled as a directly supported LLM provider in the hosted server image.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/mem0ai/mem0 @ f135cb9)
1. **Core memory library ships with a default vector and LLM stack**: pyproject.toml pins qdrant-client and openai as unconditional dependencies of the mem0ai package, so a fresh install has a working vector store and LLM/embedder immediately, while its optional-dependency groups (vector-stores, llms) swap in over a dozen alternative backends.
2. **Hosted server is layered on the core library, not a fork of it**: server/requirements.txt depends on mem0ai itself alongside fastapi and uvicorn, plus its own auth stack (sqlalchemy, alembic, passlib, python-jose) and rate limiting (slowapi), so the hosted API adds a multi-tenant layer on top of the open-source engine.
3. **The server bundles a fixed set of LLM providers, not the full extras**: server/requirements.txt pins anthropic and google-generativeai directly, with a comment noting that adding a provider means rebuilding the image and updating BUNDLED_LLM_PROVIDERS in main.py, instead of installing the broader optional llms dependency group defined in the root pyproject.toml.
4. **The dashboard is a standalone Next.js app, not server-rendered by the API**: server/dashboard/package.json defines its own Next.js 15 project with its own Dockerfile producing a standalone Node build (.next/standalone), so the dashboard is built, containerized, and scaled independently of the FastAPI server it calls.
5. **PostgreSQL plays two different roles depending on which part is deployed**: The root pyproject.toml lists psycopg and psycopg-pool as optional dependencies for using Postgres, via pgvector, as a vector store inside the core library, while server/requirements.txt depends on psycopg unconditionally to back the relational auth and account database used only by the hosted server.
6. **Telemetry is opt-out by default across the library and the server**: Both the root pyproject.toml and server/requirements.txt depend on posthog, and server/requirements.txt documents it directly as anonymous telemetry that is on by default and disabled by setting MEM0_TELEMETRY=false.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
- Structure as a Turborepo monorepo with strict package boundaries:
- `apps/web`: Application UI, routing, layouts, and server endpoints.
- `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
- `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
- `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
- Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
- Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
- Utilize Next.js 15 App Router: default to React Server Components (RSC) for data fetching. Handle mutations through Server Actions with Zod validation. Keep 'use client' directives restricted strictly to interactive leaf components.
4. **Design System & Aesthetics**:
- Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
- Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
- Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
- Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (Qdrant, OpenAI, PostgreSQL, SQLAlchemy, Redis): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.Frequently asked about Mem0
What is Mem0 built with?
The core memory library is Python (pyproject.toml), defaulting to Qdrant for vector storage and OpenAI for LLM and embedding calls. A TypeScript SDK (mem0-ts) mirrors it, and an optional hosted server (server/) adds a FastAPI backend with a Next.js dashboard (server/dashboard).
Does Mem0 need a backend?
Not necessarily. The Python and TypeScript SDKs can run embedded in an application against a vector store directly. server/ adds an optional FastAPI backend with its own PostgreSQL-backed auth for teams that want a hosted memory API instead.
Can I self-host Mem0?
Yes. server/Dockerfile packages the FastAPI server on python:3.12-slim with uvicorn, and server/dashboard/Dockerfile packages the Next.js dashboard as a standalone Node build, so both pieces run as separate containers.
Which vector stores does Mem0 support?
Qdrant is the default, pinned directly in pyproject.toml. The vector-stores optional dependency group adds Chroma, Weaviate, Pinecone, FAISS, Redis, Elasticsearch, Milvus, MongoDB, Azure AI Search, and PostgreSQL via pgvector, among others.
Which LLM providers does Mem0 support?
OpenAI is the core default. The llms optional dependency group in pyproject.toml adds Groq, Together, LiteLLM, Ollama, and Google Vertex AI/Generative AI, and the hosted server in server/requirements.txt additionally bundles Anthropic and google-generativeai directly.
One email a month: new deep dives and stack trends
New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.
Similar architectures
- Dify.aiAI-agentLLM App Builder · 20+ peopleShares Next.js · TypeScript · Python
- FormbricksAI-agentSurvey & Feedback SaaS · 2-5 peopleShares Next.js · TypeScript · PostgreSQL
- Open WebUIAI-agentSelf-Hosted AI Interface & Agent Hub · 2-5 peopleShares Python · TypeScript · FastAPI
- UmamiHybridWeb Analytics · SoloShares TypeScript · Next.js · PostgreSQL
- LangfuseAI-agentLLM Observability · 6-20 peopleShares TypeScript · Next.js · PostgreSQL
- OpenMAICClassicMulti-Agent Interactive AI Classroom · 6-20 peopleShares TypeScript · Next.js · PostgreSQL