# abhinav5568/in_memory_kv_store architecture

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

- Interactive diagram: https://gitdiagram.com/abhinav5568/in_memory_kv_store
- Repository: https://github.com/abhinav5568/in_memory_kv_store

## Overview

This repository implements a TCP key-value cache server with per-user memory blocks, an LRU/TTL cache, and append-only persistence restored at startup. The main workflow is a client sending AUTH and cache commands to the server, which routes them to a user cache and logs mutations; startup replays those logs before listening. The README is empty, so the map is based on the shown source excerpts and SOURCE INDEX; test files and data fixtures are omitted.

Main entry points: [`engine/server.js`](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/server.js) (TCP Server), [`engine/aof_bootstrap.js`](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/aof_bootstrap.js) (AOF Rehydration), [`engine/init/connections.js`](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/init/connections.js) (Shared Connections), [`engine/lru.js`](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/lru.js) (Per-user LRU Cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["TCP Runtime"]
  node_client["KV Client<br/>[KVClient.js]"]
  node_server["TCP Server<br/>[server.js]"]
end

subgraph group_identity["User Sessions"]
  node_manager["Connection Manager"]
  node_connections["Shared Connections<br/>[connections.js]"]
end

subgraph group_cache["Cache Engine"]
  node_cache["Per-user LRU Cache<br/>[lru.js]"]
end

subgraph group_persistence["Persistence"]
  node_logger["AOF Logger"]
  node_bootstrap["AOF Rehydration<br/>[aof_bootstrap.js]"]
  node_aof["AOF Files"]
end

node_actor(("Client App"))

node_actor -->|"uses"| node_client
node_client -->|"sends TCP frames"| node_server
node_server -->|"routes AUTH/INIT"| node_connections
node_connections -->|"exports instance"| node_manager
node_manager -->|"creates per-user"| node_cache
node_server -->|"executes commands"| node_cache
node_server -->|"logs mutations"| node_logger
node_logger -->|"appends commands"| node_aof
node_server -->|"awaits startup replay"| node_bootstrap
node_bootstrap -->|"reads logs"| node_aof
node_bootstrap -->|"restores user caches"| node_connections
node_bootstrap -->|"replays mutations"| node_cache

click node_client "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/lib/KVClient.js"
click node_server "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/server.js"
click node_manager "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/connection_manager.js"
click node_connections "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/init/connections.js"
click node_cache "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/lru.js"
click node_logger "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/aof_logger_engine.js"
click node_bootstrap "https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/aof_bootstrap.js"
click node_aof "https://github.com/abhinav5568/in_memory_kv_store/tree/main/engine/data"

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_client,node_server,node_actor toneBlue
class node_manager,node_connections toneAmber
class node_cache toneMint
class node_logger,node_bootstrap,node_aof toneRose
```

## Components

### TCP Runtime

- [KV Client](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/lib/KVClient.js): `engine/lib/KVClient.js`
- [TCP Server](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/server.js): `engine/server.js`

### User Sessions

- [Connection Manager](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/connection_manager.js): `engine/connection_manager.js`
- [Shared Connections](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/init/connections.js): `engine/init/connections.js`

### Cache Engine

- [Per-user LRU Cache](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/lru.js): `engine/lru.js`

### Persistence

- [AOF Logger](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/aof_logger_engine.js): `engine/aof_logger_engine.js`
- [AOF Rehydration](https://github.com/abhinav5568/in_memory_kv_store/blob/main/engine/aof_bootstrap.js): `engine/aof_bootstrap.js`
- [AOF Files](https://github.com/abhinav5568/in_memory_kv_store/tree/main/engine/data): `engine/data`

### Other components

- **Client App**

## Connections

- Client App → KV Client: uses (evidence: `engine/lib/KVClient.js`)
- KV Client → TCP Server: sends TCP frames (evidence: `engine/lib/KVClient.js`)
- TCP Server → Shared Connections: routes AUTH/INIT (evidence: `engine/server.js`)
- Shared Connections → Connection Manager: exports instance (evidence: `engine/init/connections.js`)
- Connection Manager → Per-user LRU Cache: creates per-user (evidence: `engine/connection_manager.js`)
- TCP Server → Per-user LRU Cache: executes commands (evidence: `engine/server.js`)
- TCP Server → AOF Logger: logs mutations (evidence: `engine/server.js`)
- AOF Logger → AOF Files: appends commands (evidence: `engine/aof_logger_engine.js`)
- TCP Server → AOF Rehydration: awaits startup replay (evidence: `engine/server.js`)
- AOF Rehydration → AOF Files: reads logs (evidence: `engine/aof_bootstrap.js`)
- AOF Rehydration → Shared Connections: restores user caches (evidence: `engine/aof_bootstrap.js`)
- AOF Rehydration → Per-user LRU Cache: replays mutations (evidence: `engine/aof_bootstrap.js`)
