Status: Production Ready | Version: 1.0.0
MemoryKit uses Clean Architecture with strict dependency rules:
┌──────────────────────────────────────┐
│ API (REST) │
├──────────────────────────────────────┤
│ Application (Use Cases) │
├──────────────────────────────────────┤
│ Domain (Business Logic) ⭐ │ ← No Dependencies!
├──────────────────────────────────────┤
│ Infrastructure (External Services) │
└──────────────────────────────────────┘
Key Rule: Dependency flow is always inward. Domain has ZERO external dependencies.
Purpose: Core business logic - the heart of MemoryKit
| Component | Examples |
|---|---|
| Entities | Message, Conversation, ExtractedFact, ProceduralPattern |
| Value Objects | ImportanceScore, EmbeddingVector, QueryPlan |
| Enums | MessageRole, QueryType, MemoryLayer, EntityType |
| Interfaces | All service contracts (IWorkingMemoryService, etc.) |
Rules:
- ❌ ZERO external dependencies (except logging)
- ✅ Pure C# business logic
- ✅ Framework-agnostic
- ✅ Entities use factory methods, not public constructors
Purpose: Use cases and orchestration
| Component | Technology | Examples |
|---|---|---|
| Use Cases | MediatR CQRS | AddMessage, QueryMemory, GetContext |
| DTOs | Records | CreateMessageRequest, MessageResponse |
| Validators | FluentValidation | CreateMessageRequestValidator |
| Mapping | AutoMapper | Entity → DTO conversions |
Dependencies: Domain only
Purpose: External service implementations
| Namespace | Purpose |
|---|---|
| Azure | Redis, Table Storage, Blob Storage, AI Search |
| Cognitive | Amygdala, Hippocampus, Prefrontal Controller |
| SemanticKernel | Azure OpenAI, embeddings |
| InMemory | Testing implementations |
Dependencies: Implements Domain interfaces
Purpose: REST endpoints
| Component | Purpose |
|---|---|
| Controllers | REST endpoints |
| Middleware | Rate limiting, authentication |
| Program.cs | DI configuration |
Dependencies: All layers (composition root)
4-layer memory system inspired by human cognition:
| Layer | Storage | Latency | Capacity | Purpose |
|---|---|---|---|---|
| L3: Working | Redis | <5ms | 10 items | Hot context |
| L2: Semantic | Table Storage | ~30ms | Unlimited* | Facts & entities |
| L1: Episodic | Blob + AI Search | ~120ms | Full history | Complete archive |
| LP: Procedural | Table Storage | ~50ms | Patterns | Learned routines |
*With intelligent pruning
Services:
IWorkingMemoryServiceIScratchpadServiceIEpisodicMemoryServiceIProceduralMemoryService
| Brain Component | Function | Software | Service |
|---|---|---|---|
| Prefrontal Cortex | Executive function | Query planning | IPrefrontalController |
| Amygdala | Emotional tagging | Importance scoring | IAmygdalaImportanceEngine |
| Hippocampus | Short-term consolidation | Initial indexing | IHippocampusIndexer |
| Basal Ganglia | Procedural memory | Pattern matching | IProceduralMemoryService |
┌─────────────────┐
│ HTTP Request │
└────────┬────────┘
│
┌────▼─────┐
│Controller │
└────┬─────┘
│
┌────▼──────────┐
│ MediatR Query │
└────┬──────────┘
│
┌────▼──────────────┐
│ Application Layer │
└────┬──────────────┘
│
┌────▼────────────────────────┐
│ MemoryOrchestrator │
│ - BuildQueryPlan │
│ - RetrieveContext (parallel) │
└────┬────────────────────────┘
│
┌────┴──────────────────────────────┐
│ (Parallel retrieval) │
│ │
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐ │
│ L3 │ │ L2 │ │ L1 │ │ LP │ │
│Redis│ │Table│ │Blob+│ │Table│ │
│ │ │Store│ │Search │ │ │
└──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ │
│ │ │ │ │
└───────┴───────┴───────┴────────┘
│
┌────▼──────────────┐
│ SemanticKernel │
│ - LLM completion │
└────┬──────────────┘
│
┌────▼─────────┐
│ HTTP Response │
└───────────────┘
- Create interface in
Domain/Interfaces - Implement
IMemoryLayerinterface - Register in dependency injection
- Update
MemoryOrchestratorto use new layer - Add tests
- Create interface in
Infrastructure/Cognitive - Implement service in
Infrastructure/Cognitive - Register in dependency injection
- Update relevant orchestrators
- Add tests
- Create controller or update existing
- Create mediator command/query
- Create DTOs
- Create validators
- Add integration tests
- Commands for write operations
- Queries for read operations
- Separated handlers for each
- Abstracted data access
- Memory layer implementations
- Loose coupling
- Testability
- Flexibility
- Entity creation through factories
- Ensures valid state
- Pluggable memory layer implementations
- Different cognitive service strategies
- Memory layers retrieved in parallel
- Reduces total latency
- Working memory LRU eviction
- Fact importance-based retention
- Episodic compression
- Minimal context selection
- Query plan optimization
- Irrelevant data filtering
- API authentication/authorization
- User data isolation
- GDPR-compliant deletion
- Input validation
- XSS prevention
- CSRF protection
- Domain entities and value objects
- Business logic in services
- Memory layer interactions
- End-to-end query processing
- Latency monitoring
- Throughput testing
See DEPLOYMENT.md for cloud deployment strategies and infrastructure setup.
- Start with Domain layer (entities, interfaces)
- Implement Application layer (use cases)
- Create Infrastructure implementations
- Build API controllers
- Write tests throughout
- Performance testing
- Security review
- Documentation