Codebase Guide
Workspace Layout
Memorose is a Cargo workspace with four crates plus a Next.js dashboard:Crate Dependency Graph
- memorose-common has no internal dependencies — it is pure types and config.
- memorose-core depends on
memorose-commonand contains all business logic. - memorose-server and memorose-gateway both depend on
memorose-coreandmemorose-common.
Crate Responsibilities
memorose-common
Shared foundations used by every other crate:Event,EventContent,Memorydomain types- Configuration loading — TOML file + environment variable overrides
- Serialization helpers (serde, chrono, uuid)
- Error types (thiserror)
memorose-core
The bulk of the codebase. Key modules:| Module | Path | Role |
|---|---|---|
engine/ | src/engine/ | MemoroseEngine — main orchestrator with ~17 submodules for memory operations |
storage/ | src/storage/ | Multi-backend abstraction (see below) |
worker.rs | src/worker.rs | Background consolidation pipeline: L0 → L1 → L2, decay, pruning, community detection |
llm/ | src/llm/ | LLM provider abstraction — Gemini, OpenAI, and Mock implementations |
graph/ | src/graph/ | Knowledge graph operations, community detection (Louvain / LPA) |
ingest/ | src/ingest/ | Event ingestion pipeline |
raft/ | src/raft/ | Distributed consensus via openraft |
fact_extraction.rs | src/fact_extraction.rs | LLM-based fact extraction from raw events |
arbitrator.rs | src/arbitrator.rs | Conflict resolution between overlapping memories |
reranker.rs | src/reranker.rs | Search result reranking |
Storage Backends
All undermemorose-core/src/storage/:
| File | Backend | Purpose |
|---|---|---|
kv.rs | RocksDB | Key-value store for L0 raw events |
index.rs | LanceDB + Tantivy | Vector index (LanceDB) + full-text index (Tantivy) for L1 memories |
graph.rs | Custom | Knowledge graph storage for L2 insights |
blob.rs | File system | Blob storage for multimodal content |
system_kv.rs | RocksDB | System metadata and internal state |
tests.rs | — | Comprehensive storage test suite |
memorose-server
The HTTP layer:main.rs— Axum routes, Raft node bootstrap, API handlersshard_manager.rs— Shard-to-node routing logictypes.rs— API request / response typesdashboard/— Dashboard authentication and handler endpoints
memorose-gateway
A stateless HTTP proxy that sits in front of server nodes:- Routes requests to the correct shard based on
user_id - Handles tenant isolation via URL path
- No persistent state of its own
Dashboard Frontend
Thedashboard/ directory is a standard Next.js app:
- All API calls go through
fetchAPI()inlib/api.ts - Data fetching uses SWR hooks defined in
lib/hooks.ts - Types mirror the Rust server types in
lib/types.ts
Key Patterns
SQL Filter Builder
build_user_filter(user_id, app_id, extra) constructs SQL WHERE clauses for LanceDB queries. Used across vector search operations.
KV Scan
Key-value iteration useskv.scan(b"u:") with key window filtering for :unit: or :event: segments.
Dashboard Cache
Dashboard API responses are cached with a 5-minute TTL viastate.dashboard_cache (powered by moka).
Bitemporal Search
search_bitemporal() supports both valid-time and transaction-time queries, with optional agent_id filtering as the 7th parameter.