Skip to content

About

A browser-based learning platform for SQL and relational database concepts featuring SQL execution, relational algebra, ER modeling, and data generation tools.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Repository files navigation

QueryCraft: Master SQL. Understand the theory.

QueryCraft

One workspace for SQL, relational algebra, tuple calculus and ER diagrams. Write a query, see the theory behind it, and move between them without leaving the page.

Next.js React TypeScript Tailwind CSS SQLite WASM Tests

Features · Screenshots · Getting started · How it works · Project layout


Why QueryCraft

Database courses teach the same ideas in four different notations: SQL, relational algebra, tuple relational calculus and ER diagrams. Most tools cover only one of them, and most need a server or an account.

QueryCraft puts all four in one browser app, runs on the same sample data, and lets you translate between them.

  • Nothing to install or sign up for. SQL runs in your browser through SQLite compiled to WebAssembly. There is no database server and no account.
  • Theory and practice side by side. An algebra expression shows its evaluation tree and step results, then converts to SQL. A calculus expression converts to SQL and runs against the same tables.
  • Your work stays yours. Queries, history and diagrams are saved in your browser's localStorage and never leave your machine.
  • Built for practice. Bundled datasets, a table generator and a searchable reference mean you can start learning in seconds.

Features

SQL Sandbox In-browser SQL editor with syntax highlighting and autocomplete, a schema browser, statement-level results, query history, CSV export and SQL file import. Covers DDL, DML, joins, transactions, users and privileges, stored routines, triggers and cursors, with a MySQL compatibility layer on top of SQLite.
Relational Algebra Expression editor with a symbol palette (σ π ρ γ τ, set operations and every join type). Shows a parsed expression tree, intermediate results for each step, and a translation to SQL.
Tuple Relational Calculus Write { <t.name, t.gpa> | students(t) ∧ t.gpa > 3.5 } style queries, convert them to SQL and run them against your tables.
ER Diagram Builder Drag-and-drop canvas with entities, weak entities, relationships and key, multivalued, derived and composite attributes. Ships with University, Banking and Credentia presets, exports to PNG and converts the diagram to relational tables.
Table Generator Define tables and columns, and QueryCraft picks realistic Faker-based sample data from the column name. Handles foreign keys across tables and outputs ready-to-run CREATE and INSERT SQL.
Learn Searchable SQL and DBMS reference, from DDL and joins to transactions, DCL, routines and relational algebra, with runnable examples.
Themes Multiple editor and UI themes, dark and light, including Tokyo Night, Catppuccin Mocha, Nord and One Dark Pro.

Screenshots

SQL Sandbox running a join query on the university dataset
SQL Sandbox. Run queries against bundled datasets and export results.
Relational algebra workspace showing a step-by-step evaluation
Relational Algebra. Evaluate step by step, view the tree, convert to SQL.
Tuple relational calculus workspace
Tuple Calculus. Write calculus, get SQL and results.
ER diagram builder showing the University preset
ER Builder. Draw the model, then convert it to tables.
Table generator producing CREATE and INSERT statements
Table Generator. Realistic sample data as ready-to-run SQL.
Learn page with searchable SQL reference cards
Learn. A searchable SQL and DBMS reference.

All screenshots are taken from the running app using the bundled university dataset.

Getting started

Prerequisites: Node.js 22.13+ (22.x), 24.x or 26+, and npm.

git clone https://github.com/Cosmos-0118/QueryCraft.git
cd QueryCraft
npm install
npm run dev

Open http://localhost:3000. No environment variables are needed.

npm install also copies the sql.js WebAssembly runtime into public/ through the postinstall script.

Scripts

Command What it does
npm run dev Start the development server
npm run build Create a production build
npm run start Serve the production build
npm run lint Run ESLint with zero warnings allowed
npm run typecheck Type-check without emitting files
npm run format Format the repository with Prettier
npm run test Run the Vitest suite once
npm run test:watch Run Vitest in watch mode
npm run sync:sql-wasm Re-copy the sql.js WASM runtime to public/

How it works

flowchart LR
    SQL[SQL Sandbox] --> E[SqlExecutor<br/>sql.js · SQLite WASM]
    ALG[Relational Algebra] -->|translate to SQL| E
    TRC[Tuple Calculus] -->|translate to SQL| E
    ER[ER Builder] -->|convert to tables| SQL
    GEN[Table Generator] -->|CREATE + INSERT| SQL
    SEED[(seed/datasets)] -->|/api/datasets| E
    E --> UI[Results, trees, history]
Loading
  • Execution. SqlExecutor wraps sql.js. A translation layer rewrites MySQL syntax to SQLite, and emulates admin commands such as SHOW and DESCRIBE, privileges, procedures, triggers and cursors. See MySQL compatibility limitations for the cases it cannot match.
  • Seed data. Bundled datasets in seed/datasets (banking, credentia, university) are served by GET /api/datasets and loaded into the engine on start.
  • State. Zustand stores, persisted to localStorage. Nothing is sent to a server.
  • Diagrams. The ER canvas is built on @xyflow/react, with PNG export through html-to-image.

Tech stack

Area Tools
Framework Next.js (App Router, Turbopack), React 19, TypeScript
SQL engine sql.js (SQLite compiled to WebAssembly)
Editor CodeMirror 6 with @codemirror/lang-sql
State Zustand
Styling Tailwind CSS v4, Framer Motion, Lucide icons
Data Faker for sample data, Zod for validation
Testing Vitest

Routes

Route Page
/ Landing page
/learn SQL and DBMS reference
/sandbox, /sandbox/history SQL Sandbox and its query history
/algebra, /algebra/history Relational algebra and its history
/tuple-calculus, /tuple-calculus/history Tuple calculus and its history
/er-builder ER diagram builder
/generator Table generator
/our-team, /privacy, /terms About and policy pages
GET /api/datasets Seed datasets from seed/datasets

Project layout

src/
  app/            Routes (landing page, dashboard workspaces, API)
  features/       sandbox, algebra, tuple-calculus, er-builder, generator, our-team
  shared/         SQL engine, UI components, storage helpers
  styles/         Global styles and theme tokens
seed/datasets/    Bundled sample databases (JSON)
tests/            Vitest suites (SQL executor, PL/SQL runtime, app helpers)
docs/             Documentation and README images
scripts/          Build-time helpers (sql.js WASM sync)

Testing

npm run test

The suite covers the SQL executor (DDL, DML, DCL, transactions, procedures, triggers, cursors and MySQL compatibility), statement splitting, the PL/SQL runtime, the data generator's column hinting and session persistence. See tests/README.md for the folder layout.

Note

TypeScript stays on 6.0.x because the ESLint TypeScript parser needs a version below 6.1, and ESLint stays on 9.x because Next's React, accessibility and import plugins do not yet support ESLint 10.

About

A browser-based learning platform for SQL and relational database concepts featuring SQL execution, relational algebra, ER modeling, and data generation tools.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages