# sawastik7-bit/build_your_own_redis_implementation architecture

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

- Interactive diagram: https://gitdiagram.com/sawastik7-bit/build_your_own_redis_implementation
- Repository: https://github.com/sawastik7-bit/build_your_own_redis_implementation

## Overview

This is a Redis-inspired TCP key-value server. Its principal workflow is a Redis CLI/client sending RESP over TCP; the server parses and dispatches commands, command handlers access the in-memory Map, and replies return over the socket. Supported command families include key operations, counters, expiration, multi-key access and server-side key management. Persistence uses a JSON dump, while a periodic expiration check is a separate internal layer. The graph follows documented or indexed relationships; some command implementations and the MSET/MGET handlers are not excerpted, so their detailed storage behavior is not asserted.

Main entry points: [`src/server.js`](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/server.js) (TCP server and dispatcher), [`src/storage/store.js`](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/store.js) (In-memory Map), [`src/storage/persistent.js`](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/persistent.js) (JSON persistence), [`src/commands`](https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands) (Key commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_network["Network protocol"]
  node_server["TCP server and dispatcher<br/>[server.js]"]
  node_parser["RESP parser<br/>[respParser.js]"]
end

subgraph group_commands["Command handling"]
  node_key_commands["Key commands"]
  node_counter_commands["Counter commands"]
  node_expiry_commands["Expiration commands"]
  node_multi_commands["Multi-key commands"]
  node_server_commands["Database commands<br/>[server.js]"]
end

subgraph group_state["Storage and expiry"]
  node_store[("In-memory Map<br/>[store.js]")]
  node_persistence[("JSON persistence<br/>[persistent.js]")]
  node_expiry_check["Expiry checker<br/>[expireCheckFunc.js]"]
end

node_client(("Redis client"))

node_client -->|"sends TCP requests"| node_server
node_server -->|"parses requests"| node_parser
node_server -->|"dispatches key ops"| node_key_commands
node_server -->|"dispatches counters"| node_counter_commands
node_server -->|"dispatches expiry"| node_expiry_commands
node_server -.->|"dispatches multi-key"| node_multi_commands
node_server -->|"handles DB ops"| node_server_commands
node_key_commands -->|"reads and writes"| node_store
node_counter_commands -->|"updates values"| node_store
node_expiry_commands -->|"reads and updates"| node_store
node_key_commands -->|"saves changes"| node_persistence
node_counter_commands -->|"saves changes"| node_persistence
node_expiry_commands -->|"saves changes"| node_persistence
node_store -->|"loads at startup"| node_persistence
node_server -->|"runs periodically"| node_expiry_check
node_expiry_check -->|"checks expirations"| node_store
node_expiry_check -->|"saves state"| node_persistence
node_server -->|"writes RESP replies"| node_client

click node_server "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/server.js"
click node_parser "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/parser/respParser.js"
click node_store "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/store.js"
click node_persistence "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/persistent.js"
click node_expiry_check "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/utils/expireCheckFunc.js"
click node_key_commands "https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands"
click node_counter_commands "https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands"
click node_expiry_commands "https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands"
click node_multi_commands "https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands"
click node_server_commands "https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/server.js"

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_parser toneBlue
class node_key_commands,node_counter_commands,node_expiry_commands,node_multi_commands,node_server_commands,node_client toneAmber
class node_store,node_persistence,node_expiry_check toneMint
```

## Components

### Network protocol

- [TCP server and dispatcher](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/server.js): `src/server.js`
- [RESP parser](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/parser/respParser.js): `src/parser/respParser.js`

### Command handling

- [Key commands](https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands): `src/commands`
- [Counter commands](https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands): `src/commands`
- [Expiration commands](https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands): `src/commands`
- [Multi-key commands](https://github.com/sawastik7-bit/build_your_own_redis_implementation/tree/main/src/commands): `src/commands`
- [Database commands](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/server.js): `src/server.js`

### Storage and expiry

- [In-memory Map](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/store.js): `src/storage/store.js`
- [JSON persistence](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/storage/persistent.js): `src/storage/persistent.js`
- [Expiry checker](https://github.com/sawastik7-bit/build_your_own_redis_implementation/blob/main/src/utils/expireCheckFunc.js): `src/utils/expireCheckFunc.js`

### Other components

- **Redis client**

## Connections

- Redis client → TCP server and dispatcher: sends TCP requests (evidence: `README.md`)
- TCP server and dispatcher → RESP parser: parses requests (evidence: `src/server.js`)
- TCP server and dispatcher → Key commands: dispatches key ops (evidence: `src/server.js`)
- TCP server and dispatcher → Counter commands: dispatches counters (evidence: `src/server.js`)
- TCP server and dispatcher → Expiration commands: dispatches expiry (evidence: `src/server.js`)
- TCP server and dispatcher → Multi-key commands: dispatches multi-key (evidence: `src/server.js`)
- TCP server and dispatcher → Database commands: handles DB ops (evidence: `src/server.js`)
- Key commands → In-memory Map: reads and writes (evidence: `src/commands/set.js`)
- Counter commands → In-memory Map: updates values (evidence: `src/commands/incrFunc.js`)
- Expiration commands → In-memory Map: reads and updates (evidence: `src/commands/expireFunc.js`)
- Key commands → JSON persistence: saves changes (evidence: `src/commands/set.js`)
- Counter commands → JSON persistence: saves changes (evidence: `src/commands/incrFunc.js`)
- Expiration commands → JSON persistence: saves changes (evidence: `src/commands/expireFunc.js`)
- In-memory Map → JSON persistence: loads at startup (evidence: `src/storage/store.js`)
- TCP server and dispatcher → Expiry checker: runs periodically (evidence: `src/server.js`)
- Expiry checker → In-memory Map: checks expirations (evidence: `src/utils/expireCheckFunc.js`)
- Expiry checker → JSON persistence: saves state (evidence: `src/utils/expireCheckFunc.js`)
- TCP server and dispatcher → Redis client: writes RESP replies (evidence: `src/server.js`)
