Skip to content

aravii0/sqlcoder-text-to-sql

Repository files navigation

Perfect — here’s a complete, realistic README.md for your TechCorp Database NLP Project, written like a professional open-source or portfolio project explanation. It gives a clear scenario, database schema overview, project explanation, and a detailed step-by-step setup guide that actually works when followed.


🏢 TechCorp Text-to-SQL (NLP to Database Query)

📖 Overview

TechCorp is a fictional mid-sized IT company that manages multiple departments, employees, projects, and attendance data. This project demonstrates how users can query a company database using natural language (NLP) — for example:

“Show all employees in the Engineering department” “List all projects managed by the Finance department” “Who has the highest salary at TechCorp?”

The system automatically converts these plain-English questions into SQL queries, executes them on the TechCorp database, and displays structured results.

It combines:

  • 🧠 Natural Language Understanding (NLP)
  • 💾 SQLite database
  • ⚙️ FastAPI backend
  • 💻 React frontend
  • 🤖 AI model (SQLCoder or LLM API)

🧩 Scenario: TechCorp Organization Structure

TechCorp manages employee and departmental data as part of its internal HR and project tracking system. Here’s how the database reflects real operations:

Table Description
departments List of all company departments (HR, Engineering, Finance, etc.)
employees Employee details like name, salary, department, and join date
projects Projects managed by various departments
attendance Daily attendance logs for employees

🔹 Example Use-Cases

  • HR queries: “List all employees who joined after 2023.”
  • Project manager queries: “Show all projects handled by the Engineering department.”
  • Finance queries: “Find the average salary per department.”
  • Admin queries: “How many employees were present on 2025-11-08?”

🧱 Database Schema

-- departments table
CREATE TABLE departments (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL
);

-- employees table
CREATE TABLE employees (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    age INTEGER,
    department_id INTEGER,
    salary REAL,
    date_joined TEXT,
    FOREIGN KEY (department_id) REFERENCES departments(id)
);

-- projects table
CREATE TABLE projects (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    department_id INTEGER,
    start_date TEXT,
    end_date TEXT,
    FOREIGN KEY (department_id) REFERENCES departments(id)
);

-- attendance table
CREATE TABLE attendance (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    employee_id INTEGER,
    date TEXT,
    status TEXT,
    FOREIGN KEY (employee_id) REFERENCES employees(id)
);

🧠 Example Data (Inserted via init_db.py)

Table Example Entries
departments Engineering, HR, Finance, Marketing
employees Alice (Engineering, ₹70k), Bob (Finance, ₹60k), Carol (HR, ₹55k)
projects AI Chatbot, Payroll System, Recruitment Tracker
attendance Alice – Present on 2025-11-08

⚙️ Project Setup Guide

1️⃣ Clone the Repository

git clone https://github.com/yourusername/techcorp-text-to-sql.git
cd techcorp-text-to-sql

2️⃣ Setup Virtual Environment

python -m venv venv
.\venv\Scripts\Activate.ps1
      # On Windows
# or
source venv/bin/activate    # On Linux/Mac

3️⃣ Install Backend Dependencies

cd backend
pip install -r requirements.txt

📦 Typical dependencies:

fastapi
uvicorn
sqlite3
sqlalchemy
python-dotenv

4️⃣ Create and Initialize the Database

Run both scripts to generate and populate the SQLite database:

python createdb.py
python init_db.py

This will create a file named techcorp.db (or init.db) inside the backend folder.

✅ After running, you can verify:

sqlite3 techcorp.db
.tables
SELECT * FROM employees LIMIT 5;

5️⃣ Start the Backend Server

uvicorn main:app --reload

Backend runs on http://127.0.0.1:8000


6️⃣ Setup the Frontend

cd ../frontend
npm install
npm run dev

Frontend runs at http://localhost:5173


7️⃣ Using the App

  • Type a natural language question in the input box (e.g., “Show all employees in HR.”)
  • The backend converts it to SQL using the model.
  • The result table is displayed instantly.

💡 Example Questions

Category Example Query
Employees “Show all employees in the Engineering department.”
Projects “List all projects handled by the Finance department.”
Salary “Who earns the highest salary?”
Attendance “How many employees were present on 2025-11-08?”
HR “Find employees who joined after 2023.”

🧠 Tech Stack

Component Technology
Backend FastAPI, SQLite
Frontend React, Tailwind
NLP Model SQLCoder or custom LLM
ORM SQLAlchemy
API Server Uvicorn

🚀 Future Enhancements

  • Add employee performance data.
  • Integrate authentication and roles.
  • Use OpenAI GPT-based SQL translation.
  • Add chart visualization (PowerBI-style summary).

👨‍💻 Author

Aravind Kumar Data Engineering Enthusiast | Python Developer | TechCorp Demo Creator

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published