# migorithm/duva architecture

> Architecture diagram of the GitHub repository migorithm/duva, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/migorithm/duva
- Repository: https://github.com/migorithm/duva

## Overview

##### Main Components

a) Core Services Layer:
- Client Service
- Cluster Service
- Config Service
- Statefuls Service (Cache and Persistence)

b) Actor System:
- Cache Actors
- TTL Actors
- Listening Actors
- Replication Actors

c) Protocol Layer:
- RESP Protocol Handler
- Stream Management

d) Storage Components:
- In-memory Cache
- Persistence (RDB file storage)
- AOF (Append Only File)

**┌─ Client Layer ─────────────────────────┐**
- RESP Protocol │ Client Connections     │
- Service Layer ──────────────────────────────────────┐
- Client Service │ Cluster Service │ Config Service    │
- Actor System ───────────────────────────────────────┐
- Cache Actors │ TTL Actors │ Listening │ Replication  │
- Storage Layer ─────────────────────────────────────┐
- In-Memory Cache │ RDB Storage │ AOF Storage        │
- ┘

##### Additional Elements

- Client request flow (as shown in client_query.mmd)
- Clustering mechanism (as shown in clustering.mmd)
- Election process (for Raft consensus)

##### Implementation Details

- src/services/client: Client handling
- src/services/cluster: Clustering functionality
- src/services/statefuls: State management
- src/adapters: I/O and cancellation handling

##### Key Processes to Highlight

- SET/GET operations flow
- TTL management
- Cluster formation and maintenance
- Data persistence operations
- Peer discovery and heartbeat mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef actor fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef future stroke-dasharray: 5 5
    
    %% Client Layer
    subgraph ClientLayer
        RESP["RESP Protocol"]
        ClientConn["Client Connections"]
        StreamMgmt["Stream Management"]
    end
    
    %% Service Layer
    subgraph ServiceLayer
        ClientSvc["Client Service"]
        ClusterSvc["Cluster Service"]
        ConfigSvc["Config Service"]
        StatefulsSvc["Statefuls Service"]
    end
    
    %% Actor System
    subgraph ActorSystem
        CacheActor["Cache Actors"]
        TTLActor["TTL Actors"]
        ListenActor["Listening Actors"]
        ReplActor["Replication Actors"]
    end
    
    %% Storage Layer
    subgraph StorageLayer
        Cache["In-Memory Cache"]
        RDB["RDB Storage"]
        AOF["AOF Storage"]
    end
    
    %% Future Components
    subgraph FutureFeatures
        Sharding["Distributed Sharding"]:::future
        AntiEntropy["Anti-Entropy"]:::future
        PubSub["Pub/Sub System"]:::future
    end
    
    %% Relationships
    RESP --> ClientSvc
    ClientConn --> StreamMgmt
    StreamMgmt --> ClientSvc
    
    ClientSvc --> CacheActor
    ClientSvc --> ClusterSvc
    
    ClusterSvc --> ListenActor
    ClusterSvc --> ReplActor
    
    ConfigSvc --> StatefulsSvc
    StatefulsSvc --> CacheActor
    
    CacheActor --> Cache
    CacheActor --> TTLActor
    TTLActor -.-> Cache
    
    Cache --> RDB
    Cache --> AOF
    
    ReplActor -.-> ListenActor
    
    %% Click Events
    click ClientSvc "https://github.com/Migorithm/duva/tree/master/src/services/client/"
    click ClusterSvc "https://github.com/Migorithm/duva/tree/master/src/services/cluster/"
    click ConfigSvc "https://github.com/Migorithm/duva/tree/master/src/services/config/"
    click StatefulsSvc "https://github.com/Migorithm/duva/tree/master/src/services/statefuls/"
    click CacheActor "https://github.com/Migorithm/duva/blob/master/src/services/statefuls/cache/actor.rs"
    click TTLActor "https://github.com/Migorithm/duva/blob/master/src/services/statefuls/cache/ttl/actor.rs"
    click ListenActor "https://github.com/Migorithm/duva/blob/master/src/services/cluster/actors/listening_actor.rs"
    click ReplActor "https://github.com/Migorithm/duva/blob/master/src/services/cluster/actors/replication.rs"
    click StreamMgmt "https://github.com/Migorithm/duva/blob/master/src/services/client/stream.rs"
    click Cache "https://github.com/Migorithm/duva/tree/master/src/services/statefuls/cache/"
    click RDB "https://github.com/Migorithm/duva/tree/master/src/services/statefuls/persist/"
    
    %% Style Applications
    class RESP,ClientConn,StreamMgmt client
    class ClientSvc,ClusterSvc,ConfigSvc,StatefulsSvc service
    class CacheActor,TTLActor,ListenActor,ReplActor actor
    class Cache,RDB,AOF storage
    class Sharding,AntiEntropy,PubSub future
```
