# yashk2003/blockdb architecture

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

- Interactive diagram: https://gitdiagram.com/yashk2003/blockdb
- Repository: https://github.com/yashk2003/blockdb

## Overview

SimpleRA is an interactive relational-algebra engine for tables and matrices, designed around block-based storage and memory-conscious query processing. Its main workflow reads a command, parses and semantically validates it, then dispatches execution that reads relations and produces results. The graph also preserves documented matrix operations, relational operators, external sorting/grouping, and indexed mutations. Evidence is strongest for the command loop, SEARCH, DELETE, GROUP BY, and storage helpers; several executor implementations are unsampled, so their documented relationships are attributed to the README rather than inferred from names.

Main entry points: [`src/server.cpp`](https://github.com/yashk2003/blockdb/blob/main/src/server.cpp) (Interactive server), [`src/executors/search.cpp`](https://github.com/yashk2003/blockdb/blob/main/src/executors/search.cpp) (Search execution), [`src/bufferManager.cpp`](https://github.com/yashk2003/blockdb/blob/main/src/bufferManager.cpp) (Page buffer), [`src/table.cpp`](https://github.com/yashk2003/blockdb/blob/main/src/table.cpp) (Table relations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Command Processing"]
  node_server["Interactive server<br/>[server.cpp]"]
  node_syntax["Syntax parser"]
  node_semantic["Semantic parser<br/>[semanticParser.cpp]"]
  node_dispatcher["Command dispatcher<br/>[executor.cpp]"]
  node_query_state["Parsed query state<br/>[syntacticParser.h]"]
end

subgraph group_operators["Relational Operators"]
  node_relational_ops["Relational operators"]
  node_groupby["Grouping and aggregates<br/>[groupby.cpp]"]
  node_join["Join processing<br/>[join.cpp]"]
  node_sort["Sort and ordering<br/>[sort.cpp]"]
  node_orderby["Order by<br/>[orderby.cpp]"]
  node_matrix_exec["Matrix commands<br/>[rotate.cpp]"]
end

subgraph group_indexing["Indexed Operations"]
  node_search["Search execution<br/>[search.cpp]"]
  node_btree[("B+ tree index<br/>[BPTree.cpp]")]
  node_btree_search["Index range search<br/>[BPTree_search.cpp]"]
  node_btree_remove["Index removal<br/>[BPTree_remove.cpp]"]
  node_mutations["Insert update delete<br/>[delete.cpp]"]
end

subgraph group_storage["Storage and Matrices"]
  node_catalogue[("Table catalogue<br/>[tableCatalogue.cpp]")]
  node_table[("Table relations<br/>[table.cpp]")]
  node_cursor["Row cursor<br/>[cursor.cpp]"]
  node_buffer["Page buffer<br/>[bufferManager.cpp]"]
  node_page[("Disk pages<br/>[page.cpp]")]
  node_matrix[("Matrix operations<br/>[matrix.cpp]")]
end

node_user(("Command user"))

node_user -->|"enters commands"| node_server
node_server -->|"parses commands"| node_syntax
node_server -->|"validates commands"| node_semantic
node_server -->|"dispatches valid commands"| node_dispatcher
node_syntax -->|"sets query fields"| node_query_state
node_syntax -->|"routes operator syntax"| node_relational_ops
node_search -->|"builds missing index"| node_btree
node_search -->|"runs index search"| node_btree_search
node_btree_search -->|"writes matching row locations"| node_search
node_search -->|"reads matched pages"| node_buffer
node_mutations -->|"finds affected rows"| node_btree_search
node_mutations -->|"removes index keys"| node_btree_remove
node_mutations -->|"updates table pages"| node_buffer
node_buffer -->|"loads and writes"| node_page
node_groupby -->|"sorts and writes results"| node_table
node_join -->|"reads relations and creates result"| node_table
node_sort -->|"sorts relations"| node_table
node_orderby -->|"produces ordered tables"| node_sort
node_matrix_exec -->|"performs matrix operations"| node_matrix
node_matrix -.->|"uses block cache"| node_buffer
node_catalogue -->|"tracks relations"| node_table

click node_server "https://github.com/yashk2003/blockdb/blob/main/src/server.cpp"
click node_syntax "https://github.com/yashk2003/blockdb/blob/main/src/syntacticParser.cpp"
click node_semantic "https://github.com/yashk2003/blockdb/blob/main/src/semanticParser.cpp"
click node_dispatcher "https://github.com/yashk2003/blockdb/blob/main/src/executor.cpp"
click node_query_state "https://github.com/yashk2003/blockdb/blob/main/src/syntacticParser.h"
click node_relational_ops "https://github.com/yashk2003/blockdb/tree/main/src/executors"
click node_groupby "https://github.com/yashk2003/blockdb/blob/main/src/executors/groupby.cpp"
click node_join "https://github.com/yashk2003/blockdb/blob/main/src/executors/join.cpp"
click node_sort "https://github.com/yashk2003/blockdb/blob/main/src/executors/sort.cpp"
click node_orderby "https://github.com/yashk2003/blockdb/blob/main/src/executors/orderby.cpp"
click node_search "https://github.com/yashk2003/blockdb/blob/main/src/executors/search.cpp"
click node_btree "https://github.com/yashk2003/blockdb/blob/main/src/BPTree.cpp"
click node_btree_search "https://github.com/yashk2003/blockdb/blob/main/src/BPTree_search.cpp"
click node_btree_remove "https://github.com/yashk2003/blockdb/blob/main/src/BPTree_remove.cpp"
click node_mutations "https://github.com/yashk2003/blockdb/blob/main/src/executors/delete.cpp"
click node_catalogue "https://github.com/yashk2003/blockdb/blob/main/src/tableCatalogue.cpp"
click node_table "https://github.com/yashk2003/blockdb/blob/main/src/table.cpp"
click node_cursor "https://github.com/yashk2003/blockdb/blob/main/src/cursor.cpp"
click node_buffer "https://github.com/yashk2003/blockdb/blob/main/src/bufferManager.cpp"
click node_page "https://github.com/yashk2003/blockdb/blob/main/src/page.cpp"
click node_matrix "https://github.com/yashk2003/blockdb/blob/main/src/matrix.cpp"
click node_matrix_exec "https://github.com/yashk2003/blockdb/blob/main/src/executors/rotate.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_server,node_syntax,node_semantic,node_dispatcher,node_query_state,node_user toneBlue
class node_relational_ops,node_groupby,node_join,node_sort,node_orderby,node_matrix_exec toneAmber
class node_search,node_btree,node_btree_search,node_btree_remove,node_mutations toneMint
class node_catalogue,node_table,node_cursor,node_buffer,node_page,node_matrix toneRose
```

## Components

### Command Processing

- [Interactive server](https://github.com/yashk2003/blockdb/blob/main/src/server.cpp): `src/server.cpp`
- [Syntax parser](https://github.com/yashk2003/blockdb/blob/main/src/syntacticParser.cpp): `src/syntacticParser.cpp`
- [Semantic parser](https://github.com/yashk2003/blockdb/blob/main/src/semanticParser.cpp): `src/semanticParser.cpp`
- [Command dispatcher](https://github.com/yashk2003/blockdb/blob/main/src/executor.cpp): `src/executor.cpp`
- [Parsed query state](https://github.com/yashk2003/blockdb/blob/main/src/syntacticParser.h): `src/syntacticParser.h`

### Relational Operators

- [Relational operators](https://github.com/yashk2003/blockdb/tree/main/src/executors): `src/executors`
- [Grouping and aggregates](https://github.com/yashk2003/blockdb/blob/main/src/executors/groupby.cpp): `src/executors/groupby.cpp`
- [Join processing](https://github.com/yashk2003/blockdb/blob/main/src/executors/join.cpp): `src/executors/join.cpp`
- [Sort and ordering](https://github.com/yashk2003/blockdb/blob/main/src/executors/sort.cpp): `src/executors/sort.cpp`
- [Order by](https://github.com/yashk2003/blockdb/blob/main/src/executors/orderby.cpp): `src/executors/orderby.cpp`
- [Matrix commands](https://github.com/yashk2003/blockdb/blob/main/src/executors/rotate.cpp): `src/executors/rotate.cpp`

### Indexed Operations

- [Search execution](https://github.com/yashk2003/blockdb/blob/main/src/executors/search.cpp): `src/executors/search.cpp`
- [B+ tree index](https://github.com/yashk2003/blockdb/blob/main/src/BPTree.cpp): `src/BPTree.cpp`
- [Index range search](https://github.com/yashk2003/blockdb/blob/main/src/BPTree_search.cpp): `src/BPTree_search.cpp`
- [Index removal](https://github.com/yashk2003/blockdb/blob/main/src/BPTree_remove.cpp): `src/BPTree_remove.cpp`
- [Insert update delete](https://github.com/yashk2003/blockdb/blob/main/src/executors/delete.cpp): `src/executors/delete.cpp`

### Storage and Matrices

- [Table catalogue](https://github.com/yashk2003/blockdb/blob/main/src/tableCatalogue.cpp): `src/tableCatalogue.cpp`
- [Table relations](https://github.com/yashk2003/blockdb/blob/main/src/table.cpp): `src/table.cpp`
- [Row cursor](https://github.com/yashk2003/blockdb/blob/main/src/cursor.cpp): `src/cursor.cpp`
- [Page buffer](https://github.com/yashk2003/blockdb/blob/main/src/bufferManager.cpp): `src/bufferManager.cpp`
- [Disk pages](https://github.com/yashk2003/blockdb/blob/main/src/page.cpp): `src/page.cpp`
- [Matrix operations](https://github.com/yashk2003/blockdb/blob/main/src/matrix.cpp): `src/matrix.cpp`

### Other components

- **Command user**

## Connections

- Command user → Interactive server: enters commands (evidence: `src/server.cpp`)
- Interactive server → Syntax parser: parses commands (evidence: `src/server.cpp`)
- Interactive server → Semantic parser: validates commands (evidence: `src/server.cpp`)
- Interactive server → Command dispatcher: dispatches valid commands (evidence: `src/server.cpp`)
- Syntax parser → Parsed query state: sets query fields (evidence: `src/syntacticParser.cpp`)
- Syntax parser → Relational operators: routes operator syntax (evidence: `src/syntacticParser.cpp`)
- Search execution → B+ tree index: builds missing index (evidence: `src/executors/search.cpp`)
- Search execution → Index range search: runs index search (evidence: `src/executors/search.cpp`)
- Index range search → Search execution: writes matching row locations (evidence: `src/BPTree_search.cpp`)
- Search execution → Page buffer: reads matched pages (evidence: `src/executors/search.cpp`)
- Insert update delete → Index range search: finds affected rows (evidence: `src/executors/delete.cpp`)
- Insert update delete → Index removal: removes index keys (evidence: `src/executors/delete.cpp`)
- Insert update delete → Page buffer: updates table pages (evidence: `src/executors/delete.cpp`)
- Page buffer → Disk pages: loads and writes (evidence: `src/bufferManager.cpp`)
- Grouping and aggregates → Table relations: sorts and writes results (evidence: `src/executors/groupby.cpp`)
- Join processing → Table relations: reads relations and creates result (evidence: `src/executors/join.cpp`)
- Sort and ordering → Table relations: sorts relations
- Order by → Sort and ordering: produces ordered tables
- Matrix commands → Matrix operations: performs matrix operations
- Matrix operations → Page buffer: uses block cache
- Table catalogue → Table relations: tracks relations
