Core Pattern: Layered architecture with dependency injection via constructors and factory patterns.
MemoryManager (orchestrator)
├── Handlers (embedding, LLM, cache)
├── Stores (memory, JSON, SPARQL)
├── Connectors (Ollama, Claude, Mistral)
└── Context/Utils (window management, templates)
- MemoryManager: Main coordinator, handles initialization/disposal lifecycle
- BaseStore: Abstract storage interface - extend for new backends
- BaseAPI: Abstract API interface - extend for new endpoints
- EmbeddingHandler: Vector operations with validation/standardization
- LLMHandler: Chat/completion with prompt templating
- Config: Hierarchical config merging (defaults → file → env → user)
- Custom error classes with type/cause properties
- Graceful degradation with fallbacks
- Proper cleanup in disposal/shutdown methods
- Constructor → async initialize() → operations → dispose()
- Promise-based with proper error propagation
- Timeout/retry logic for external services
- Environment variables override config files
- Validation in
validateConfig() - Provider fallback chains by priority
// All stores implement:
async loadHistory() → [shortTerm[], longTerm[]]
async saveMemoryToHistory(memoryStore)
async beginTransaction/commitTransaction/rollbackTransaction// All APIs implement:
async initialize()
async executeOperation(operation, params)
async getMetrics()
async shutdown()src/MemoryManager.js- Main orchestratorsrc/Config.js- Configuration managementsrc/stores/BaseStore.js- Storage interfacesrc/api/common/BaseAPI.js- API interface
src/stores/JSONStore.js- File-based storage with transactionssrc/stores/SPARQLStore.js- RDF/SPARQL storage with validationsrc/connectors/OllamaConnector.js- Local LLM integrationsrc/api/features/MemoryAPI.js- Memory operations API
CLAUDE_API_KEY,OLLAMA_API_BASE- Provider credentialsLOG_LEVEL- Logging verbosityNODE_ENV- Environment mode
config/config.json- Production configurationconfig.sample.json- Template with all options.env- Local development overrides
- Unit Tests: Core classes with mocked dependencies
- Integration Tests: End-to-end with real services
- LLM Tests: Separate test suite for external dependencies
- Use
vitestframework with coverage reporting
- Setup: Copy
example.env→.env, configure API keys - Core Changes: Modify base classes, update implementing classes
- New Stores: Extend
BaseStore, implement interface methods - New APIs: Extend
BaseAPI, register inAPIRegistry - Testing: Run
npm test(excludes LLM tests),npm run test:llmsfor full suite
- ES Modules: Use
import/export, no CommonJS - Error First: Validate inputs, fail fast with descriptive errors
- Disposal: Always implement cleanup (close connections, clear timers)
- Logging: Use
loglevelwith appropriate levels - Immutability: Clone objects when modifying, avoid mutation
- Type Safety: JSDoc annotations, runtime validation
- Extend
BaseStoreclass - Implement required methods with proper error handling
- Add configuration options to
Config.defaults - Register in storage factory/selection logic
- Create connector implementing required methods
- Add provider config to
llmProvidersarray - Update
Config.jstransformation logic - Test with representative models
- Extend
BaseAPIclass - Implement
executeOperationwith operation routing - Register in
APIRegistry - Add HTTP routes in server configuration
Core: faiss-node (vectors), loglevel (logging), uuid (IDs)
Storage: Direct HTTP for SPARQL, filesystem for JSON
LLM: hyperdata-clients (unified interface), provider SDKs
Server: express, cors, helmet, compression