# eclipsu/minidb architecture

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

- Interactive diagram: https://gitdiagram.com/eclipsu/minidb
- Repository: https://github.com/eclipsu/minidb

## Overview

MiniDB is a file-backed, in-memory database with a SQL prompt. The primary workflow is prompt input → tokenization → parsing into a statement → database execution → formatted result; table operations use a per-table B-Tree, while dot commands manage CSV persistence. The README also documents table listing, save/load, and exit handling. The excerpts establish the prompt orchestration, parsing and execution behavior, and storage mechanics; some executor-to-tree and database-to-storage links are supported by the documented interfaces rather than complete call-site excerpts.

Main entry points: [`src/main.cpp`](https://github.com/eclipsu/minidb/blob/main/src/main.cpp) (Prompt and commands), [`src/executor.cpp`](https://github.com/eclipsu/minidb/blob/main/src/executor.cpp) (Database executor), [`src/btree.h`](https://github.com/eclipsu/minidb/blob/main/src/btree.h) (B-Tree interface), [`src/storage.cpp`](https://github.com/eclipsu/minidb/blob/main/src/storage.cpp) (CSV table storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["SQL interface"]
  node_prompt["Prompt and commands<br/>[main.cpp]"]
  node_tokenizer["SQL tokenizer<br/>[tokenizer.cpp]"]
  node_parser["SQL parser<br/>[parser.cpp]"]
  node_statement["Statement model<br/>[statement.h]"]
end

subgraph group_database["Database execution"]
  node_executor["Database executor<br/>[executor.cpp]"]
  node_tables["Table catalog<br/>[executor.h]"]
  node_query["Query and row operations<br/>[executor.cpp]"]
  node_result["Result formatting<br/>[executor.cpp]"]
end

subgraph group_index["B-Tree index"]
  node_btree_api["B-Tree interface<br/>[btree.h]"]
  node_btree_insert["B-Tree insertion<br/>[btree_insert.cpp]"]
  node_btree_remove["B-Tree deletion<br/>[btree_remove.cpp]"]
  node_btree_core["B-Tree traversal and checks<br/>[btree.cpp]"]
end

subgraph group_persistence["CSV persistence"]
  node_storage["CSV table storage<br/>[storage.cpp]"]
  node_csv_files[("Table CSV files")]
end

node_user(("SQL user"))

node_user -->|"enters commands"| node_prompt
node_prompt -->|"tokenizes SQL"| node_tokenizer
node_prompt -->|"parses tokens"| node_parser
node_parser -->|"builds statement"| node_statement
node_prompt -->|"executes statement"| node_executor
node_executor -->|"consumes statement"| node_statement
node_executor -->|"manages tables"| node_tables
node_executor -->|"dispatches operations"| node_query
node_prompt -->|"formats response"| node_result
node_executor -->|"formats results"| node_result
node_query -->|"uses row index"| node_btree_api
node_btree_api -->|"inserts via"| node_btree_insert
node_btree_api -->|"removes via"| node_btree_remove
node_btree_api -->|"delegates core"| node_btree_core
node_executor -->|"saves and loads"| node_storage
node_storage -->|"reads and writes"| node_csv_files
node_storage -->|"traverses and populates"| node_btree_api
node_prompt -->|"lists tables"| node_tables
node_prompt -->|"routes dot commands"| node_storage
node_prompt -->|"checks exit changes"| node_executor

click node_prompt "https://github.com/eclipsu/minidb/blob/main/src/main.cpp"
click node_tokenizer "https://github.com/eclipsu/minidb/blob/main/src/tokenizer.cpp"
click node_parser "https://github.com/eclipsu/minidb/blob/main/src/parser.cpp"
click node_statement "https://github.com/eclipsu/minidb/blob/main/src/statement.h"
click node_executor "https://github.com/eclipsu/minidb/blob/main/src/executor.cpp"
click node_tables "https://github.com/eclipsu/minidb/blob/main/src/executor.h"
click node_query "https://github.com/eclipsu/minidb/blob/main/src/executor.cpp"
click node_result "https://github.com/eclipsu/minidb/blob/main/src/executor.cpp"
click node_btree_api "https://github.com/eclipsu/minidb/blob/main/src/btree.h"
click node_btree_insert "https://github.com/eclipsu/minidb/blob/main/src/btree_insert.cpp"
click node_btree_remove "https://github.com/eclipsu/minidb/blob/main/src/btree_remove.cpp"
click node_btree_core "https://github.com/eclipsu/minidb/blob/main/src/btree.cpp"
click node_storage "https://github.com/eclipsu/minidb/blob/main/src/storage.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_prompt,node_tokenizer,node_parser,node_statement,node_user toneBlue
class node_executor,node_tables,node_query,node_result toneAmber
class node_btree_api,node_btree_insert,node_btree_remove,node_btree_core toneMint
class node_storage,node_csv_files toneRose
```

## Components

### SQL interface

- [Prompt and commands](https://github.com/eclipsu/minidb/blob/main/src/main.cpp): `src/main.cpp`
- [SQL tokenizer](https://github.com/eclipsu/minidb/blob/main/src/tokenizer.cpp): `src/tokenizer.cpp`
- [SQL parser](https://github.com/eclipsu/minidb/blob/main/src/parser.cpp): `src/parser.cpp`
- [Statement model](https://github.com/eclipsu/minidb/blob/main/src/statement.h): `src/statement.h`

### Database execution

- [Database executor](https://github.com/eclipsu/minidb/blob/main/src/executor.cpp): `src/executor.cpp`
- [Table catalog](https://github.com/eclipsu/minidb/blob/main/src/executor.h): `src/executor.h`
- [Query and row operations](https://github.com/eclipsu/minidb/blob/main/src/executor.cpp): `src/executor.cpp`
- [Result formatting](https://github.com/eclipsu/minidb/blob/main/src/executor.cpp): `src/executor.cpp`

### B-Tree index

- [B-Tree interface](https://github.com/eclipsu/minidb/blob/main/src/btree.h): `src/btree.h`
- [B-Tree insertion](https://github.com/eclipsu/minidb/blob/main/src/btree_insert.cpp): `src/btree_insert.cpp`
- [B-Tree deletion](https://github.com/eclipsu/minidb/blob/main/src/btree_remove.cpp): `src/btree_remove.cpp`
- [B-Tree traversal and checks](https://github.com/eclipsu/minidb/blob/main/src/btree.cpp): `src/btree.cpp`

### CSV persistence

- [CSV table storage](https://github.com/eclipsu/minidb/blob/main/src/storage.cpp): `src/storage.cpp`
- **Table CSV files**

### Other components

- **SQL user**

## Connections

- SQL user → Prompt and commands: enters commands (evidence: `README.md`)
- Prompt and commands → SQL tokenizer: tokenizes SQL (evidence: `src/main.cpp`)
- Prompt and commands → SQL parser: parses tokens (evidence: `src/main.cpp`)
- SQL parser → Statement model: builds statement (evidence: `src/parser.cpp`)
- Prompt and commands → Database executor: executes statement (evidence: `src/main.cpp`)
- Database executor → Statement model: consumes statement
- Database executor → Table catalog: manages tables (evidence: `src/executor.h`)
- Database executor → Query and row operations: dispatches operations (evidence: `src/executor.cpp`)
- Prompt and commands → Result formatting: formats response (evidence: `src/main.cpp`)
- Database executor → Result formatting: formats results (evidence: `src/executor.cpp`)
- Query and row operations → B-Tree interface: uses row index
- B-Tree interface → B-Tree insertion: inserts via (evidence: `src/btree.h`)
- B-Tree interface → B-Tree deletion: removes via (evidence: `src/btree.h`)
- B-Tree interface → B-Tree traversal and checks: delegates core (evidence: `src/btree.h`)
- Database executor → CSV table storage: saves and loads
- CSV table storage → Table CSV files: reads and writes (evidence: `src/storage.cpp`)
- CSV table storage → B-Tree interface: traverses and populates (evidence: `src/storage.cpp`)
- Prompt and commands → Table catalog: lists tables (evidence: `src/main.cpp`)
- Prompt and commands → CSV table storage: routes dot commands (evidence: `src/main.cpp`)
- Prompt and commands → Database executor: checks exit changes (evidence: `src/main.cpp`)
