# destrivate/ddb architecture

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

- Interactive diagram: https://gitdiagram.com/destrivate/ddb
- Repository: https://github.com/destrivate/ddb

## Overview

DDB is a small in-memory key-value database exposed over TCP. Its main workflow starts at the process entry point, loads optional pipe-delimited defaults into the shared store, then accepts client connections; each handler dispatches set/get/del commands to the store and sends the resulting status or value back. Configuration supplies the port and default-file path. The README documents syntax-error responses, though the sampled handler does not cover every malformed-command case; other runtime links are shown only where the excerpts establish them.

Main entry points: [`src/main.cpp`](https://github.com/destrivate/ddb/blob/main/src/main.cpp) (Process startup), [`src/server/server.cpp`](https://github.com/destrivate/ddb/blob/main/src/server/server.cpp) (Command handler), [`src/storage/ddb.cpp`](https://github.com/destrivate/ddb/blob/main/src/storage/ddb.cpp) (Key-value operations), [`src/storage/ddb.hpp`](https://github.com/destrivate/ddb/blob/main/src/storage/ddb.hpp) (In-memory map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup"]
  node_process["Process startup<br/>[main.cpp]"]
  node_defaults["Default loader<br/>[main.cpp]"]
end

subgraph group_network["TCP Server"]
  node_server["TCP server<br/>[server.cpp]"]
  node_handler["Command handler<br/>[server.cpp]"]
end

subgraph group_storage["Key-Value Storage"]
  node_core["Key-value operations<br/>[ddb.cpp]"]
  node_map[("In-memory map<br/>[ddb.hpp]")]
end

subgraph group_runtime["Runtime Support"]
  node_config["Config reader<br/>[config_utility.hpp]"]
  node_logger["Logger<br/>[logger.hpp]"]
end

node_default_file["Default data file<br/>[default.txt]"]
node_client(("TCP client"))

node_process -->|"reads settings"| node_config
node_process -->|"logs port"| node_logger
node_process -->|"loads defaults"| node_defaults
node_defaults -->|"reads rows"| node_default_file
node_defaults -->|"inserts values"| node_core
node_process -->|"starts server"| node_server
node_server -->|"accepts connections"| node_client
node_client -.->|"sends commands"| node_handler
node_server -->|"dispatches clients"| node_handler
node_handler -->|"calls operations"| node_core
node_core -->|"reads and writes"| node_map
node_handler -->|"sends replies"| node_client

click node_process "https://github.com/destrivate/ddb/blob/main/src/main.cpp"
click node_config "https://github.com/destrivate/ddb/blob/main/include/config_utility.hpp"
click node_defaults "https://github.com/destrivate/ddb/blob/main/src/main.cpp"
click node_default_file "https://github.com/destrivate/ddb/blob/main/default.txt"
click node_server "https://github.com/destrivate/ddb/blob/main/src/server/server.cpp"
click node_handler "https://github.com/destrivate/ddb/blob/main/src/server/server.cpp"
click node_core "https://github.com/destrivate/ddb/blob/main/src/storage/ddb.cpp"
click node_map "https://github.com/destrivate/ddb/blob/main/src/storage/ddb.hpp"
click node_logger "https://github.com/destrivate/ddb/blob/main/include/logger.hpp"

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_process,node_defaults,node_client toneBlue
class node_server,node_handler toneAmber
class node_core,node_map toneMint
class node_config,node_logger toneRose
class node_default_file toneTeal
```

## Components

### Startup

- [Process startup](https://github.com/destrivate/ddb/blob/main/src/main.cpp): `src/main.cpp`
- [Default loader](https://github.com/destrivate/ddb/blob/main/src/main.cpp): `src/main.cpp`

### TCP Server

- [TCP server](https://github.com/destrivate/ddb/blob/main/src/server/server.cpp): `src/server/server.cpp`
- [Command handler](https://github.com/destrivate/ddb/blob/main/src/server/server.cpp): `src/server/server.cpp`

### Key-Value Storage

- [Key-value operations](https://github.com/destrivate/ddb/blob/main/src/storage/ddb.cpp): `src/storage/ddb.cpp`
- [In-memory map](https://github.com/destrivate/ddb/blob/main/src/storage/ddb.hpp): `src/storage/ddb.hpp`

### Runtime Support

- [Config reader](https://github.com/destrivate/ddb/blob/main/include/config_utility.hpp): `include/config_utility.hpp`
- [Logger](https://github.com/destrivate/ddb/blob/main/include/logger.hpp): `include/logger.hpp`

### Other components

- [Default data file](https://github.com/destrivate/ddb/blob/main/default.txt): `default.txt`
- **TCP client**

## Connections

- Process startup → Config reader: reads settings (evidence: `src/main.cpp`)
- Process startup → Logger: logs port (evidence: `src/main.cpp`)
- Process startup → Default loader: loads defaults (evidence: `src/main.cpp`)
- Default loader → Default data file: reads rows (evidence: `src/main.cpp`)
- Default loader → Key-value operations: inserts values (evidence: `src/main.cpp`)
- Process startup → TCP server: starts server (evidence: `src/main.cpp`)
- TCP server → TCP client: accepts connections (evidence: `src/server/server.cpp`)
- TCP client → Command handler: sends commands
- TCP server → Command handler: dispatches clients (evidence: `src/server/server.cpp`)
- Command handler → Key-value operations: calls operations (evidence: `src/server/server.cpp`)
- Key-value operations → In-memory map: reads and writes (evidence: `src/storage/ddb.cpp`)
- Command handler → TCP client: sends replies (evidence: `src/server/server.cpp`)
