Skip to content

DarianTr/DatabaseProject

Repository files navigation

SQL Coach 2.0

A full-stack, gamified SQL learning platform where users master SQL querying through progressive challenges against a real relational database. Built with Go, React, and PostgreSQL.


Overview

SQL Coach guides learners through increasingly complex SQL concepts — from basic SELECT statements to multi-table JOIN operations — using an interactive code editor with live query execution and instant feedback. Users track their progress across modules, compete on leaderboards, and build real querying skills against a hospital management database.


Tech Stack

Layer Technology
Backend Go 1.20, Fiber v2, JWT Authentication
Frontend React 18, TypeScript, CodeMirror (SQL editor), Tailwind CSS
Database PostgreSQL
Build esbuild, Docker (multi-stage)

Features

  • Interactive SQL Editor — CodeMirror-based editor with syntax highlighting and schema-aware autocompletion
  • Live Query Execution — Run SQL against a real PostgreSQL database and see results instantly
  • Progressive Learning — 3 modules with escalating difficulty (Simple Queries → Simple JOINs → Multi-JOINs)
  • Automatic Validation — Submitted queries are compared against reference solutions in real time
  • Progress Tracking — Per-user attempt history, completion status, and last submitted query
  • Leaderboards — Global rankings by levels completed and per-level rankings by efficiency
  • JWT Authentication — Secure user sessions with token refresh
  • Database Schema Browser — Sidebar showing all tables, columns, and relationships
  • Fully Containerized — Docker setup for both the application and database

Architecture

┌──────────────────────────────────────────────────┐
│                  React Frontend                   │
│  CodeMirror Editor · Result Tables · Leaderboards │
└──────────────────────┬───────────────────────────┘
                       │ REST API
┌──────────────────────▼───────────────────────────┐
│                Go / Fiber Backend                  │
│    Auth (JWT) · Query Execution · Level Mgmt      │
└──────────────────────┬───────────────────────────┘
                       │
┌──────────────────────▼───────────────────────────┐
│                   PostgreSQL                       │
│  Hospital Schema · User Accounts · Progress Data  │
└──────────────────────────────────────────────────┘

Database Schema

The learning domain is a hospital management system with the following relational model:

Stationen ──< Zimmer ──< Patienten
                │
          Stationspersonal ──< Pflegepersonal
                                     │
                                   Arzt >── Behandeln ──< Patienten

Tables: Stationen (wards), Zimmer (rooms), Patienten (patients), Stationspersonal (staff), Pflegepersonal (nursing), Arzt (doctors), Behandeln (treatments)


Project Structure

├── main.go                  # Server entry point & route definitions
├── auth/                    # JWT authentication (login, register, refresh)
├── controllers/             # API handlers (query execution, levels, leaderboards)
├── database/                # PostgreSQL connection, query runner, models
├── models/                  # Shared data structures
├── frontend/                # React/TypeScript application
│   ├── Application.tsx      # Router & entry point
│   └── pages/               # Components (Editor, Leaderboards, Login, etc.)
├── sql/                     # DB init scripts (schema, seed data, levels)
├── views/                   # HTML templates
├── Dockerfile               # Multi-stage app build
└── db.Dockerfile            # PostgreSQL with init scripts

Getting Started

Prerequisites

  • Docker

Run with Docker

# Build and start the database
docker build -f db.Dockerfile -t sqlcoach-db .
docker run -d -p 5432:5432 --name sqlcoach-db sqlcoach-db

# Build and start the application
docker build -t sqlcoach .
docker run -d -p 8080:8080 --link sqlcoach-db sqlcoach

Local Development

# Backend
go run main.go

# Frontend (watch mode)
npm install
npm run dev

The app runs on http://localhost:8080.


API Endpoints

Method Endpoint Description
POST /api/auth/signin User login
POST /api/auth/register User registration
POST /api/auth/refresh Refresh JWT token
GET /api/exec Execute SQL query
POST /api/level Get level details & solution
POST /api/updateUser Record query attempt
GET /api/modules List modules & user progress
GET /api/GLeaderboard Global leaderboard (top 10)
POST /api/LLeaderboard Per-level leaderboard

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages