# comictor2ro/nexdb architecture

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

- Interactive diagram: https://gitdiagram.com/comictor2ro/nexdb
- Repository: https://github.com/comictor2ro/nexdb

## Overview

NexDB is a lightweight relational database with SQL access through a TCP server and an interactive GUI. The main workflow is a client submitting SQL, which is tokenized, parsed into a statement, and handled by the engine; table data and catalog metadata are persisted, with WAL recovery for interrupted changes. The README also describes authentication, rate limiting, indexing, and GUI browsing/results. Some internal call paths are not shown in the excerpts, so those links are marked unverified rather than inferred as certain.

Main entry points: [`Engine/Engine.cpp`](https://github.com/comictor2ro/nexdb/blob/main/Engine/Engine.cpp) (Query Engine), [`Storage/PageManager/PageManager.cpp`](https://github.com/comictor2ro/nexdb/blob/main/Storage/PageManager/PageManager.cpp) (Page Manager), [`Table/Table.cpp`](https://github.com/comictor2ro/nexdb/blob/main/Table/Table.cpp) (Table Operations), [`Frontend/Parser/Parser.cpp`](https://github.com/comictor2ro/nexdb/blob/main/Frontend/Parser/Parser.cpp) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sql["SQL Processing"]
  node_lexer["Lexer<br/>[Lexer.cpp]"]
  node_parser["Parser<br/>[Parser.cpp]"]
  node_ast["SQL Statements"]
end

subgraph group_engine["Database Engine"]
  node_engine["Query Engine<br/>[Engine.cpp]"]
  node_catalog[("Catalog<br/>[Catalog.cpp]")]
  node_table["Table Operations<br/>[Table.cpp]"]
  node_index["B+ Tree Index<br/>[BPlusTree.cpp]"]
end

subgraph group_storage["Persistence"]
  node_storagefile[("Storage Files<br/>[StorageFile.cpp]")]
  node_pages["Page Manager<br/>[PageManager.cpp]"]
  node_page["Page Data<br/>[Page.cpp]"]
  node_cache["LRU Cache<br/>[LRUCache.cpp]"]
  node_wal[("Write-Ahead Log<br/>[WALManager.cpp]")]
end

subgraph group_access["Client Interfaces"]
  node_network["TCP Server<br/>[NetworkServer.cpp]"]
  node_gui["Interactive GUI<br/>[GUI.cpp]"]
  node_config["Configuration<br/>[Config.cpp]"]
end

node_client(("SQL Client"))

node_client -->|"sends SQL"| node_network
node_network -->|"submits queries"| node_engine
node_gui -->|"runs queries"| node_engine
node_engine -.->|"tokenizes SQL"| node_lexer
node_lexer -->|"provides tokens"| node_parser
node_parser -->|"builds statements"| node_ast
node_engine -.->|"parses queries"| node_parser
node_engine -.->|"executes statements"| node_ast
node_engine -.->|"uses metadata"| node_catalog
node_engine -.->|"runs table operations"| node_table
node_table -.->|"uses index"| node_index
node_engine -.->|"coordinates recovery"| node_wal
node_wal -->|"replays statements"| node_engine
node_table -.->|"uses pages"| node_pages
node_pages -.->|"reads and writes"| node_storagefile
node_pages -.->|"manages pages"| node_page
node_pages -.->|"caches pages"| node_cache
node_gui -.->|"loads settings"| node_config

click node_lexer "https://github.com/comictor2ro/nexdb/blob/main/Frontend/Lexer/Lexer.cpp"
click node_parser "https://github.com/comictor2ro/nexdb/blob/main/Frontend/Parser/Parser.cpp"
click node_ast "https://github.com/comictor2ro/nexdb/tree/main/AST"
click node_engine "https://github.com/comictor2ro/nexdb/blob/main/Engine/Engine.cpp"
click node_catalog "https://github.com/comictor2ro/nexdb/blob/main/Catalog/Catalog.cpp"
click node_table "https://github.com/comictor2ro/nexdb/blob/main/Table/Table.cpp"
click node_index "https://github.com/comictor2ro/nexdb/blob/main/Indexing/BPlusTree/BPlusTree.cpp"
click node_network "https://github.com/comictor2ro/nexdb/blob/main/Networking/NetworkServer.cpp"
click node_gui "https://github.com/comictor2ro/nexdb/blob/main/GUI/GUI.cpp"
click node_config "https://github.com/comictor2ro/nexdb/blob/main/Config/Config.cpp"
click node_storagefile "https://github.com/comictor2ro/nexdb/blob/main/Storage/StorageFile/StorageFile.cpp"
click node_pages "https://github.com/comictor2ro/nexdb/blob/main/Storage/PageManager/PageManager.cpp"
click node_page "https://github.com/comictor2ro/nexdb/blob/main/Storage/Page/Page.cpp"
click node_cache "https://github.com/comictor2ro/nexdb/blob/main/Storage/LRUCache/LRUCache.cpp"
click node_wal "https://github.com/comictor2ro/nexdb/blob/main/WALManager/WALManager.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_lexer,node_parser,node_ast,node_client toneBlue
class node_engine,node_catalog,node_table,node_index toneAmber
class node_storagefile,node_pages,node_page,node_cache,node_wal toneMint
class node_network,node_gui,node_config toneRose
```

## Components

### SQL Processing

- [Lexer](https://github.com/comictor2ro/nexdb/blob/main/Frontend/Lexer/Lexer.cpp): `Frontend/Lexer/Lexer.cpp`
- [Parser](https://github.com/comictor2ro/nexdb/blob/main/Frontend/Parser/Parser.cpp): `Frontend/Parser/Parser.cpp`
- [SQL Statements](https://github.com/comictor2ro/nexdb/tree/main/AST): `AST`

### Database Engine

- [Query Engine](https://github.com/comictor2ro/nexdb/blob/main/Engine/Engine.cpp): `Engine/Engine.cpp`
- [Catalog](https://github.com/comictor2ro/nexdb/blob/main/Catalog/Catalog.cpp): `Catalog/Catalog.cpp`
- [Table Operations](https://github.com/comictor2ro/nexdb/blob/main/Table/Table.cpp): `Table/Table.cpp`
- [B+ Tree Index](https://github.com/comictor2ro/nexdb/blob/main/Indexing/BPlusTree/BPlusTree.cpp): `Indexing/BPlusTree/BPlusTree.cpp`

### Persistence

- [Storage Files](https://github.com/comictor2ro/nexdb/blob/main/Storage/StorageFile/StorageFile.cpp): `Storage/StorageFile/StorageFile.cpp`
- [Page Manager](https://github.com/comictor2ro/nexdb/blob/main/Storage/PageManager/PageManager.cpp): `Storage/PageManager/PageManager.cpp`
- [Page Data](https://github.com/comictor2ro/nexdb/blob/main/Storage/Page/Page.cpp): `Storage/Page/Page.cpp`
- [LRU Cache](https://github.com/comictor2ro/nexdb/blob/main/Storage/LRUCache/LRUCache.cpp): `Storage/LRUCache/LRUCache.cpp`
- [Write-Ahead Log](https://github.com/comictor2ro/nexdb/blob/main/WALManager/WALManager.cpp): `WALManager/WALManager.cpp`

### Client Interfaces

- [TCP Server](https://github.com/comictor2ro/nexdb/blob/main/Networking/NetworkServer.cpp): `Networking/NetworkServer.cpp`
- [Interactive GUI](https://github.com/comictor2ro/nexdb/blob/main/GUI/GUI.cpp): `GUI/GUI.cpp`
- [Configuration](https://github.com/comictor2ro/nexdb/blob/main/Config/Config.cpp): `Config/Config.cpp`

### Other components

- **SQL Client**

## Connections

- SQL Client → TCP Server: sends SQL
- TCP Server → Query Engine: submits queries
- Interactive GUI → Query Engine: runs queries
- Query Engine → Lexer: tokenizes SQL
- Lexer → Parser: provides tokens
- Parser → SQL Statements: builds statements
- Query Engine → Parser: parses queries
- Query Engine → SQL Statements: executes statements
- Query Engine → Catalog: uses metadata
- Query Engine → Table Operations: runs table operations
- Table Operations → B+ Tree Index: uses index
- Query Engine → Write-Ahead Log: coordinates recovery
- Write-Ahead Log → Query Engine: replays statements (evidence: `WALManager/WALManager.cpp`)
- Table Operations → Page Manager: uses pages
- Page Manager → Storage Files: reads and writes
- Page Manager → Page Data: manages pages
- Page Manager → LRU Cache: caches pages
- Interactive GUI → Configuration: loads settings
