Skip to content

Commit 9cf4c77

Browse files
authored
Merge pull request #2 from rahulapjs/patch
Patch
2 parents 4454eda + 3b871d5 commit 9cf4c77

37 files changed

+5066
-18
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: AskSQLAI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
backend-lint-and-build:
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: ./backend
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
pip install flake8
29+
30+
- name: Lint with flake8
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34+
# exit-zero treats all errors as warnings
35+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36+
37+
frontend-lint-and-build:
38+
runs-on: ubuntu-latest
39+
defaults:
40+
run:
41+
working-directory: ./frontend
42+
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Use Node.js
47+
uses: actions/setup-node@v3
48+
with:
49+
node-version: '18.x'
50+
cache: 'npm'
51+
cache-dependency-path: './frontend/package-lock.json'
52+
53+
- name: Install dependencies
54+
run: npm ci
55+
56+
- name: Build
57+
run: npm run build
58+
59+
- name: Lint
60+
run: npm run lint

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# AskSQL AI
2+
3+
Convert natural language questions into PostgreSQL queries with a heavy-duty, premium AI-powered interface.
4+
5+
## 🚀 Features
6+
7+
- **Intuitive NL to SQL**: Powered by Gemini 2.5 Flash for high accuracy.
8+
- **Midnight Sapphire UI**: Ultra-premium dark theme with advanced glassmorphism.
9+
- **Live Database Connection**: Automatically reflects your current schema.
10+
- **Dynamic Schema Creator**: Create tables with support for **TEXT, INTEGER, FLOAT, TIMESTAMP, and DATE**.
11+
- **Execution Safety**: Strict read-only validation blocks destructive commands.
12+
13+
## 🛠️ Tech Stack
14+
15+
- **Frontend**: React 18, Vite, TypeScript, Custom CSS (Midnight theme).
16+
- **Backend**: FastAPI, PostgreSQL, Google GenAI SDK.
17+
- **Orchestration**: Docker & Docker Compose.
18+
19+
## 📦 Quick Start
20+
21+
1. **API Key**: Get a Gemini API key from [Google AI Studio](https://aistudio.google.com/).
22+
2. **Environment**: Add your keys and DB config to `backend/.env`.
23+
3. **Run**:
24+
```bash
25+
docker-compose up --build
26+
```
27+
28+
Access the app at: `http://localhost:3000`
29+
30+
## 🔒 Security
31+
32+
All generated SQL queries are parsed for restricted keywords (`DROP`, `DELETE`, etc.) before execution to ensure a read-only experience for the AI.

backend/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# AskSQL AI - Backend
2+
3+
FastAPI service handling NL to SQL conversion, schema exploration, and safe query execution.
4+
5+
## 🚀 Key Features
6+
- **GenAI Integration**: Uses Gemini 1.5 Flash with optimized system instructions.
7+
- **SQL Guardrails**: Custom validator blocks non-SELECT statements.
8+
- **Schema Reflection**: Real-time introspection of the `public` schema.
9+
- **Table Creator**: Support for common PostgreSQL types (`INT`, `TEXT`, `REAL`, etc).
10+
11+
## 🛠️ Technical Details
12+
- **Framework**: FastAPI
13+
- **DB Driver**: Psycopg2
14+
- **Validation**: Pydantic v2
15+
- **AI**: Google Generative AI
16+
17+
## 🔧 Local Development
18+
19+
1. **Install**: `pip install -r requirements.txt`
20+
2. **Env**: Set `GEMINI_API_KEY` and DB credentials in `.env`.
21+
3. **Run**: `uvicorn main:app --reload`

backend/app/services/schema_creator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
ALLOWED_TYPES = {
55
"text": "TEXT",
6+
"string": "TEXT",
67
"int": "INTEGER",
8+
"integer": "INTEGER",
9+
"number": "REAL",
710
"float": "REAL",
811
"timestamp": "TIMESTAMP",
12+
"date": "TIMESTAMP",
913
}
1014

1115

docker-compose.yml

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
version: '3.8'
22

33
services:
4-
# backend:
5-
# build:
6-
# context: ./backend
7-
# dockerfile: Dockerfile
8-
# container_name: asksql_backend
9-
# ports:
10-
# - "8000:8000"
11-
# volumes:
12-
# - ./backend:/app
13-
# env_file:
14-
# - ./backend/.env
15-
# environment:
16-
# - DB_HOST=db
17-
# - DB_PORT=5432
18-
# depends_on:
19-
# - db
20-
# networks:
21-
# - asksql_network
4+
backend:
5+
build:
6+
context: ./backend
7+
dockerfile: Dockerfile
8+
container_name: asksql_backend
9+
ports:
10+
- "8000:8000"
11+
volumes:
12+
- ./backend:/app
13+
env_file:
14+
- ./backend/.env
15+
environment:
16+
- DB_HOST=db
17+
- DB_PORT=5432
18+
depends_on:
19+
- db
20+
networks:
21+
- asksql_network
22+
23+
frontend:
24+
build:
25+
context: ./frontend
26+
dockerfile: Dockerfile
27+
container_name: asksql_frontend
28+
ports:
29+
- "3000:80"
30+
environment:
31+
- VITE_API_BASE_URL=http://localhost:8000/api
32+
depends_on:
33+
- backend
34+
networks:
35+
- asksql_network
2236

2337
db:
2438
image: postgres:15-alpine

frontend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=http://localhost:8000/api

frontend/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

frontend/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM node:18-alpine as build
2+
3+
WORKDIR /app
4+
5+
# Copy package files
6+
COPY package*.json ./
7+
8+
# Install dependencies
9+
RUN npm ci
10+
11+
# Copy source code
12+
COPY . .
13+
14+
# Build the application
15+
RUN npm run build
16+
17+
# Production stage with nginx
18+
FROM nginx:alpine
19+
20+
# Copy built assets from build stage
21+
COPY --from=build /app/dist /usr/share/nginx/html
22+
23+
# Copy nginx configuration
24+
COPY nginx.conf /etc/nginx/conf.d/default.conf
25+
26+
EXPOSE 80
27+
28+
CMD ["nginx", "-g", "daemon off;"]

frontend/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# AskSQL AI - Frontend
2+
3+
A high-performance React frontend featuring a premium "Midnight Sapphire" glassmorphism aesthetic.
4+
5+
## 🎨 Design System
6+
- **Midnight Deep**: Dark mode by default for high visual comfort.
7+
- **Glassmorphism**: 25px blur with subtle white borders.
8+
- **Electric Accents**: Vibrant blues and cyans for interactive elements.
9+
- **Typeface**: 'Outfit' for titles, 'JetBrains Mono' for code.
10+
11+
## 🚀 Highlights
12+
- **Schema Explorer**: Visual modal to browse existing tables and columns.
13+
- **Table Architect**: GUI for creating new tables (supports `int`, `text`, `float`, etc).
14+
- **Result Playground**: High-contrast tables and syntax-highlighted SQL view.
15+
- **Centralized API**: Typed service layer for all backend communications.
16+
17+
## 🛠️ Build & Run
18+
1. `npm install`
19+
2. `npm run dev`

frontend/eslint.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
7+
8+
export default defineConfig([
9+
globalIgnores(['dist']),
10+
{
11+
files: ['**/*.{ts,tsx}'],
12+
extends: [
13+
js.configs.recommended,
14+
tseslint.configs.recommended,
15+
reactHooks.configs.flat.recommended,
16+
reactRefresh.configs.vite,
17+
],
18+
languageOptions: {
19+
ecmaVersion: 2020,
20+
globals: globals.browser,
21+
},
22+
},
23+
])

0 commit comments

Comments
 (0)