# cruelkratos/prqlite architecture

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

- Interactive diagram: https://gitdiagram.com/cruelkratos/prqlite
- Repository: https://github.com/cruelkratos/prqlite

## Overview

#### Purpose and entry point
PRQLite is a lightweight, persistent relational database implemented in modern C++. It accepts SQL through a local executable/interactive entry point in `src/main.cpp`, with shared startup declarations in `include/main.hpp`. Build composition is defined by `CMakeLists.txt` and `src/CMakeLists.txt`; `Dockerfile` packages the process with `/data` as persistent database storage.

#### SQL front end
The query pipeline begins with tokenization, recursive-descent parsing, and AST construction:
- `src/frontend/lexer.cpp`
- `src/frontend/parser/parser.cpp`
- `src/frontend/parser/AST.cpp`

Public contracts reside in `include/frontend/lexer.hpp`, `include/frontend/parser/parser.hpp`, and `include/frontend/parser/AST.hpp`. The parser produces the intermediate representation consumed by semantic and execution layers.

#### Semantic boundary
Semantic analysis validates/binds parsed SQL against database metadata before execution:
- `src/frontend/semantic_analyzer.cpp`
- `include/frontend/semantic_analyzer.hpp`
- `include/catalog.hpp`

This stage is the boundary between syntax-level ASTs and catalog-aware executable operations, including schema/type interpretation.

#### Catalog and table metadata
Catalog and table abstractions own database metadata and table-level representation:
- `src/catalog.cpp`
- `src/table.cpp`
- `include/table.hpp`

The checked-in `data/.catalog.db` and `data/prqlite.db` indicate persisted metadata and database state. The catalog is the dependency point used for semantic binding and table-oriented execution.

#### Execution engine and relational operators
The virtual-machine layer turns validated statements into operations over tables and rows:
- `src/virtual_machine/executor_engine.cpp`
- `src/virtual_machine/table_manager.cpp`
- `include/virtual_machine/executor.hpp`

Implemented operator stages include selection, filtering, projection, insertion, deletion, and table/index creation in `src/virtual_machine/select_operator.cpp`, `src/virtual_machine/filter_operator.cpp`, and `src/virtual_machine/create_index.cpp`. `include/virtual_machine/memory_manager.hpp` defines execution-side memory management.

#### Persistent storage subsystem
Storage is page-based, separating logical table access from cached pages and durable files:
- `src/backend/disk_manager.cpp`
- `src/backend/buffer_pool.cpp`
- `src/backend/page_table.cpp`

`include/backend/disk_manager.hpp` mediates database-file I/O; `include/backend/buffer_pool.hpp` caches pages; `src/backend/random_replacer.cpp` supplies page eviction. This is the execution-to-disk durability boundary.

#### Transactions and recovery
Transaction coordination and WAL support protect writes:
- `src/transaction/transaction_manager.cpp`
- `src/recovery/log_manager.cpp`
- `src/recovery/log_record.cpp`

Interfaces in `include/transaction/transaction_manager.hpp`, `include/transaction/transaction_context.hpp`, and `include/recovery/lock_manager.hpp` define transaction state, locking, and logging responsibilities. `data/.wal.db` is the on-disk write-ahead log; WAL cleanup is explicitly still in progress.

#### Runtime and deployment
The system is a native C++ process built with CMake and has no indicated database-service dependency or network protocol. Docker deployment uses a mounted `/data` volume for durable files via `Dockerfile`. CI builds the CMake project and Docker image under `.github/workflows/cmake-build.yml` and `.github/workflows/docker-image.yml`.

