A simple, educational Database Management System built from scratch in C#. This project demonstrates how a real database engine works internally from SQL parsing to data persistence on disk with multiple ways to interact with it (CLI, REST API, Web UI).
Version 1.0 β Supports
SELECT,INSERT,UPDATE,DELETE,CREATE TABLE,DROP TABLE, andWHEREclause.
| Feature | Description |
|---|---|
| SQL Parser | Tokenizes and parses raw SQL queries into structured objects |
| SQL Execution Engine | Routes parsed queries to the appropriate handler |
| Buffer Pool Manager | In-memory data management with dirty page tracking |
| Disk Manager | Persistent storage using JSON serialization |
| TCP Server | Multi-client TCP server with custom protocol on port 9090 |
| Interactive CLI Client | Console REPL for sending SQL queries to the server |
| REST API | ASP.NET Core Minimal API bridge between HTTP and TCP |
| Web Frontend | Browser-based SQL editor with table rendering |
ββββββββββββββββ HTTP POST /query ββββββββββββββββ
β Frontend β ββββββββββββββββββββββ> β REST API β
β (HTML/JS) β β (ASP.NET) β
ββββββββββββββββ ββββββββ¬ββββββββ
β TCP (custom protocol)
ββββββββββββββββ TCP (custom protocol) β
β CLI Client β βββββββββββββββββββββββββββββββ>β
ββββββββββββββββ βΌ
βββββββββββββββββββββ
β TCP Server β
β ConnectionHandler β
ββββββββββ¬βββββββββββ
β
ββββββΌβββββββ
βSqlParser β β Tokenize & parse SQL
ββββββ¬βββββββ
β SqlParser object
ββββββΌββββββββββββ
β SqlExecution β β Route to handler
ββββββ¬ββββββββββββ
β
ββββββββββΌβββββββββββββββ
β BufferPoolManager β β In-memory operations
β (dirty page tracking)β
ββββββββββ¬βββββββββββββββ
β flush on write
ββββββΌβββββββββββ
β DiskManager β β JSON file I/O
βββββββββββββββββ
β
databases_list/
mydb.json
DBMS_API/
βββ Database/ # π§ Core Database Server
β βββ Program.cs # Entry point β starts TCP server
β βββ ConnectionHandler.cs # TCP server & client connection manager
β βββ SqlParser.cs # SQL query tokenizer & parser
β βββ SqlExecution.cs # Query execution router
β βββ BufferPoolManager.cs # In-memory data + dirty page tracking
β βββ DiskManager.cs # JSON read/write to disk
β βββ Database.csproj # Project file
β
βββ Client/ # π» CLI Client
β βββ Program.cs # Entry point β prompts for DB name
β βββ DbClient.cs # TCP client with REPL loop
β βββ Client.csproj # Project file
β
βββ Api/ # π REST API Bridge
β βββ Program.cs # ASP.NET Minimal API (POST /query)
β βββ DbClientService.cs # TCP client service for API
β βββ Api.csproj # Project file
β
βββ Frontend/ # π¨ Web UI
β βββ index.html # Main page
β βββ style.css # Dark theme styling
β βββ app.js # Frontend logic (fetch + table render)
β
βββ databases_list/ # π Data storage (JSON files)
βββ queries.sql # π Sample SQL queries
βββ presentation.txt # π Project presentation (French)
βββ DBMS.sln # Visual Studio solution file
βββ README.md # This file
- .NET 8.0 SDK or later
git clone <repository-url>
cd DBMS_APIcd Database
dotnet runYou will see:
Starting DBMS Server...
Server Is Listening on: localhost:9090
Open a new terminal:
cd Client
dotnet runEnter a database name when prompted (e.g. testdb), then start typing SQL commands:
testdb >>> CREATE TABLE users (username VARCHAR,age INT,salary FLOAT);
OK: New Table Created !
testdb >>> INSERT INTO users (username,age,salary) VALUES ('hamza',24,100.0);
OK: New Row Has Been Inserted !
testdb >>> SELECT * FROM users;
[
{
"username": "hamza",
"age": 24,
"salary": 100.0
}
]
testdb >>> exitStart the API (in a new terminal, while the server is running):
cd Api
dotnet runThe API will start on http://localhost:5232.
Then open Frontend/index.html in your browser to use the web-based SQL editor.
You can also call the API directly:
curl -X POST http://localhost:5232/query \
-H "Content-Type: application/json" \
-d '{"dbName": "testdb", "query": "SELECT * FROM users;"}'| Command | Syntax | Example |
|---|---|---|
| CREATE TABLE | CREATE TABLE name (col TYPE, ...); |
CREATE TABLE users (username VARCHAR,age INT,salary FLOAT); |
| INSERT INTO | INSERT INTO name (cols) VALUES (vals); |
INSERT INTO users (username,age,salary) VALUES ('hamza',24,100.0); |
| SELECT * | SELECT * FROM name; |
SELECT * FROM users; |
| SELECT columns | SELECT col1,col2 FROM name; |
SELECT username,age FROM users; |
| SELECT WHERE | SELECT * FROM name WHERE condition; |
SELECT * FROM users WHERE age > 20; |
| SELECT WHERE (compound) | ... WHERE cond1 AND/OR cond2; |
SELECT * FROM users WHERE age > 20 AND salary < 1500.0; |
| UPDATE | UPDATE name SET col=val [WHERE ...]; |
UPDATE users SET age = 25 WHERE username = 'hamza'; |
| UPDATE (all rows) | UPDATE name SET col=val; |
UPDATE users SET salary = 2000.0; |
| DELETE | DELETE FROM name [WHERE ...]; |
DELETE FROM users WHERE age < 25; |
| DELETE (all rows) | DELETE FROM name; |
DELETE FROM users; |
| DROP TABLE | DROP TABLE name; |
DROP TABLE users; |
The WHERE clause can be used with SELECT, UPDATE, and DELETE.
| Operator | Meaning |
|---|---|
= |
Equal to |
!= |
Not equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
IS NULL |
Value is null |
IS NOT NULL |
Value is not null |
| Operator | Meaning |
|---|---|
AND |
Both conditions must be true |
OR |
At least one condition must be true |
SELECT * FROM users WHERE age = 23;
SELECT * FROM users WHERE age > 20 AND salary < 1300.0;
SELECT username FROM users WHERE age < 20 OR salary > 1300.0;
UPDATE users SET age = 25 WHERE username = 'hamza';
UPDATE users SET age = 30, salary = 3000.0 WHERE age > 25;
DELETE FROM users WHERE salary < 1000.0;| Type | Description | Example |
|---|---|---|
VARCHAR |
String values (use single quotes) | 'hamza' |
INT |
Integer values | 24 |
FLOAT |
Decimal / floating-point values | 100.0 |
The server and clients communicate using a simple text-based protocol:
Format: key:>value\n
| Message | Direction | Example |
|---|---|---|
| Database connection | Client β Server | db:>testdb\n |
| Connection response | Server β Client | message:>Connected to testdb Successfully !\nis_json:>0\ncon:>1\n |
| SQL query | Client β Server | query:>SELECT * FROM users;\n |
| Query response | Server β Client | messages:>[...]\nis_json:>1\n |
A comprehensive set of sample queries is available in queries.sql, covering:
- Table creation (
CREATE TABLE) - Data insertion (
INSERT INTO) - Basic
SELECTqueries WHEREwith all comparison operators- Compound conditions with
AND/OR
- This is an educational project β not all SQL features are supported.
- Data is persisted as JSON files inside the
databases_list/folder. - Each database is stored as a single
.jsonfile withTables(schema) andRows(data). - The server supports multiple concurrent client connections via
Task.Run.
This project is for educational purposes.