# tejas544/distributed-kv architecture

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

- Interactive diagram: https://gitdiagram.com/tejas544/distributed-kv
- Repository: https://github.com/tejas544/distributed-kv

## Overview

Anvil combines a distributed key-value database with its deterministic simulation-testing harness. A workload issues client operations; the simulator runs the cluster against controlled time, network, disk, and process behavior, while protocol invariants and transactional-history checking detect failures and the minimiser reduces fault schedules. The database path spans range routing, shard storage, transaction coordination, MVCC, Raft, and LSM persistence. README-described capabilities are included even where implementation files were not sampled; edges relying on those descriptions cite the README.

Main entry points: [`anvil/core/shard/store.cc`](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/store.cc) (Shard store), [`anvil/sim/simulation.h`](https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/simulation.h) (Simulation runner), [`workloads/txn_bank.cc`](https://github.com/tejas544/distributed-kv/blob/main/workloads/txn_bank.cc) (Transaction workload), [`anvil/core/txn/coordinator.cc`](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/txn/coordinator.cc) (Transaction coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_database["Database"]
  node_range_cache["Range cache<br/>[router.cc]"]
  node_shard_store["Shard store<br/>[store.cc]"]
  node_placement["Placement and topology<br/>[topology.cc]"]
  node_txn_coordinator["Transaction coordinator<br/>[coordinator.cc]"]
  node_txn_store["Transaction store<br/>[store.cc]"]
  node_mvcc["MVCC and locks<br/>[mvcc.cc]"]
end

subgraph group_storage["Storage and consensus"]
  node_raft["Raft consensus<br/>[raft.cc]"]
  node_raft_storage["Raft persistence<br/>[storage.cc]"]
  node_lsm_db[("LSM database<br/>[db.cc]")]
  node_lsm_wal["Write-ahead log<br/>[wal.h]"]
end

subgraph group_simulation["Deterministic simulation"]
  node_runtime["Runtime seam<br/>[runtime.h]"]
  node_simulation_runner["Simulation runner<br/>[simulation.h]"]
  node_scheduler["Virtual scheduler<br/>[scheduler.cc]"]
  node_fault_models["Fault models<br/>[disk_model.cc]"]
end

subgraph group_verification["Verification"]
  node_invariants["Protocol invariants<br/>[raft_invariants.cc]"]
  node_history_checker["History checker<br/>[elle.cc]"]
  node_minimiser["Fault minimiser<br/>[minimiser.cc]"]
end

subgraph group_workloads["Workloads"]
  node_txn_workload["Transaction workload<br/>[txn_bank.cc]"]
  node_shard_workload["Shard workload<br/>[shard_kv.cc]"]
end

node_client(("Client"))

node_client -->|"routes requests"| node_range_cache
node_range_cache -->|"targets ranges"| node_shard_store
node_shard_workload -->|"exercises shards"| node_shard_store
node_txn_workload -->|"issues transactions"| node_txn_coordinator
node_txn_workload -->|"creates store"| node_shard_store
node_txn_coordinator -->|"coordinates operations"| node_shard_store
node_txn_coordinator -.->|"uses transaction records"| node_txn_store
node_shard_store -.->|"serves MVCC"| node_mvcc
node_placement -.->|"manages ranges"| node_shard_store
node_shard_store -.->|"replicates ranges"| node_raft
node_raft -->|"persists state"| node_raft_storage
node_raft_storage -->|"uses WAL framing"| node_lsm_wal
node_lsm_db -->|"logs writes"| node_lsm_wal
node_runtime -->|"abstracts execution"| node_simulation_runner
node_simulation_runner -.->|"runs scheduled events"| node_scheduler
node_simulation_runner -.->|"injects modeled faults"| node_fault_models
node_simulation_runner -->|"runs workload"| node_txn_workload
node_simulation_runner -->|"checks protocol state"| node_invariants
node_txn_workload -->|"checks recorded history"| node_history_checker
node_simulation_runner -.->|"minimises failures"| node_minimiser
node_invariants -->|"examines Raft state"| node_raft

click node_txn_workload "https://github.com/tejas544/distributed-kv/blob/main/workloads/txn_bank.cc"
click node_shard_workload "https://github.com/tejas544/distributed-kv/blob/main/workloads/shard_kv.cc"
click node_range_cache "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/router.cc"
click node_shard_store "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/store.cc"
click node_placement "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/topology.cc"
click node_txn_coordinator "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/txn/coordinator.cc"
click node_txn_store "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/txn/store.cc"
click node_mvcc "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/mvcc/mvcc.cc"
click node_raft "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/raft/raft.cc"
click node_raft_storage "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/raft/storage.cc"
click node_lsm_db "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/lsm/db.cc"
click node_lsm_wal "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/lsm/wal.h"
click node_runtime "https://github.com/tejas544/distributed-kv/blob/main/anvil/core/runtime/runtime.h"
click node_simulation_runner "https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/simulation.h"
click node_scheduler "https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/scheduler.cc"
click node_fault_models "https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/disk_model.cc"
click node_invariants "https://github.com/tejas544/distributed-kv/blob/main/anvil/checker/raft_invariants.cc"
click node_history_checker "https://github.com/tejas544/distributed-kv/blob/main/anvil/checker/elle.cc"
click node_minimiser "https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/minimiser.cc"

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_range_cache,node_shard_store,node_placement,node_txn_coordinator,node_txn_store,node_mvcc,node_client toneBlue
class node_raft,node_raft_storage,node_lsm_db,node_lsm_wal toneAmber
class node_runtime,node_simulation_runner,node_scheduler,node_fault_models toneMint
class node_invariants,node_history_checker,node_minimiser toneRose
class node_txn_workload,node_shard_workload toneIndigo
```

## Components

### Database

- [Range cache](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/router.cc): `anvil/core/shard/router.cc`
- [Shard store](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/store.cc): `anvil/core/shard/store.cc`
- [Placement and topology](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/shard/topology.cc): `anvil/core/shard/topology.cc`
- [Transaction coordinator](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/txn/coordinator.cc): `anvil/core/txn/coordinator.cc`
- [Transaction store](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/txn/store.cc): `anvil/core/txn/store.cc`
- [MVCC and locks](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/mvcc/mvcc.cc): `anvil/core/mvcc/mvcc.cc`

### Storage and consensus

- [Raft consensus](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/raft/raft.cc): `anvil/core/raft/raft.cc`
- [Raft persistence](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/raft/storage.cc): `anvil/core/raft/storage.cc`
- [LSM database](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/lsm/db.cc): `anvil/core/lsm/db.cc`
- [Write-ahead log](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/lsm/wal.h): `anvil/core/lsm/wal.h`

### Deterministic simulation

- [Runtime seam](https://github.com/tejas544/distributed-kv/blob/main/anvil/core/runtime/runtime.h): `anvil/core/runtime/runtime.h`
- [Simulation runner](https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/simulation.h): `anvil/sim/simulation.h`
- [Virtual scheduler](https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/scheduler.cc): `anvil/sim/scheduler.cc`
- [Fault models](https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/disk_model.cc): `anvil/sim/disk_model.cc`

### Verification

- [Protocol invariants](https://github.com/tejas544/distributed-kv/blob/main/anvil/checker/raft_invariants.cc): `anvil/checker/raft_invariants.cc`
- [History checker](https://github.com/tejas544/distributed-kv/blob/main/anvil/checker/elle.cc): `anvil/checker/elle.cc`
- [Fault minimiser](https://github.com/tejas544/distributed-kv/blob/main/anvil/sim/minimiser.cc): `anvil/sim/minimiser.cc`

### Workloads

- [Transaction workload](https://github.com/tejas544/distributed-kv/blob/main/workloads/txn_bank.cc): `workloads/txn_bank.cc`
- [Shard workload](https://github.com/tejas544/distributed-kv/blob/main/workloads/shard_kv.cc): `workloads/shard_kv.cc`

### Other components

- **Client**

## Connections

- Client → Range cache: routes requests
- Range cache → Shard store: targets ranges
- Shard workload → Shard store: exercises shards
- Transaction workload → Transaction coordinator: issues transactions (evidence: `workloads/txn_bank.cc`)
- Transaction workload → Shard store: creates store (evidence: `workloads/txn_bank.cc`)
- Transaction coordinator → Shard store: coordinates operations
- Transaction coordinator → Transaction store: uses transaction records
- Shard store → MVCC and locks: serves MVCC
- Placement and topology → Shard store: manages ranges
- Shard store → Raft consensus: replicates ranges
- Raft consensus → Raft persistence: persists state
- Raft persistence → Write-ahead log: uses WAL framing (evidence: `anvil/core/raft/storage.cc`)
- LSM database → Write-ahead log: logs writes
- Runtime seam → Simulation runner: abstracts execution (evidence: `anvil/core/runtime/runtime.h`)
- Simulation runner → Virtual scheduler: runs scheduled events
- Simulation runner → Fault models: injects modeled faults
- Simulation runner → Transaction workload: runs workload
- Simulation runner → Protocol invariants: checks protocol state
- Transaction workload → History checker: checks recorded history
- Simulation runner → Fault minimiser: minimises failures
- Protocol invariants → Raft consensus: examines Raft state
