# sarthak-shubham/cherry architecture

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

- Interactive diagram: https://gitdiagram.com/sarthak-shubham/cherry
- Repository: https://github.com/sarthak-shubham/cherry

## Overview

Cherry is a single-node persistent key-value store. CLI commands send HTTP requests to the server, which routes GET, PUT, and DELETE operations to the concurrent in-memory store; writes append to the WAL before changing memory. At startup, main replays the WAL to rebuild the map before serving requests. The graph follows those documented and excerpted paths; it omits test and build machinery.

Main entry points: [`main.go`](https://github.com/sarthak-shubham/cherry/blob/main/main.go) (Startup orchestration), [`store/methods.go`](https://github.com/sarthak-shubham/cherry/blob/main/store/methods.go) (Concurrent operations), [`server/server.go`](https://github.com/sarthak-shubham/cherry/blob/main/server/server.go) (HTTP server), [`client/cli.go`](https://github.com/sarthak-shubham/cherry/blob/main/client/cli.go) (CLI commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entrypoints"]
  node_cli["CLI commands<br/>[cli.go]"]
  node_client_http["HTTP client<br/>[client.go]"]
end

subgraph group_api["HTTP API"]
  node_server_start["HTTP server<br/>[server.go]"]
  node_routing["Request routing<br/>[handler.go]"]
  node_api_handlers["KV handlers<br/>[kv.go]"]
end

subgraph group_storage["Store and WAL"]
  node_store_core["Store state<br/>[store.go]"]
  node_store_ops["Concurrent operations<br/>[methods.go]"]
  node_wal[("JSONL write-ahead log<br/>[persist.go]")]
end

subgraph group_startup["Startup recovery"]
  node_startup_main["Startup orchestration<br/>[main.go]"]
  node_replay["WAL replay<br/>[recover.go]"]
end

node_user(("CLI user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"dispatches commands"| node_client_http
node_client_http -->|"sends HTTP"| node_server_start
node_server_start -->|"routes requests"| node_routing
node_routing -->|"dispatches methods"| node_api_handlers
node_api_handlers -->|"calls operations"| node_store_ops
node_store_ops -->|"reads and updates"| node_store_core
node_store_ops -->|"appends records"| node_wal
node_startup_main -->|"recovers state"| node_replay
node_replay -->|"reads records"| node_wal
node_startup_main -->|"creates store"| node_store_core
node_startup_main -->|"starts server"| node_server_start

click node_cli "https://github.com/sarthak-shubham/cherry/blob/main/client/cli.go"
click node_client_http "https://github.com/sarthak-shubham/cherry/blob/main/client/client.go"
click node_server_start "https://github.com/sarthak-shubham/cherry/blob/main/server/server.go"
click node_routing "https://github.com/sarthak-shubham/cherry/blob/main/server/handler.go"
click node_api_handlers "https://github.com/sarthak-shubham/cherry/blob/main/server/kv.go"
click node_store_core "https://github.com/sarthak-shubham/cherry/blob/main/store/store.go"
click node_store_ops "https://github.com/sarthak-shubham/cherry/blob/main/store/methods.go"
click node_wal "https://github.com/sarthak-shubham/cherry/blob/main/persistence/persist.go"
click node_startup_main "https://github.com/sarthak-shubham/cherry/blob/main/main.go"
click node_replay "https://github.com/sarthak-shubham/cherry/blob/main/recovery/recover.go"

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_cli,node_client_http,node_user toneBlue
class node_server_start,node_routing,node_api_handlers toneAmber
class node_store_core,node_store_ops,node_wal toneMint
class node_startup_main,node_replay toneRose
```

## Components

### Application entrypoints

- [CLI commands](https://github.com/sarthak-shubham/cherry/blob/main/client/cli.go): `client/cli.go`
- [HTTP client](https://github.com/sarthak-shubham/cherry/blob/main/client/client.go): `client/client.go`

### HTTP API

- [HTTP server](https://github.com/sarthak-shubham/cherry/blob/main/server/server.go): `server/server.go`
- [Request routing](https://github.com/sarthak-shubham/cherry/blob/main/server/handler.go): `server/handler.go`
- [KV handlers](https://github.com/sarthak-shubham/cherry/blob/main/server/kv.go): `server/kv.go`

### Store and WAL

- [Store state](https://github.com/sarthak-shubham/cherry/blob/main/store/store.go): `store/store.go`
- [Concurrent operations](https://github.com/sarthak-shubham/cherry/blob/main/store/methods.go): `store/methods.go`
- [JSONL write-ahead log](https://github.com/sarthak-shubham/cherry/blob/main/persistence/persist.go): `persistence/persist.go`

### Startup recovery

- [Startup orchestration](https://github.com/sarthak-shubham/cherry/blob/main/main.go): `main.go`
- [WAL replay](https://github.com/sarthak-shubham/cherry/blob/main/recovery/recover.go): `recovery/recover.go`

### Other components

- **CLI user**

## Connections

- CLI user → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → HTTP client: dispatches commands (evidence: `client/cli.go`)
- HTTP client → HTTP server: sends HTTP (evidence: `README.md`)
- HTTP server → Request routing: routes requests (evidence: `server/server.go`)
- Request routing → KV handlers: dispatches methods (evidence: `server/handler.go`)
- KV handlers → Concurrent operations: calls operations (evidence: `server/kv.go`)
- Concurrent operations → Store state: reads and updates (evidence: `store/methods.go`)
- Concurrent operations → JSONL write-ahead log: appends records (evidence: `store/methods.go`)
- Startup orchestration → WAL replay: recovers state (evidence: `main.go`)
- WAL replay → JSONL write-ahead log: reads records (evidence: `README.md`)
- Startup orchestration → Store state: creates store (evidence: `main.go`)
- Startup orchestration → HTTP server: starts server (evidence: `main.go`)
