Natural Language → SQL → PostgreSQL → Results
This project enables users to search for mobile phones and laptops using natural language, powered by an LLM (Gemini or LLaMA3 via Ollama). The system converts the query into secure SQL, executes it on a PostgreSQL database, and displays results via a Streamlit UI.
- ✨ LLM-based SQL generation (
SELECTonly) - 🛒 Product search: mobiles & laptops
 - 🔐 Safe query validation & execution
 - 🧱 Modular architecture (LLM, DB API, UI)
 - 🗃️ PostgreSQL backend with real product data
 - 🔁 Switchable LLM backend (Gemini / Ollama)
 
User 🔁 Streamlit UI 
        │
        ▼
Prompt 🔁 LLM Service (FastAPI)
        │
        ▼
     SQL Query 🔁 DB Service (Express + pg)
        │
        ▼
   Result Table 📦 PostgreSQL| Layer | Technology | 
|---|---|
| 🧠 LLM | Gemini API / Ollama (LLaMA3) | 
| 🧮 DB Engine | PostgreSQL | 
| 🧪 Query API | Node.js + Express.js + pg | 
| ⚡ LLM Backend | Python + FastAPI + LangChain | 
| 🌐 UI Frontend | Python + Streamlit | 
project-root/
│
├── llm-service/           # Natural language → SQL
│   ├── main.py
│   ├── llm/sql_query_generator.py
│   ├── api/generate_sql.py
│   └── .env
│
├── server/                # PostgreSQL query runner
│   ├── index.js
│   ├── routes/runSql.js
│   ├── db/pool.js
│   └── utils/validateSql.js
│
├── llm-ui/                # Streamlit frontend
│   ├── main.py
│   ├── api/query_llm.py
│   ├── api/run_query.py
│   └── .env
│
├── .gitignore
└── README.mdgit clone https://github.com/your-username/llm-ecommerce-search.git
cd llm-ecommerce-searchllm-service/.env
LLM_PORT=4001
GEMINI_API_KEY="your-gemini-or-ollama-key"server/.env
PORT=4000
PGHOST=localhost
PGUSER=postgres
PGPASSWORD=yourpassword
PGDATABASE=yourdb
PGPORT=5432llm-ui/.env
LLM_API_URL=http://localhost:4001/generate-sql
DB_API_URL=http://localhost:4000/run-sql# LLM Backend
cd llm-service
pip install -r requirements.txt
# DB Service
cd ../server
npm install
# Frontend
cd ../llm-ui
pip install -r requirements.txt# LLM Service
cd llm-service
uvicorn main:app --reload --port 4001
# DB Service
cd ../server
node index.js
# Streamlit UI
cd ../llm-ui
streamlit run main.py“Show me laptops from HP or Dell under ₹60,000 with at least 16GB RAM”
🧠 → LLM generates:
SELECT * FROM laptops 
WHERE brand ILIKE 'HP' OR brand ILIKE 'Dell' 
  AND price < 60000 AND ram >= 16;📦 → Results displayed in a table
- ✅ Only safe SELECT queries are allowed
 - 🚫 
INSERT,UPDATE,DELETE,DROPare blocked - ✅ Queries validated before execution
 - 🔐 Sensitive configs kept in 
.env 
- 🗣️ Voice-based product search
 - 🖼️ Image similarity search
 - 🎯 Personalized product recommendations
 - 🧾 Query history and feedback loop
 - 🧠 Context-aware multi-turn chat