How cruelkratos/prqlite works
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: semantic_analyzer.cpp Semantic Analyzer · executor_engine.cpp Executor Engine · table_manager.cpp Table Manager · disk_manager.cpp Disk Manager
Components 20
Runtime
- Local SQL CLI · Interactive local process accepting SQL.
src/main.cpp
SQL Front End
- Lexer
src/frontend/lexer.cpp - SQL Parser
src/frontend/parser/parser.cpp - SQL AST
src/frontend/parser/AST.cpp - Semantic Analyzer · Validates and binds SQL before execution.
src/frontend/semantic_analyzer.cpp
Catalog & Execution
- Catalog
src/catalog.cpp - Table Model
src/table.cpp - Executor Engine · Turns validated statements into table and row operations.
src/virtual_machine/executor_engine.cpp - Table Manager
src/virtual_machine/table_manager.cpp - Relational Operators
src/virtual_machine/select_operator.cpp
Storage & Recovery
- Disk Manager · Durability boundary for database files.
src/backend/disk_manager.cpp - Buffer Pool
src/backend/buffer_pool.cpp - Page Table
src/backend/page_table.cpp - Transaction Manager
src/transaction/transaction_manager.cpp - WAL Manager
src/recovery/log_manager.cpp - Database Files · Catalog and database state under the data directory.
data/prqlite.db - WAL File
data/.wal.db
Build & Deployment
- CMake Build
CMakeLists.txt - Docker Image · Mounts /data for durable database storage.
Dockerfile - Build CI · Builds the CMake project and Docker image.
.github/workflows/cmake-build.yml
Connections 22
- 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