with one click
architecture
// Memoria codebase structure, workspace layout, key traits, database tables, config patterns, and testing conventions. Use when navigating or modifying Memoria code.
// Memoria codebase structure, workspace layout, key traits, database tables, config patterns, and testing conventions. Use when navigating or modifying Memoria code.
Use Memoria as OpenClaw's durable memory slot. Triggers: "remember this", "save to memory", "what do you remember", "continue from last time", "forget this", "correct memory", "take a snapshot", "rollback memory", "branch memory", "merge memory", "use long-term memory".
Install Memoria and configure MCP for AI tools (Kiro, Cursor, Claude Code, Codex, Gemini CLI). Decision tree for Cloud vs self-hosted mode, database, embedding provider. Use when helping users set up Memoria.
Deploy Memoria with Docker Compose or Kubernetes. Environment variables, multi-instance setup, security. Use when deploying or configuring Memoria.
Memoria REST API endpoints, request/response formats, auth, rate limits. Use when calling or implementing API endpoints.
Run embedding on-device with ONNX Runtime. Build from source, model selection, offline mode. Use when setting up local embedding without an API key.
Create, test, sign, and publish Memoria governance plugins. Covers Rhai and gRPC runtimes, manifest format, lifecycle. Use when developing or managing plugins.
| name | architecture |
| description | Memoria codebase structure, workspace layout, key traits, database tables, config patterns, and testing conventions. Use when navigating or modifying Memoria code. |
memoria/ # Cargo workspace root
āāā crates/
ā āāā memoria-core/ # Shared types: MemoriaError, Memory, MemoryType
ā āāā memoria-storage/ # SqlMemoryStore ā all SQL queries, migrations
ā āāā memoria-service/ # Business logic
ā ā āāā src/
ā ā āāā service.rs # MemoryService ā main entry point
ā ā āāā scheduler.rs # GovernanceScheduler ā periodic tasks + leader election
ā ā āāā config.rs # Config struct (reads env vars)
ā ā āāā distributed.rs # DistributedLock, AsyncTaskStore traits + SQL impls
ā ā āāā governance/ # GovernanceStrategy trait, DefaultGovernanceStrategy
ā ā āāā plugin/ # Plugin system (manifest, repository, rhai, grpc)
ā āāā memoria-api/ # REST API (axum)
ā ā āāā src/
ā ā āāā lib.rs # build_router(), route registration
ā ā āāā state.rs # AppState (service, task_store, instance_id)
ā ā āāā routes/ # memory, admin, governance, plugins, sessions
ā āāā memoria-mcp/ # MCP server (stdio/SSE transport)
ā āāā memoria-cli/ # CLI binary: init, mcp, serve, plugin, benchmark
ā āāā memoria-embedding/ # Embedding + LLM client
ā āāā memoria-git/ # Git-for-Data: snapshots, branches, merge
āāā Cargo.toml # Workspace deps
āāā build.rs # Proto compilation (tonic)
trait GovernanceStrategy: Send + Sync {
fn strategy_key(&self) -> &str;
async fn plan(&self, store, task) -> Result<GovernancePlan>;
async fn execute(&self, store, task, plan) -> Result<GovernanceExecution>;
}
trait GovernanceStore: Send + Sync {
async fn list_active_users(&self) -> Result<Vec<String>>;
async fn quarantine_low_confidence(&self, user) -> Result<i64>;
// ... cleanup/maintenance methods
}
trait DistributedLock: Send + Sync {
async fn try_acquire(&self, key, holder, ttl) -> Result<bool>;
async fn renew(&self, key, holder, ttl) -> Result<bool>;
async fn release(&self, key, holder) -> Result<()>;
}
trait AsyncTaskStore: Send + Sync {
async fn create_task(&self, task) -> Result<()>;
async fn complete_task(&self, task_id, result) -> Result<()>;
async fn fail_task(&self, task_id, error) -> Result<()>;
async fn get_task(&self, task_id) -> Result<Option<AsyncTask>>;
}
| Group | Tables |
|---|---|
| Core | mem_memories, mem_user_state, mem_branches, mem_snapshots |
| Graph | memory_graph_nodes, memory_graph_edges, mem_entities, mem_memory_entity_links, mem_entity_links |
| Audit | mem_edit_log, mem_retrieval_feedback, mem_memories_stats |
| Governance | mem_governance_cooldown, mem_governance_runtime_state, mem_user_retrieval_params |
| Auth | mem_api_keys |
| Plugin | mem_plugin_packages, mem_plugin_signers, mem_plugin_bindings, mem_plugin_binding_rules, mem_plugin_reviews, mem_plugin_audit_events |
| Distributed | mem_distributed_locks, mem_async_tasks |
Config struct in config.rs reads from env vars:
| Field | Env Var | Default |
|---|---|---|
db_url | DATABASE_URL | mysql://root:111@localhost:6001/memoria |
embedding_provider | EMBEDDING_PROVIDER | local |
instance_id | MEMORIA_INSTANCE_ID | Random UUID |
lock_ttl_secs | MEMORIA_LOCK_TTL_SECS | 120 |
governance_plugin_dir | MEMORIA_GOVERNANCE_PLUGIN_DIR | None |
governance_plugin_binding | MEMORIA_GOVERNANCE_PLUGIN_BINDING | default |
governance_plugin_subject | MEMORIA_GOVERNANCE_PLUGIN_SUBJECT | system |
When adding a Config field: update ALL test Config { .. } constructors ā check scheduler.rs tests AND tests/plugin_repository.rs.
| Prefix | Module | Auth | Purpose |
|---|---|---|---|
/v1/memories | routes/memory.rs | Bearer | CRUD, search, retrieve |
/v1/snapshots, /v1/branches | routes/memory.rs | Bearer | Git-for-Data |
/v1/sessions | routes/sessions.rs | Bearer | Episodic memory, async tasks |
/v1/governance | routes/governance.rs | Bearer | Trigger governance |
/admin/* | routes/admin.rs | Master | Admin ops |
/admin/plugins/* | routes/plugins.rs | Master | Plugin repository |
/health | routes/admin.rs | None | Liveness probe |
/health/instance | routes/memory.rs | None | Readiness probe (returns instance_id) |
memoria-api/src/routes/memoria-api/src/lib.rs build_router()memoria-api/tests/api_e2e.rs using spawn_server()plugin/
āāā mod.rs # Re-exports
āāā manifest.rs # PluginManifest, PluginPackage, signing verification
āāā repository.rs # Publish, review, score, binding rules, audit
āāā rhai_runtime.rs # RhaiGovernanceStrategy (sandboxed Rhai)
āāā grpc_runtime.rs # GrpcGovernanceStrategy (remote gRPC)
āāā governance_hook.rs # Contract testing harness
āāā templates/ # Rhai governance template
| Component | File | Purpose |
|---|---|---|
DistributedLock trait | distributed.rs | Lock abstraction |
NoopDistributedLock | distributed.rs | Single-instance no-op |
SqlMemoryStore lock impl | distributed.rs | INSERT-based DB lock with TTL |
AsyncTaskStore trait | distributed.rs | Cross-instance task visibility |
GovernanceScheduler | scheduler.rs | Leader election + heartbeat |
AppState | state.rs | Holds instance_id + DB task store |
make check # cargo check + clippy -D warnings (MUST pass)
make test-unit # Unit tests (no DB): memoria-core, memoria-service, memoria-mcp
make test # All tests (needs MatrixOne, --test-threads=1)
make test-e2e # API e2e tests only
Patterns:
spawn_server() ā random port, shared DB, reqwest clientspawn_server_with_instance() ā custom instance IDbuild_signed_plugin_files() helper for base64 file mapsuuid::Uuid::new_v4().simple() for test isolationDATABASE_URL env var-D warnings ā any warning = build failurePathBuf::from("x") in comparisons ā use Path::new("x")format!() inside println!() ā inline args directlyrepository.rs ā plugin/mod.rs ā lib.rsGovernanceScheduler constructors ā #[allow(clippy::too_many_arguments)]chrono::NaiveDateTime, not String