# rajeshpatel07/corekv architecture

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

- Interactive diagram: https://gitdiagram.com/rajeshpatel07/corekv
- Repository: https://github.com/rajeshpatel07/corekv

## Overview

CoreKV is an event-driven, in-memory key-value server for Redis-compatible clients. A client sends RESP commands to the TCP server; its event loop reads connection data, the parser decodes complete frames and dispatches commands, and command handlers access the sharded database before encoding replies for the connection. The graph also shows the internal hash-map layer and shared value types. Persistence and roadmap features are not implemented. Relationships are limited to calls visible in excerpts or references in the source index; unsampled details are omitted.

Main entry points: [`src/server/server.cpp`](https://github.com/rajeshpatel07/corekv/blob/main/src/server/server.cpp) (Event Server), [`src/parser/parser.cpp`](https://github.com/rajeshpatel07/corekv/blob/main/src/parser/parser.cpp) (Connection Parser), [`src/command/executor.cpp`](https://github.com/rajeshpatel07/corekv/blob/main/src/command/executor.cpp) (Command Dispatcher), [`src/db/db.cpp`](https://github.com/rajeshpatel07/corekv/blob/main/src/db/db.cpp) (Sharded Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_network["Networking"]
  node_server["Event Server<br/>[server.cpp]"]
  node_epoll["Epoll Wrapper<br/>[epoll.cpp]"]
  node_listener["TCP Listener<br/>[socket.cpp]"]
  node_connection["Client Connection<br/>[socket.h]"]
end

subgraph group_protocol["RESP Protocol"]
  node_parser["Connection Parser<br/>[parser.cpp]"]
  node_resp["RESP Codec<br/>[resp.cpp]"]
end

subgraph group_commands["Command Handling"]
  node_executor["Command Dispatcher<br/>[executor.cpp]"]
end

subgraph group_storage["Storage"]
  node_common["Value Types<br/>[common.h]"]
  node_database[("Sharded Database<br/>[db.cpp]")]
  node_hashmap["Incremental Hash Map<br/>[hashtable.cpp]"]
end

node_client(("Redis Client"))
node_entry["Application Entry<br/>[main.cpp]"]

node_client -->|"sends RESP"| node_server
node_entry -->|"starts"| node_server
node_server -->|"waits and updates"| node_epoll
node_server -->|"accepts clients"| node_listener
node_server -->|"reads and writes"| node_parser
node_server -->|"owns client"| node_connection
node_parser -->|"buffers frames"| node_connection
node_parser -->|"decodes frames"| node_resp
node_parser -->|"dispatches commands"| node_executor
node_executor -->|"encodes replies"| node_resp
node_executor -->|"reads and writes"| node_database
node_executor -->|"hashes keys"| node_common
node_database -->|"uses maps"| node_hashmap
node_hashmap -->|"stores values"| node_common

click node_entry "https://github.com/rajeshpatel07/corekv/blob/main/src/main.cpp"
click node_server "https://github.com/rajeshpatel07/corekv/blob/main/src/server/server.cpp"
click node_epoll "https://github.com/rajeshpatel07/corekv/blob/main/src/net/epoll.cpp"
click node_listener "https://github.com/rajeshpatel07/corekv/blob/main/src/net/socket.cpp"
click node_connection "https://github.com/rajeshpatel07/corekv/blob/main/src/net/socket.h"
click node_parser "https://github.com/rajeshpatel07/corekv/blob/main/src/parser/parser.cpp"
click node_resp "https://github.com/rajeshpatel07/corekv/blob/main/src/parser/resp.cpp"
click node_executor "https://github.com/rajeshpatel07/corekv/blob/main/src/command/executor.cpp"
click node_common "https://github.com/rajeshpatel07/corekv/blob/main/src/common/common.h"
click node_database "https://github.com/rajeshpatel07/corekv/blob/main/src/db/db.cpp"
click node_hashmap "https://github.com/rajeshpatel07/corekv/blob/main/src/db/hashtable.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_server,node_epoll,node_listener,node_connection toneBlue
class node_parser,node_resp,node_client toneAmber
class node_executor toneMint
class node_common,node_database,node_hashmap toneRose
class node_entry toneTeal
```

## Components

### Networking

- [Event Server](https://github.com/rajeshpatel07/corekv/blob/main/src/server/server.cpp): `src/server/server.cpp`
- [Epoll Wrapper](https://github.com/rajeshpatel07/corekv/blob/main/src/net/epoll.cpp): `src/net/epoll.cpp`
- [TCP Listener](https://github.com/rajeshpatel07/corekv/blob/main/src/net/socket.cpp): `src/net/socket.cpp`
- [Client Connection](https://github.com/rajeshpatel07/corekv/blob/main/src/net/socket.h): `src/net/socket.h`

### RESP Protocol

- [Connection Parser](https://github.com/rajeshpatel07/corekv/blob/main/src/parser/parser.cpp): `src/parser/parser.cpp`
- [RESP Codec](https://github.com/rajeshpatel07/corekv/blob/main/src/parser/resp.cpp): `src/parser/resp.cpp`

### Command Handling

- [Command Dispatcher](https://github.com/rajeshpatel07/corekv/blob/main/src/command/executor.cpp): `src/command/executor.cpp`

### Storage

- [Value Types](https://github.com/rajeshpatel07/corekv/blob/main/src/common/common.h): `src/common/common.h`
- [Sharded Database](https://github.com/rajeshpatel07/corekv/blob/main/src/db/db.cpp): `src/db/db.cpp`
- [Incremental Hash Map](https://github.com/rajeshpatel07/corekv/blob/main/src/db/hashtable.cpp): `src/db/hashtable.cpp`

### Other components

- **Redis Client**
- [Application Entry](https://github.com/rajeshpatel07/corekv/blob/main/src/main.cpp): `src/main.cpp`

## Connections

- Redis Client → Event Server: sends RESP (evidence: `README.md`)
- Application Entry → Event Server: starts (evidence: `src/main.cpp`)
- Event Server → Epoll Wrapper: waits and updates (evidence: `src/server/server.cpp`)
- Event Server → TCP Listener: accepts clients (evidence: `src/server/server.cpp`)
- Event Server → Connection Parser: reads and writes (evidence: `src/server/server.cpp`)
- Event Server → Client Connection: owns client (evidence: `src/server/server.cpp`)
- Connection Parser → Client Connection: buffers frames (evidence: `src/parser/parser.cpp`)
- Connection Parser → RESP Codec: decodes frames (evidence: `src/parser/parser.cpp`)
- Connection Parser → Command Dispatcher: dispatches commands (evidence: `src/parser/parser.cpp`)
- Command Dispatcher → RESP Codec: encodes replies (evidence: `src/command/executor.cpp`)
- Command Dispatcher → Sharded Database: reads and writes (evidence: `src/command/executor.cpp`)
- Command Dispatcher → Value Types: hashes keys (evidence: `src/command/executor.cpp`)
- Sharded Database → Incremental Hash Map: uses maps (evidence: `src/db/db.cpp`)
- Incremental Hash Map → Value Types: stores values
