Skip to content

Commit 7467c99

Browse files
committed
completed
1 parent cd28b7f commit 7467c99

File tree

8 files changed

+253
-22
lines changed

8 files changed

+253
-22
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: RAG Application CI
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# AI Document RAG System
2+
3+
A complete full-stack application for securely chatting with PDF documents using Retrieval-Augmented Generation (RAG) and Google's Gemini API.
4+
5+
## Project Architecture
6+
7+
- **Frontend**: React + TypeScript + Vite. A polished, single-page application with a modern SaaS CSS design.
8+
- **Backend**: FastAPI (Python). Handles embedding generation, vector search, and LLM interaction.
9+
- **Infrastructure**: Docker & Docker Compose for easy deployment.
10+
11+
## Quick Start (Docker)
12+
13+
The easiest way to run the entire system is with Docker Compose.
14+
15+
1. **Prerequisites**: Ensure Docker and Docker Compose are installed.
16+
2. **Run**:
17+
```bash
18+
docker-compose up --build
19+
```
20+
3. **Access**:
21+
- Frontend: `http://localhost:5173`
22+
- Backend API: `http://localhost:8000`
23+
24+
## Manual Development Setup
25+
26+
### Backend
27+
Navigate to `backend/` and follow the `README.md` to start the FastAPI server on port 8000.
28+
29+
### Frontend
30+
Navigate to `frontend/` and follow the `README.md` to start the Vite dev server on port 5173.
31+
32+
Ensure the backend is running before using the frontend.
33+
34+
## Features
35+
36+
- **Private by Design**: Your API key stays in your browser memory and is sent directly to the backend for that session only.
37+
- **Session Isolation**: Each user session gets its own vector store.
38+
- **Responsive Design**: Works on desktop and mobile.
39+
- **Type Safety**: Full TypeScript support in frontend, Pydantic validation in backend.

backend/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Copy requirements first for caching
11+
COPY requirements.txt .
12+
RUN pip install --no-cache-dir -r requirements.txt
13+
14+
# Copy application code
15+
COPY . .
16+
17+
# Expose port
18+
EXPOSE 8000
19+
20+
# Run the application
21+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

backend/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RAG Backend API
2+
3+
This is the FastAPI backend for the Document RAG (Retrieval-Augmented Generation) application. It handles file processing, embeddings, vector storage, and chat interactions using Google's Gemini API.
4+
5+
## Features
6+
7+
- **Document Processing**: Upload and parse PDF documents.
8+
- **RAG Implementation**: Uses vector store to retrieve relevant context for queries.
9+
- **Session Management**: Isolated vector stores per session.
10+
- **API Key Security**: Validates Gemini API keys without storing them persistently.
11+
12+
## Setup
13+
14+
1. **Install Python 3.11+**
15+
2. **Create Virtual Environment**:
16+
```bash
17+
python -m venv venv
18+
source venv/bin/activate # Windows: venv\Scripts\activate
19+
```
20+
3. **Install Dependencies**:
21+
```bash
22+
pip install -r requirements.txt
23+
```
24+
25+
## Running
26+
27+
Start the server:
28+
```bash
29+
uvicorn app.main:app --reload
30+
```
31+
The API will be available at `http://localhost:8000`.
32+
Docs available at `http://localhost:8000/docs`.
33+
34+
## API Endpoints
35+
36+
- `POST /api/validate-key`: Validate Gemini API key.
37+
- `POST /api/upload`: Upload PDF for processing.
38+
- `POST /api/ask`: Ask a question about the uploaded document.
39+
- `DELETE /api/clear`: Clear session data.

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3.8'
2+
3+
services:
4+
backend:
5+
build: ./backend
6+
container_name: rag-backend
7+
ports:
8+
- "8000:8000"
9+
environment:
10+
- PYTHONUNBUFFERED=1
11+
networks:
12+
- app-network
13+
14+
frontend:
15+
build: ./frontend
16+
container_name: rag-frontend
17+
ports:
18+
- "5173:80"
19+
depends_on:
20+
- backend
21+
networks:
22+
- app-network
23+
24+
networks:
25+
app-network:
26+
driver: bridge

frontend/Dockerfile

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

frontend/README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
# Document RAG Frontend
1+
# RAG Frontend
22

3-
A React + Vite + TypeScript frontend for the Document RAG system.
3+
A modern, responsive React application for interacting with the Document RAG system. It features a professional SaaS-like UI with a focus on usability and aesthetics.
4+
5+
## Features
6+
7+
- **Modern UI**: Clean, card-based layout with glassmorphism effects.
8+
- **Interactive Experience**: Smooth transitions, drop-zone for files, and chat interface.
9+
- **Secure**: API keys are held in memory only and never persisted.
10+
- **Header Navigation**: Quick access to API status and session reset.
11+
12+
## Tech Stack
13+
14+
- React (Vite)
15+
- TypeScript
16+
- Vanilla CSS (Custom Design System)
417

518
## Setup
619

7-
1. Navigate to the frontend directory:
8-
```bash
9-
cd frontend
10-
```
11-
2. Install dependencies:
20+
1. **Install Node.js 18+**
21+
2. **Install Dependencies**:
1222
```bash
1323
npm install
1424
```
15-
3. Start the development server:
16-
```bash
17-
npm run dev
18-
```
1925

20-
## Features
26+
## Running
2127

22-
- **Session Management**: Automatically generates unique sessions, persists them in sessionStorage, and ensures backend cleanup on reload/reset.
23-
- **Secure Key Handling**: Gemini API Key is stored in memory only and cleared on reload.
24-
- **Styling**: Custom CSS (no frameworks) with a premium dark/glassmorphism design.
25-
- **Type Safety**: Full TypeScript implementation.
26-
- **API Integration**: Connects to `http://localhost:8000/api`.
28+
Start the development server:
29+
```bash
30+
npm run dev
31+
```
32+
Access the app at `http://localhost:5173`.
2733

28-
## Tech Stack
34+
## Build
2935

30-
- React
31-
- Vite
32-
- TypeScript
33-
- Vanilla CSS
36+
Create production build:
37+
```bash
38+
npm run build
39+
```
40+
The output will be in the `dist` directory.

frontend/nginx.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
root /usr/share/nginx/html;
6+
index index.html index.htm;
7+
try_files $uri $uri/ /index.html;
8+
}
9+
10+
# Proxy API requests to the backend service
11+
location /api/ {
12+
proxy_pass http://backend:8000/api/;
13+
proxy_set_header Host $host;
14+
proxy_set_header X-Real-IP $remote_addr;
15+
}
16+
}

0 commit comments

Comments
 (0)