Main entry points: [`src/frontend/semantic_analyzer.cpp`](https://github.com/cruelkratos/prqlite/blob/main/src/frontend/semantic_analyzer.cpp) (Semantic Analyzer), [`src/virtual_machine/executor_engine.cpp`](https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/executor_engine.cpp) (Executor Engine), [`src/virtual_machine/table_manager.cpp`](https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/table_manager.cpp) (Table Manager), [`src/backend/disk_manager.cpp`](https://github.com/cruelkratos/prqlite/blob/main/src/backend/disk_manager.cpp) (Disk Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_cli["Local SQL CLI<br/>native entry point<br/>[main.cpp]"]
end

subgraph group_frontend["SQL Front End"]
  node_lexer["Lexer<br/>tokenizer<br/>[lexer.cpp]"]
  node_parser["SQL Parser<br/>recursive-descent parser<br/>[parser.cpp]"]
  node_ast["SQL AST<br/>intermediate representation<br/>[AST.cpp]"]
  node_semantic["Semantic Analyzer<br/>catalog-aware binder"]
end

subgraph group_execution["Catalog &amp; Execution"]
  node_catalog[("Catalog<br/>database metadata<br/>[catalog.cpp]")]
  node_table["Table Model<br/>table representation<br/>[table.cpp]"]
  node_executor["Executor Engine<br/>virtual machine"]
  node_table_manager["Table Manager<br/>execution table access<br/>[table_manager.cpp]"]
  node_operators["Relational Operators<br/>select/filter/projection/write operators"]
end

subgraph group_storage["Storage &amp; Recovery"]
  node_disk_manager["Disk Manager<br/>database file I/O<br/>[disk_manager.cpp]"]
  node_buffer_pool["Buffer Pool<br/>page cache<br/>[buffer_pool.cpp]"]
  node_page_table["Page Table<br/>page mapping<br/>[page_table.cpp]"]
  node_transaction_manager["Transaction Manager<br/>transaction coordinator"]
  node_log_manager["WAL Manager<br/>write-ahead logging<br/>[log_manager.cpp]"]
  node_database_files[("Database Files<br/>persistent data<br/>[prqlite.db]")]
  node_wal_file["WAL File<br/>persistent log<br/>[.wal.db]"]
end

subgraph group_deployment["Build &amp; Deployment"]
  node_cmake["CMake Build<br/>native build definition<br/>[CMakeLists.txt]"]
  node_docker["Docker Image<br/>container packaging"]
  node_ci["Build CI<br/>automation workflow<br/>[cmake-build.yml]"]
end

node_cli -->|"SQL input"| node_lexer
node_lexer -->|"tokens"| node_parser
node_parser -->|"builds"| node_ast
node_ast -->|"binds"| node_semantic
node_semantic -->|"validates against"| node_catalog
node_semantic -->|"validated statement"| node_executor
node_catalog -->|"metadata"| node_table
node_executor -->|"dispatches"| node_operators
node_executor -->|"table operations"| node_table_manager
node_table_manager -->|"accesses"| node_table
node_table_manager -->|"persists tables"| node_disk_manager
node_operators -->|"coordinates writes"| node_transaction_manager
node_transaction_manager -->|"records WAL"| node_log_manager
node_log_manager -->|"appends"| node_wal_file
node_disk_manager -->|"reads and writes pages"| node_buffer_pool
node_buffer_pool -->|"tracks cached pages"| node_page_table
node_disk_manager -->|"durable I/O"| node_database_files
node_cmake -->|"builds"| node_cli
node_cmake -->|"packages"| node_docker
node_docker -.->|"mounts /data"| node_database_files
node_ci -->|"builds"| node_cmake
node_ci -->|"builds image"| node_docker

click node_cli "https://github.com/cruelkratos/prqlite/blob/main/src/main.cpp"
click node_lexer "https://github.com/cruelkratos/prqlite/blob/main/src/frontend/lexer.cpp"
click node_parser "https://github.com/cruelkratos/prqlite/blob/main/src/frontend/parser/parser.cpp"
click node_ast "https://github.com/cruelkratos/prqlite/blob/main/src/frontend/parser/AST.cpp"
click node_semantic "https://github.com/cruelkratos/prqlite/blob/main/src/frontend/semantic_analyzer.cpp"
click node_catalog "https://github.com/cruelkratos/prqlite/blob/main/src/catalog.cpp"
click node_table "https://github.com/cruelkratos/prqlite/blob/main/src/table.cpp"
click node_executor "https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/executor_engine.cpp"
click node_table_manager "https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/table_manager.cpp"
click node_operators "https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/select_operator.cpp"
click node_disk_manager "https://github.com/cruelkratos/prqlite/blob/main/src/backend/disk_manager.cpp"
click node_buffer_pool "https://github.com/cruelkratos/prqlite/blob/main/src/backend/buffer_pool.cpp"
click node_page_table "https://github.com/cruelkratos/prqlite/blob/main/src/backend/page_table.cpp"
click node_transaction_manager "https://github.com/cruelkratos/prqlite/blob/main/src/transaction/transaction_manager.cpp"
click node_log_manager "https://github.com/cruelkratos/prqlite/blob/main/src/recovery/log_manager.cpp"
click node_database_files "https://github.com/cruelkratos/prqlite/blob/main/data/prqlite.db"
click node_wal_file "https://github.com/cruelkratos/prqlite/blob/main/data/.wal.db"
click node_cmake "https://github.com/cruelkratos/prqlite/blob/main/CMakeLists.txt"
click node_docker "https://github.com/cruelkratos/prqlite/blob/main/Dockerfile"
click node_ci "https://github.com/cruelkratos/prqlite/blob/main/.github/workflows/cmake-build.yml"

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 toneBlue
class node_lexer,node_parser,node_ast,node_semantic toneAmber
class node_catalog,node_table,node_executor,node_table_manager,node_operators toneMint
class node_disk_manager,node_buffer_pool,node_page_table,node_transaction_manager,node_log_manager,node_database_files,node_wal_file toneRose
class node_cmake,node_docker,node_ci toneIndigo
```

## Components

### Runtime

- [Local SQL CLI](https://github.com/cruelkratos/prqlite/blob/main/src/main.cpp): native entry point · Interactive local process accepting SQL. · `src/main.cpp`

### SQL Front End

- [Lexer](https://github.com/cruelkratos/prqlite/blob/main/src/frontend/lexer.cpp): tokenizer · `src/frontend/lexer.cpp`
- [SQL Parser](https://github.com/cruelkratos/prqlite/blob/main/src/frontend/parser/parser.cpp): recursive-descent parser · `src/frontend/parser/parser.cpp`
- [SQL AST](https://github.com/cruelkratos/prqlite/blob/main/src/frontend/parser/AST.cpp): intermediate representation · `src/frontend/parser/AST.cpp`
- [Semantic Analyzer](https://github.com/cruelkratos/prqlite/blob/main/src/frontend/semantic_analyzer.cpp): catalog-aware binder · Validates and binds SQL before execution. · `src/frontend/semantic_analyzer.cpp`

### Catalog & Execution

- [Catalog](https://github.com/cruelkratos/prqlite/blob/main/src/catalog.cpp): database metadata · `src/catalog.cpp`
- [Table Model](https://github.com/cruelkratos/prqlite/blob/main/src/table.cpp): table representation · `src/table.cpp`
- [Executor Engine](https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/executor_engine.cpp): virtual machine · Turns validated statements into table and row operations. · `src/virtual_machine/executor_engine.cpp`
- [Table Manager](https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/table_manager.cpp): execution table access · `src/virtual_machine/table_manager.cpp`
- [Relational Operators](https://github.com/cruelkratos/prqlite/blob/main/src/virtual_machine/select_operator.cpp): select/filter/projection/write operators · `src/virtual_machine/select_operator.cpp`

### Storage & Recovery

- [Disk Manager](https://github.com/cruelkratos/prqlite/blob/main/src/backend/disk_manager.cpp): database file I/O · Durability boundary for database files. · `src/backend/disk_manager.cpp`
- [Buffer Pool](https://github.com/cruelkratos/prqlite/blob/main/src/backend/buffer_pool.cpp): page cache · `src/backend/buffer_pool.cpp`
- [Page Table](https://github.com/cruelkratos/prqlite/blob/main/src/backend/page_table.cpp): page mapping · `src/backend/page_table.cpp`
- [Transaction Manager](https://github.com/cruelkratos/prqlite/blob/main/src/transaction/transaction_manager.cpp): transaction coordinator · `src/transaction/transaction_manager.cpp`
- [WAL Manager](https://github.com/cruelkratos/prqlite/blob/main/src/recovery/log_manager.cpp): write-ahead logging · `src/recovery/log_manager.cpp`
- [Database Files](https://github.com/cruelkratos/prqlite/blob/main/data/prqlite.db): persistent data · Catalog and database state under the data directory. · `data/prqlite.db`
- [WAL File](https://github.com/cruelkratos/prqlite/blob/main/data/.wal.db): persistent log · `data/.wal.db`

### Build & Deployment

- [CMake Build](https://github.com/cruelkratos/prqlite/blob/main/CMakeLists.txt): native build definition · `CMakeLists.txt`
- [Docker Image](https://github.com/cruelkratos/prqlite/blob/main/Dockerfile): container packaging · Mounts /data for durable database storage. · `Dockerfile`
- [Build CI](https://github.com/cruelkratos/prqlite/blob/main/.github/workflows/cmake-build.yml): automation workflow · Builds the CMake project and Docker image. · `.github/workflows/cmake-build.yml`

## Connections

- Local SQL CLI → Lexer: SQL input
- Lexer → SQL Parser: tokens
- SQL Parser → SQL AST: builds
- SQL AST → Semantic Analyzer: binds
- Semantic Analyzer → Catalog: validates against
- Semantic Analyzer → Executor Engine: validated statement
- Catalog → Table Model: metadata
- Executor Engine → Relational Operators: dispatches
- Executor Engine → Table Manager: table operations
- Table Manager → Table Model: accesses
- Table Manager → Disk Manager: persists tables
- Relational Operators → Transaction Manager: coordinates writes
- Transaction Manager → WAL Manager: records WAL
- WAL Manager → WAL File: appends
- Disk Manager → Buffer Pool: reads and writes pages
- Buffer Pool → Page Table: tracks cached pages
- Disk Manager → Database Files: durable I/O
- CMake Build → Local SQL CLI: builds
- CMake Build → Docker Image: packages
- Docker Image → Database Files: mounts /data
- Build CI → CMake Build: builds
- Build CI → Docker Image: builds image
