Skip to content

Commit ce5116d

Browse files
committed
frontend ui and functionality
1 parent f0f708a commit ce5116d

36 files changed

Lines changed: 5337 additions & 18 deletions

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: SearchlyAI
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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# AskSQL AI
2+
3+
Convert your natural language questions into executable SQL queries using Google Gemini AI. Features a modern glass-morphism UI built with React and a robust FastAPI backend.
4+
5+
## 🚀 Features
6+
7+
- **NL to SQL**: Translate complex questions into PostgreSQL queries.
8+
- **Auto Schema Loading**: Automatically fetches your database schema to provide context to the AI.
9+
- **Safe Execution**: Only permits `SELECT` queries to ensure database safety.
10+
- **Schema Management**: Create new tables directly from the UI.
11+
- **Glass-morphism UI**: Beautiful, responsive blue & white theme.
12+
13+
## 🛠️ Tech Stack
14+
15+
- **Backend**: FastAPI, PostgreSQL, google-genai SDK.
16+
- **Frontend**: React (Vite), TypeScript, Custom CSS.
17+
- **Deployment**: Docker, Docker Compose.
18+
- **AI**: Gemini 1.5 Flash.
19+
20+
## 📦 Getting Started
21+
22+
### Prerequisites
23+
24+
- Docker and Docker Compose
25+
- Google Gemini API Key (Get one [here](https://makersuite.google.com/))
26+
27+
### Configuration
28+
29+
1. Create a `.env` file in the `backend/` directory (you can copy `.env.example`):
30+
```bash
31+
GEMINI_API_KEY=your_key_here
32+
DB_HOST=db
33+
DB_NAME=asksql
34+
DB_USER=postgres
35+
DB_PASSWORD=postgres
36+
```
37+
38+
### Running with Docker
39+
40+
```bash
41+
docker-compose up --build
42+
```
43+
44+
- **Frontend**: [http://localhost:3000](http://localhost:3000)
45+
- **Backend API**: [http://localhost:8000](http://localhost:8000)
46+
- **API Docs**: [http://localhost:8000/docs](http://localhost:8000/docs)
47+
48+
## 📁 Project Structure
49+
50+
- `backend/`: FastAPI application.
51+
- `app/api/`: API endpoints (`query`, `schema`).
52+
- `app/services/`: Business logic (SQL generation, execution, validation).
53+
- `app/schemas/`: Pydantic models.
54+
- `frontend/`: React application.
55+
- `src/components/`: Reusable UI components (ResultDisplay, SchemaCreator, etc.).
56+
- `src/index.css`: Core design system & glass-morphism styles.
57+
58+
## 🔒 Security
59+
60+
Matches are restricted to `SELECT` statements. The `sql_validator` service blocks any keywords like `DROP`, `DELETE`, or `UPDATE` during natural language query processing.

backend/README.md

Whitespace-only changes.

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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## React Compiler
11+
12+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13+
14+
## Expanding the ESLint configuration
15+
16+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17+
18+
```js
19+
export default defineConfig([
20+
globalIgnores(['dist']),
21+
{
22+
files: ['**/*.{ts,tsx}'],
23+
extends: [
24+
// Other configs...
25+
26+
// Remove tseslint.configs.recommended and replace with this
27+
tseslint.configs.recommendedTypeChecked,
28+
// Alternatively, use this for stricter rules
29+
tseslint.configs.strictTypeChecked,
30+
// Optionally, add this for stylistic rules
31+
tseslint.configs.stylisticTypeChecked,
32+
33+
// Other configs...
34+
],
35+
languageOptions: {
36+
parserOptions: {
37+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
38+
tsconfigRootDir: import.meta.dirname,
39+
},
40+
// other options...
41+
},
42+
},
43+
])
44+
```
45+
46+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47+
48+
```js
49+
// eslint.config.js
50+
import reactX from 'eslint-plugin-react-x'
51+
import reactDom from 'eslint-plugin-react-dom'
52+
53+
export default defineConfig([
54+
globalIgnores(['dist']),
55+
{
56+
files: ['**/*.{ts,tsx}'],
57+
extends: [
58+
// Other configs...
59+
// Enable lint rules for React
60+
reactX.configs['recommended-typescript'],
61+
// Enable lint rules for React DOM
62+
reactDom.configs.recommended,
63+
],
64+
languageOptions: {
65+
parserOptions: {
66+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
67+
tsconfigRootDir: import.meta.dirname,
68+
},
69+
// other options...
70+
},
71+
},
72+
])
73+
```

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+
])

frontend/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta name="description" content="Convert natural language questions to SQL queries using AI" />
8+
<title>AskSQL AI - Natural Language to SQL</title>
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="/src/main.tsx"></script>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)