# fool-mrrice/codecrafters-redis-rust architecture

> Architecture diagram of the GitHub repository fool-mrrice/codecrafters-redis-rust, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fool-mrrice/codecrafters-redis-rust
- Repository: https://github.com/fool-mrrice/codecrafters-redis-rust

## Overview

This repository is a Rust Redis-compatible in-memory server. The principal workflow is a client sending RESP commands to the server, which dispatches commands to handlers and returns RESP responses backed by shared database state. The documented feature branches include strings, lists, Streams, blocking commands, transactions, expiry, RDB parsing, and replication. The README and excerpts support the main command path; implementation details for server networking and replication are not sampled, so those connections are left out or marked unverified.

Main entry points: [`src/main.rs`](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/main.rs) (Server entry), [`src/blocking.rs`](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/blocking.rs) (Blocking commands), [`src/commands.rs`](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/commands.rs) (Command dispatcher), [`src/handle.rs`](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/handle.rs) (Command handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server and protocol"]
  node_server_entry["Server entry<br/>[main.rs]"]
  node_resp["RESP codec<br/>[resp.rs]"]
end

subgraph group_commands["Commands and transactions"]
  node_dispatcher["Command dispatcher<br/>[commands.rs]"]
  node_handlers["Command handlers<br/>[handle.rs]"]
  node_blocking["Blocking commands<br/>[blocking.rs]"]
end

subgraph group_data["Data and Streams"]
  node_storage[("Database state<br/>[db_storage.rs]")]
  node_config["Server configuration<br/>[config.rs]"]
  node_stream_ids["Stream ID logic<br/>[stream_id.rs]"]
end

subgraph group_replication["Persistence and replication"]
  node_rdb_parser["RDB parser<br/>[parser.rs]"]
end

node_client(("Redis client"))
node_master(("Redis master"))
node_replicas(("Replica clients"))

node_client -.->|"sends commands"| node_server_entry
node_server_entry -.->|"routes commands"| node_dispatcher
node_dispatcher -->|"dispatches"| node_handlers
node_dispatcher -->|"parses and encodes"| node_resp
node_handlers -->|"accesses state"| node_storage
node_handlers -->|"uses ID logic"| node_stream_ids
node_blocking -->|"checks and queues"| node_storage
node_blocking -->|"encodes replies"| node_resp
node_blocking -->|"compares IDs"| node_stream_ids
node_master -.->|"replication handshake"| node_server_entry
node_server_entry -.->|"propagates commands"| node_replicas
node_master -.->|"provides RDB data"| node_rdb_parser
node_rdb_parser -->|"produces values"| node_storage

click node_server_entry "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/main.rs"
click node_resp "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/utils/resp.rs"
click node_dispatcher "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/commands.rs"
click node_handlers "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/handle.rs"
click node_blocking "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/blocking.rs"
click node_storage "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/storage/db_storage.rs"
click node_config "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/storage/config.rs"
click node_stream_ids "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/stream_id.rs"
click node_rdb_parser "https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/rdb/parser.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_entry,node_resp,node_replicas toneBlue
class node_dispatcher,node_handlers,node_blocking,node_client,node_master toneAmber
class node_storage,node_config,node_stream_ids toneMint
class node_rdb_parser toneRose
```

## Components

### Server and protocol

- [Server entry](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/main.rs): `src/main.rs`
- [RESP codec](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/utils/resp.rs): `src/utils/resp.rs`

### Commands and transactions

- [Command dispatcher](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/commands.rs): `src/commands.rs`
- [Command handlers](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/handle.rs): `src/handle.rs`
- [Blocking commands](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/blocking.rs): `src/blocking.rs`

### Data and Streams

- [Database state](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/storage/db_storage.rs): `src/storage/db_storage.rs`
- [Server configuration](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/storage/config.rs): `src/storage/config.rs`
- [Stream ID logic](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/stream_id.rs): `src/stream_id.rs`

### Persistence and replication

- [RDB parser](https://github.com/fool-mrrice/codecrafters-redis-rust/blob/main/src/rdb/parser.rs): `src/rdb/parser.rs`

### Other components

- **Redis client**
- **Redis master**
- **Replica clients**

## Connections

- Redis client → Server entry: sends commands (evidence: `README.md`)
- Server entry → Command dispatcher: routes commands (evidence: `README.md`)
- Command dispatcher → Command handlers: dispatches (evidence: `src/commands.rs`)
- Command dispatcher → RESP codec: parses and encodes (evidence: `src/commands.rs`)
- Command handlers → Database state: accesses state (evidence: `src/handle.rs`)
- Command handlers → Stream ID logic: uses ID logic (evidence: `src/handle.rs`)
- Blocking commands → Database state: checks and queues (evidence: `src/blocking.rs`)
- Blocking commands → RESP codec: encodes replies (evidence: `src/blocking.rs`)
- Blocking commands → Stream ID logic: compares IDs (evidence: `src/blocking.rs`)
- Redis master → Server entry: replication handshake (evidence: `README.md`)
- Server entry → Replica clients: propagates commands (evidence: `README.md`)
- Redis master → RDB parser: provides RDB data (evidence: `README.md`)
- RDB parser → Database state: produces values (evidence: `src/rdb/parser.rs`)
