# ph-tejas/redis-clone-cpp architecture

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

- Interactive diagram: https://gitdiagram.com/ph-tejas/redis-clone-cpp
- Repository: https://github.com/ph-tejas/redis-clone-cpp

## Overview

This is a Redis-inspired, multithreaded TCP in-memory database. A client command enters the server, is parsed and dispatched to a command implementation, then operates on shared storage; mutations can be persisted for replay after restart. The map also preserves the documented key/value, list, hash, expiration, and LRU capabilities. Several command implementations and persistence internals were not excerpted, so their detailed behavior and some connections are not asserted.

Main entry points: [`src/storage/StorageEngine.cpp`](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/storage/StorageEngine.cpp) (Shared storage), [`src/commands/factory/CommandFactory.cpp`](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/commands/factory/CommandFactory.cpp) (Command factory), [`src/server/RedisServer.cpp`](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/server/RedisServer.cpp) (TCP server), [`src/validation/CommandValidator.cpp`](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/validation/CommandValidator.cpp) (Command validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_bootstrap["Runtime bootstrap<br/>[main.cpp]"]
  node_server["TCP server<br/>[RedisServer.cpp]"]
end

subgraph group_dispatch["Command dispatch"]
  node_parser["Command parser<br/>[CommandParser.cpp]"]
  node_handler["Command handler<br/>[CommandHandler.cpp]"]
  node_factory["Command factory<br/>[CommandFactory.cpp]"]
  node_validator["Command validation"]
end

subgraph group_domain["Database commands"]
  node_kv["Key-value commands"]
  node_listcmd["List commands"]
  node_hashcmd["Hash commands"]
  node_expirycmd["Expiration commands"]
end

subgraph group_state["Storage and recovery"]
  node_storage[("Shared storage<br/>[StorageEngine.cpp]")]
  node_lru["LRU eviction<br/>[LRUCache.cpp]"]
  node_persistence["Persistence manager"]
end

node_client(("TCP client"))
node_aof["AOF file"]

node_client -->|"sends commands"| node_server
node_bootstrap -->|"starts"| node_server
node_bootstrap -->|"starts cleanup"| node_storage
node_server -->|"parses input"| node_parser
node_server -->|"dispatches input"| node_handler
node_parser -.->|"provides tokens"| node_handler
node_handler -->|"selects command"| node_factory
node_factory -->|"creates commands"| node_kv
node_factory -->|"creates commands"| node_listcmd
node_factory -->|"creates commands"| node_hashcmd
node_factory -->|"creates commands"| node_expirycmd
node_kv -->|"operates on"| node_storage
node_listcmd -->|"operates on"| node_storage
node_hashcmd -->|"operates on"| node_storage
node_expirycmd -->|"operates on"| node_storage
node_kv -->|"validates with"| node_validator
node_listcmd -->|"validates with"| node_validator
node_hashcmd -->|"validates with"| node_validator
node_expirycmd -->|"validates with"| node_validator
node_storage -->|"updates eviction state"| node_lru
node_storage -->|"replays and appends"| node_persistence
node_persistence -.->|"reads and writes"| node_aof

click node_bootstrap "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/main.cpp"
click node_server "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/server/RedisServer.cpp"
click node_parser "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/parser/CommandParser.cpp"
click node_handler "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/commands/CommandHandler.cpp"
click node_factory "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/commands/factory/CommandFactory.cpp"
click node_kv "https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types"
click node_listcmd "https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types"
click node_hashcmd "https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types"
click node_expirycmd "https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types"
click node_validator "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/validation/CommandValidator.cpp"
click node_storage "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/storage/StorageEngine.cpp"
click node_lru "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/cache/LRUCache.cpp"
click node_persistence "https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/persistence/PersistenceManager.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_bootstrap,node_server,node_client toneBlue
class node_parser,node_handler,node_factory,node_validator toneAmber
class node_kv,node_listcmd,node_hashcmd,node_expirycmd toneMint
class node_storage,node_lru,node_persistence toneRose
class node_aof toneIndigo
```

## Components

### Server runtime

- [Runtime bootstrap](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/main.cpp): `src/main.cpp`
- [TCP server](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/server/RedisServer.cpp): `src/server/RedisServer.cpp`

### Command dispatch

- [Command parser](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/parser/CommandParser.cpp): `src/parser/CommandParser.cpp`
- [Command handler](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/commands/CommandHandler.cpp): `src/commands/CommandHandler.cpp`
- [Command factory](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/commands/factory/CommandFactory.cpp): `src/commands/factory/CommandFactory.cpp`
- [Command validation](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/validation/CommandValidator.cpp): `src/validation/CommandValidator.cpp`

### Database commands

- [Key-value commands](https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types): `src/commands/types`
- [List commands](https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types): `src/commands/types`
- [Hash commands](https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types): `src/commands/types`
- [Expiration commands](https://github.com/ph-tejas/redis-clone-cpp/tree/main/src/commands/types): `src/commands/types`

### Storage and recovery

- [Shared storage](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/storage/StorageEngine.cpp): `src/storage/StorageEngine.cpp`
- [LRU eviction](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/cache/LRUCache.cpp): `src/cache/LRUCache.cpp`
- [Persistence manager](https://github.com/ph-tejas/redis-clone-cpp/blob/main/src/persistence/PersistenceManager.cpp): `src/persistence/PersistenceManager.cpp`

### Other components

- **TCP client**
- **AOF file**

## Connections

- TCP client → TCP server: sends commands
- Runtime bootstrap → TCP server: starts (evidence: `src/main.cpp`)
- Runtime bootstrap → Shared storage: starts cleanup (evidence: `src/main.cpp`)
- TCP server → Command parser: parses input
- TCP server → Command handler: dispatches input
- Command parser → Command handler: provides tokens
- Command handler → Command factory: selects command (evidence: `src/commands/CommandHandler.cpp`)
- Command factory → Key-value commands: creates commands (evidence: `src/commands/factory/CommandFactory.cpp`)
- Command factory → List commands: creates commands (evidence: `src/commands/factory/CommandFactory.cpp`)
- Command factory → Hash commands: creates commands (evidence: `src/commands/factory/CommandFactory.cpp`)
- Command factory → Expiration commands: creates commands (evidence: `src/commands/factory/CommandFactory.cpp`)
- Key-value commands → Shared storage: operates on (evidence: `src/commands/types/ExistsCommand.cpp`)
- List commands → Shared storage: operates on (evidence: `src/commands/types/LPUSHCommand.cpp`)
- Hash commands → Shared storage: operates on (evidence: `src/commands/types/HSETCommand.cpp`)
- Expiration commands → Shared storage: operates on (evidence: `src/commands/types/ExpireCommand.cpp`)
- Key-value commands → Command validation: validates with (evidence: `src/commands/types/ExistsCommand.cpp`)
- List commands → Command validation: validates with (evidence: `src/commands/types/LPUSHCommand.cpp`)
- Hash commands → Command validation: validates with (evidence: `src/commands/types/HSETCommand.cpp`)
- Expiration commands → Command validation: validates with (evidence: `src/commands/types/ExpireCommand.cpp`)
- Shared storage → LRU eviction: updates eviction state (evidence: `src/storage/StorageEngine.cpp`)
- Shared storage → Persistence manager: replays and appends (evidence: `src/storage/StorageEngine.cpp`)
- Persistence manager → AOF file: reads and writes
