# kividbio/kividb architecture

> Architecture diagram of the GitHub repository kividbio/kividb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kividbio/kividb
- Repository: https://github.com/kividbio/kividb

## Overview

KiviDB is a Redis-compatible in-memory database server with RESP2/RESP3 clients, sharded key-value storage, optional persistence, replication and cluster operation, plus search, vectors, JSON and time-series capabilities. The principal workflow is a client sending a Redis command over the network; the server parses and dispatches it, operates on database state, and returns a protocol reply. The graph preserves documented product branches, but sampled excerpts do not expose the full request-dispatch implementation, so some subsystem relationships are documented by the README rather than traced through source.

Main entry points: [`src/commands`](https://github.com/kividbio/kividb/tree/master/src/commands) (Redis commands), [`src/main.rs`](https://github.com/kividbio/kividb/blob/master/src/main.rs) (Server startup), [`src/commands/search.rs`](https://github.com/kividbio/kividb/blob/master/src/commands/search.rs) (Full-text search), [`src/listen.rs`](https://github.com/kividbio/kividb/blob/master/src/listen.rs) (Network listeners)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Server startup<br/>[main.rs]"]
  node_network["Network listeners<br/>[listen.rs]"]
  node_resp["RESP protocol"]
  node_dispatch["Command dispatch<br/>[handler.rs]"]
end

subgraph group_data["Data and commands"]
  node_commands["Redis commands"]
  node_store[("Sharded key store<br/>[mod.rs]")]
  node_pubsub["Pub/sub<br/>[pubsub.rs]"]
  node_sketch["Probabilistic sketches<br/>[mod.rs]"]
end

subgraph group_search["Search and analytics"]
  node_search["Full-text search<br/>[search.rs]"]
  node_pipeline["Aggregation pipeline"]
  node_vector["Vector indexes<br/>[mod.rs]"]
  node_json["JSON commands<br/>[json.rs]"]
  node_timeseries["Time-series commands<br/>[ts_query.rs]"]
end

subgraph group_durability["Durability and topology"]
  node_aof[("Append-only log<br/>[aof.rs]")]
  node_snapshot[("Snapshots<br/>[snapshot.rs]")]
  node_replication["Replication<br/>[mod.rs]"]
  node_replica_client["Replica client<br/>[replica_client.rs]"]
  node_cluster["Cluster state<br/>[mod.rs]"]
  node_routing["Cluster routing<br/>[routing.rs]"]
end

subgraph group_security["Security and clients"]
  node_registry["Client registry<br/>[client_registry.rs]"]
  node_acl["ACL controls<br/>[acl.rs]"]
  node_config["Configuration<br/>[config.rs]"]
end

node_client(("Redis client"))

node_client -->|"connects"| node_network
node_network -->|"serves clients"| node_server
node_client -->|"speaks RESP"| node_resp
node_resp -.->|"dispatches commands"| node_dispatch
node_dispatch -.->|"routes commands"| node_commands
node_commands -.->|"reads and writes"| node_store
node_commands -.->|"publishes messages"| node_pubsub
node_commands -->|"runs FT commands"| node_search
node_search -.->|"uses indexes"| node_vector
node_search -->|"aggregates results"| node_pipeline
node_commands -->|"runs JSON commands"| node_json
node_commands -->|"runs TS commands"| node_timeseries
node_commands -.->|"runs sketch commands"| node_sketch
node_server -->|"initializes persistence"| node_aof
node_server -->|"starts replication"| node_replication
node_replication -->|"uses replica client"| node_replica_client
node_server -->|"starts cluster"| node_cluster
node_cluster -->|"routes slots"| node_routing
node_server -->|"restores indexes"| node_snapshot
node_server -->|"tracks connections"| node_registry
node_commands -.->|"checks permissions"| node_acl
node_server -.->|"loads settings"| node_config

click node_server "https://github.com/kividbio/kividb/blob/master/src/main.rs"
click node_network "https://github.com/kividbio/kividb/blob/master/src/listen.rs"
click node_resp "https://github.com/kividbio/kividb/tree/master/src/resp"
click node_dispatch "https://github.com/kividbio/kividb/blob/master/src/commands/handler.rs"
click node_registry "https://github.com/kividbio/kividb/blob/master/src/client_registry.rs"
click node_acl "https://github.com/kividbio/kividb/blob/master/src/acl.rs"
click node_config "https://github.com/kividbio/kividb/blob/master/src/config.rs"
click node_commands "https://github.com/kividbio/kividb/tree/master/src/commands"
click node_store "https://github.com/kividbio/kividb/blob/master/src/store/mod.rs"
click node_pubsub "https://github.com/kividbio/kividb/blob/master/src/pubsub.rs"
click node_search "https://github.com/kividbio/kividb/blob/master/src/commands/search.rs"
click node_pipeline "https://github.com/kividbio/kividb/blob/master/src/commands/aggregate_pipeline.rs"
click node_vector "https://github.com/kividbio/kividb/blob/master/src/vector/mod.rs"
click node_json "https://github.com/kividbio/kividb/blob/master/src/commands/json.rs"
click node_timeseries "https://github.com/kividbio/kividb/blob/master/src/commands/ts_query.rs"
click node_aof "https://github.com/kividbio/kividb/blob/master/src/aof.rs"
click node_snapshot "https://github.com/kividbio/kividb/blob/master/src/snapshot.rs"
click node_replication "https://github.com/kividbio/kividb/blob/master/src/replication/mod.rs"
click node_replica_client "https://github.com/kividbio/kividb/blob/master/src/replication/replica_client.rs"
click node_cluster "https://github.com/kividbio/kividb/blob/master/src/cluster/mod.rs"
click node_routing "https://github.com/kividbio/kividb/blob/master/src/cluster/routing.rs"
click node_sketch "https://github.com/kividbio/kividb/blob/master/src/sketch/mod.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_network,node_resp,node_dispatch toneBlue
class node_commands,node_store,node_pubsub,node_sketch,node_client toneAmber
class node_search,node_pipeline,node_vector,node_json,node_timeseries toneMint
class node_aof,node_snapshot,node_replication,node_replica_client,node_cluster,node_routing toneRose
class node_registry,node_acl,node_config toneIndigo
```

## Components

### Server runtime

- [Server startup](https://github.com/kividbio/kividb/blob/master/src/main.rs): `src/main.rs`
- [Network listeners](https://github.com/kividbio/kividb/blob/master/src/listen.rs): `src/listen.rs`
- [RESP protocol](https://github.com/kividbio/kividb/tree/master/src/resp): `src/resp`
- [Command dispatch](https://github.com/kividbio/kividb/blob/master/src/commands/handler.rs): `src/commands/handler.rs`

### Data and commands

- [Redis commands](https://github.com/kividbio/kividb/tree/master/src/commands): `src/commands`
- [Sharded key store](https://github.com/kividbio/kividb/blob/master/src/store/mod.rs): `src/store/mod.rs`
- [Pub/sub](https://github.com/kividbio/kividb/blob/master/src/pubsub.rs): `src/pubsub.rs`
- [Probabilistic sketches](https://github.com/kividbio/kividb/blob/master/src/sketch/mod.rs): `src/sketch/mod.rs`

### Search and analytics

- [Full-text search](https://github.com/kividbio/kividb/blob/master/src/commands/search.rs): `src/commands/search.rs`
- [Aggregation pipeline](https://github.com/kividbio/kividb/blob/master/src/commands/aggregate_pipeline.rs): `src/commands/aggregate_pipeline.rs`
- [Vector indexes](https://github.com/kividbio/kividb/blob/master/src/vector/mod.rs): `src/vector/mod.rs`
- [JSON commands](https://github.com/kividbio/kividb/blob/master/src/commands/json.rs): `src/commands/json.rs`
- [Time-series commands](https://github.com/kividbio/kividb/blob/master/src/commands/ts_query.rs): `src/commands/ts_query.rs`

### Durability and topology

- [Append-only log](https://github.com/kividbio/kividb/blob/master/src/aof.rs): `src/aof.rs`
- [Snapshots](https://github.com/kividbio/kividb/blob/master/src/snapshot.rs): `src/snapshot.rs`
- [Replication](https://github.com/kividbio/kividb/blob/master/src/replication/mod.rs): `src/replication/mod.rs`
- [Replica client](https://github.com/kividbio/kividb/blob/master/src/replication/replica_client.rs): `src/replication/replica_client.rs`
- [Cluster state](https://github.com/kividbio/kividb/blob/master/src/cluster/mod.rs): `src/cluster/mod.rs`
- [Cluster routing](https://github.com/kividbio/kividb/blob/master/src/cluster/routing.rs): `src/cluster/routing.rs`

### Security and clients

- [Client registry](https://github.com/kividbio/kividb/blob/master/src/client_registry.rs): `src/client_registry.rs`
- [ACL controls](https://github.com/kividbio/kividb/blob/master/src/acl.rs): `src/acl.rs`
- [Configuration](https://github.com/kividbio/kividb/blob/master/src/config.rs): `src/config.rs`

### Other components

- **Redis client**

## Connections

- Redis client → Network listeners: connects (evidence: `README.md`)
- Network listeners → Server startup: serves clients (evidence: `src/main.rs`)
- Redis client → RESP protocol: speaks RESP (evidence: `README.md`)
- RESP protocol → Command dispatch: dispatches commands
- Command dispatch → Redis commands: routes commands
- Redis commands → Sharded key store: reads and writes
- Redis commands → Pub/sub: publishes messages
- Redis commands → Full-text search: runs FT commands (evidence: `README.md`)
- Full-text search → Vector indexes: uses indexes
- Full-text search → Aggregation pipeline: aggregates results (evidence: `src/commands/aggregate_pipeline.rs`)
- Redis commands → JSON commands: runs JSON commands (evidence: `README.md`)
- Redis commands → Time-series commands: runs TS commands (evidence: `README.md`)
- Redis commands → Probabilistic sketches: runs sketch commands
- Server startup → Append-only log: initializes persistence (evidence: `src/main.rs`)
- Server startup → Replication: starts replication (evidence: `src/main.rs`)
- Replication → Replica client: uses replica client (evidence: `src/main.rs`)
- Server startup → Cluster state: starts cluster (evidence: `src/main.rs`)
- Cluster state → Cluster routing: routes slots (evidence: `src/cluster/routing.rs`)
- Server startup → Snapshots: restores indexes (evidence: `src/main.rs`)
- Server startup → Client registry: tracks connections (evidence: `src/main.rs`)
- Redis commands → ACL controls: checks permissions
- Server startup → Configuration: loads settings (evidence: `src/main.rs`)
