# silverarrow77/raft architecture

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

- Interactive diagram: https://gitdiagram.com/silverarrow77/raft
- Repository: https://github.com/silverarrow77/raft

## Overview

This is a small replicated key-value store: a client sends text commands to a node, which handles reads locally and routes writes through Raft; committed entries update the store and are persisted in a write-ahead log (WAL). Configuration supplies the node and peer addresses. The graph separates request handling, consensus, storage, and configuration, while retaining the message parser as a distinct module. The README is empty, so capabilities and links are limited to the source excerpts; unsampled client and message behavior is not inferred.

Main entry points: [`src/network/Server.cpp`](https://github.com/silverarrow77/raft/blob/main/src/network/Server.cpp) (TCP server), [`src/raft/RaftNode.cpp`](https://github.com/silverarrow77/raft/blob/main/src/raft/RaftNode.cpp) (Raft node), [`src/storage/KVStore.cpp`](https://github.com/silverarrow77/raft/blob/main/src/storage/KVStore.cpp) (Key-value state), [`src/main.cpp`](https://github.com/silverarrow77/raft/blob/main/src/main.cpp) (Program entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and networking"]
  node_main["Program entry<br/>[main.cpp]"]
  node_server["TCP server<br/>[Server.cpp]"]
  node_message["Message parser<br/>[message.cpp]"]
end

subgraph group_consensus["Raft consensus"]
  node_raft["Raft node<br/>[RaftNode.cpp]"]
end

subgraph group_storage["Key-value storage"]
  node_command["Command parsing<br/>[KVStore.cpp]"]
  node_kv[("Key-value state<br/>[KVStore.cpp]")]
  node_wal[("WAL persistence<br/>[wal.cpp]")]
end

subgraph group_setup["Node configuration"]
  node_config["Config reader<br/>[config.cpp]"]
end

node_client(("Client"))
node_peers(("Raft peers"))

node_client -->|"sends commands"| node_server
node_main -->|"reads config"| node_config
node_main -->|"constructs node"| node_raft
node_main -->|"starts server"| node_server
node_server -->|"starts node"| node_raft
node_server -->|"parses input"| node_command
node_server -->|"routes RPCs"| node_raft
node_server -->|"routes writes"| node_raft
node_server -->|"validates requests"| node_kv
node_raft -->|"sends Raft RPCs"| node_peers
node_peers -->|"sends RPCs"| node_server
node_raft -->|"applies commits"| node_kv
node_command -->|"updates state"| node_kv
node_kv -->|"appends records"| node_wal
node_server -->|"restores log"| node_wal

click node_main "https://github.com/silverarrow77/raft/blob/main/src/main.cpp"
click node_server "https://github.com/silverarrow77/raft/blob/main/src/network/Server.cpp"
click node_message "https://github.com/silverarrow77/raft/blob/main/src/message/message.cpp"
click node_raft "https://github.com/silverarrow77/raft/blob/main/src/raft/RaftNode.cpp"
click node_command "https://github.com/silverarrow77/raft/blob/main/src/storage/KVStore.cpp"
click node_kv "https://github.com/silverarrow77/raft/blob/main/src/storage/KVStore.cpp"
click node_wal "https://github.com/silverarrow77/raft/blob/main/src/storage/wal.cpp"
click node_config "https://github.com/silverarrow77/raft/blob/main/src/config/config.cpp"

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_main,node_server,node_message,node_client toneBlue
class node_raft toneAmber
class node_command,node_kv,node_wal toneMint
class node_config toneRose
class node_peers toneIndigo
```

## Components

### Entry and networking

- [Program entry](https://github.com/silverarrow77/raft/blob/main/src/main.cpp): `src/main.cpp`
- [TCP server](https://github.com/silverarrow77/raft/blob/main/src/network/Server.cpp): `src/network/Server.cpp`
- [Message parser](https://github.com/silverarrow77/raft/blob/main/src/message/message.cpp): `src/message/message.cpp`

### Raft consensus

- [Raft node](https://github.com/silverarrow77/raft/blob/main/src/raft/RaftNode.cpp): `src/raft/RaftNode.cpp`

### Key-value storage

- [Command parsing](https://github.com/silverarrow77/raft/blob/main/src/storage/KVStore.cpp): `src/storage/KVStore.cpp`
- [Key-value state](https://github.com/silverarrow77/raft/blob/main/src/storage/KVStore.cpp): `src/storage/KVStore.cpp`
- [WAL persistence](https://github.com/silverarrow77/raft/blob/main/src/storage/wal.cpp): `src/storage/wal.cpp`

### Node configuration

- [Config reader](https://github.com/silverarrow77/raft/blob/main/src/config/config.cpp): `src/config/config.cpp`

### Other components

- **Client**
- **Raft peers**

## Connections

- Client → TCP server: sends commands (evidence: `src/network/Server.cpp`)
- Program entry → Config reader: reads config (evidence: `src/main.cpp`)
- Program entry → Raft node: constructs node (evidence: `src/main.cpp`)
- Program entry → TCP server: starts server (evidence: `src/main.cpp`)
- TCP server → Raft node: starts node (evidence: `src/network/Server.cpp`)
- TCP server → Command parsing: parses input (evidence: `src/network/Server.cpp`)
- TCP server → Raft node: routes RPCs (evidence: `src/network/Server.cpp`)
- TCP server → Raft node: routes writes (evidence: `src/network/Server.cpp`)
- TCP server → Key-value state: validates requests (evidence: `src/network/Server.cpp`)
- Raft node → Raft peers: sends Raft RPCs (evidence: `src/raft/RaftNode.cpp`)
- Raft peers → TCP server: sends RPCs (evidence: `src/network/Server.cpp`)
- Raft node → Key-value state: applies commits (evidence: `src/raft/RaftNode.cpp`)
- Command parsing → Key-value state: updates state (evidence: `src/storage/KVStore.cpp`)
- Key-value state → WAL persistence: appends records (evidence: `src/storage/KVStore.cpp`)
- TCP server → WAL persistence: restores log (evidence: `src/network/Server.cpp`)
