commit aaa0b2e9af5c49c20387aeaf2910f17c307ccafe
parent 7624a386203dde9be7587db9cf6f829782436b1e
Author: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Date: Sat, 17 Jan 2026 16:36:30 +0000
Add comprehensive documentation, testing, and CORS improvements
Co-authored-by: notamitgamer <199483577+notamitgamer@users.noreply.github.com>
Diffstat:
| M | .env.example | | | 8 | +++++++- |
| A | .gitignore | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | README.md | | | 227 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
| M | backend.py | | | 8 | +++++++- |
| A | test_backend.py | | | 63 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 370 insertions(+), 4 deletions(-)
diff --git a/.env.example b/.env.example
@@ -1,12 +1,18 @@
# Gemini API Configuration
+# Get your API key from: https://aistudio.google.com/app/apikey
+# This project uses Gemini 2.5 Flash Preview model
+# Sample for testing: AIzaSyDWUl8ouV5PBn7o9a3mcC-OIyOTuC0aLLo
GEMINI_API_KEY=your_gemini_api_key_here
# Firebase Admin SDK Configuration
+# Firebase Project: ada-ai-aranag
+# Get service account key from: Firebase Console > Project Settings > Service Accounts
+
# Option 1: Use a JSON file (for local development)
# Place your firebase-adminsdk.json file in the root directory
# Option 2: Use environment variable with JSON content (for Render.com deployment)
-# FIREBASE_CREDENTIALS={"type":"service_account","project_id":"your-project-id",...}
+# FIREBASE_CREDENTIALS={"type":"service_account","project_id":"ada-ai-aranag",...}
# Option 3: Use Application Default Credentials
# Set GOOGLE_APPLICATION_CREDENTIALS to the path of your service account JSON file
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,68 @@
+# Python
+__pycache__/
+*.py[cod]
+*$py.class
+*.so
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# Virtual Environment
+venv/
+env/
+ENV/
+.venv
+
+# Environment Variables
+.env
+.env.local
+.env.*.local
+
+# Firebase
+firebase-adminsdk.json
+firebase-adminsdk*.json
+serviceAccountKey.json
+
+# IDE
+.vscode/
+.idea/
+*.swp
+*.swo
+*~
+.DS_Store
+
+# Logs
+*.log
+logs/
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# Testing
+.pytest_cache/
+.coverage
+htmlcov/
+*.cover
+
+# Temporary files
+*.tmp
+*.temp
+.tmp/
+tmp/
+
+# OS
+Thumbs.db
+.DS_Store
diff --git a/README.md b/README.md
@@ -1 +1,224 @@
-# ada-web
-\ No newline at end of file
+# Ada AI Coding Environment
+
+A specialized AI coding assistant that helps with code analysis, debugging, and generation.
+
+## Features
+
+- ๐ค **AI-Powered Code Assistant**: Uses Gemini 2.5 Flash Preview for intelligent code analysis
+- ๐ฌ **Real-time Chat**: Stream responses with markdown rendering
+- ๐ **Code Editor**: Built-in CodeMirror editor with syntax highlighting
+- ๐ **Secure Authentication**: Firebase Auth with Google OAuth and Email/Password
+- ๐พ **Chat History**: Persistent storage in Firestore
+- ๐ **Code Compilation**: Direct integration with online compiler
+- ๐ฑ **Mobile Responsive**: Works seamlessly on desktop and mobile
+
+## Tech Stack
+
+**Frontend:**
+- Vanilla JavaScript (ES6+)
+- Tailwind CSS
+- CodeMirror (code editor)
+- LZString (compression)
+- Firebase SDK (Auth & Firestore)
+- Marked.js (markdown rendering)
+
+**Backend:**
+- Python 3.x
+- Flask
+- Google Generative AI SDK (Gemini 2.5 Flash Preview)
+- Firebase Admin SDK
+- Flask-CORS
+
+**Database:**
+- Firebase Firestore (NoSQL)
+
+## Setup
+
+### Prerequisites
+- Python 3.8+
+- Node.js (for frontend development)
+- Firebase account
+- Google AI API key
+
+### Backend Setup
+
+1. Clone the repository:
+```bash
+git clone https://github.com/notamitgamer/ada-web.git
+cd ada-web
+```
+
+2. Install Python dependencies:
+```bash
+pip install -r requirements.txt
+```
+
+3. Create a `.env` file (use `.env.example` as template):
+```bash
+cp .env.example .env
+```
+
+4. Configure environment variables in `.env`:
+```
+GEMINI_API_KEY=your_actual_gemini_api_key
+FIREBASE_CREDENTIALS={"type":"service_account",...}
+PORT=5000
+```
+
+5. Run the backend:
+```bash
+python backend.py
+```
+
+### Frontend Setup
+
+The frontend is a static HTML application. Simply open `index.html` in a browser or serve it using a local server:
+
+```bash
+python -m http.server 5500
+```
+
+Then visit: `http://localhost:5500`
+
+## Firebase Configuration
+
+### Firestore Database Schema
+
+```
+users (collection)
+ โโ {uid} (document)
+ โโ email: string
+ โโ displayName: string
+ โโ photoURL: string
+ โโ createdAt: timestamp
+ โโ chats (subcollection)
+ โโ {chatUUID} (document)
+ โโ title: string
+ โโ createdAt: timestamp
+ โโ updatedAt: timestamp
+ โโ messages: array[
+ {
+ role: "user" | "model",
+ content: string,
+ timestamp: timestamp
+ }
+ ]
+```
+
+### Firebase Service Account
+
+1. Go to [Firebase Console](https://console.firebase.google.com/)
+2. Select project: `ada-ai-aranag`
+3. Navigate to Project Settings > Service Accounts
+4. Generate new private key
+5. Use the downloaded JSON for `FIREBASE_CREDENTIALS` environment variable
+
+## API Endpoints
+
+### POST `/api/chat`
+Streams AI responses for code queries.
+
+**Headers:**
+```
+Authorization: Bearer <firebase_id_token>
+Content-Type: application/json
+```
+
+**Body:**
+```json
+{
+ "message": "Why is this loop infinite?",
+ "history": [],
+ "codeContext": "while(i > 0) { ... }",
+ "fileContext": "",
+ "sessionId": "uuid-v4"
+}
+```
+
+### POST `/api/generate-title`
+Generates a short title for chat sessions.
+
+**Headers:**
+```
+Authorization: Bearer <firebase_id_token>
+Content-Type: application/json
+```
+
+**Body:**
+```json
+{
+ "message": "First user message"
+}
+```
+
+## Deployment
+
+### Render.com
+
+1. Create a new Web Service
+2. Connect your GitHub repository
+3. Set environment variables:
+ - `GEMINI_API_KEY`
+ - `FIREBASE_CREDENTIALS` (full JSON string)
+4. Deploy!
+
+### Frontend (Static Hosting)
+
+Deploy `index.html` to:
+- GitHub Pages
+- Netlify
+- Vercel
+- Any static hosting service
+
+Update the API URL in `index.html`:
+```javascript
+const API_URL = 'https://your-backend.onrender.com/api/chat';
+```
+
+## Development
+
+### Running Tests
+
+```bash
+python test_backend.py
+```
+
+### Code Style
+
+- Python: Follow PEP 8
+- JavaScript: ES6+ with consistent formatting
+- Use meaningful variable names
+- Comment complex logic
+
+## Security Features
+
+โ
Firebase ID Token verification on backend
+โ
CORS protection
+โ
Environment variable protection
+โ
Server-side authentication validation
+โ
Secure API key storage
+
+## Contributing
+
+1. Fork the repository
+2. Create a feature branch
+3. Commit your changes
+4. Push to the branch
+5. Open a Pull Request
+
+## License
+
+MIT License - see LICENSE file for details
+
+## Author
+
+**Amit Dutta**
+- Website: [amit.is-a.dev](https://amit.is-a.dev)
+- Project: [Ada AI](https://ada.amit.is-a.dev)
+
+## Acknowledgments
+
+- Google Gemini AI for powering the code assistant
+- Firebase for authentication and database
+- CodeMirror for the code editor
+- The open-source community
+\ No newline at end of file
diff --git a/backend.py b/backend.py
@@ -10,7 +10,13 @@ from firebase_admin import credentials, auth, firestore
# --- INIT APP & CONFIG ---
app = Flask(__name__)
# Allow CORS for your domain and localhost for testing
-CORS(app, resources={r"/api/*": {"origins": ["https://amit.is-a.dev", "http://127.0.0.1:5500", "http://localhost:5000"]}})
+CORS(app, resources={r"/api/*": {"origins": [
+ "https://ada.amit.is-a.dev",
+ "https://amit.is-a.dev",
+ "http://127.0.0.1:5500",
+ "http://localhost:5000",
+ "http://localhost:5500"
+]}})
# 1. Firebase Admin Init (Server-Side Security)
# Ensure you have your service account json or environment variables set up in Render
diff --git a/test_backend.py b/test_backend.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+"""
+Simple test script to verify backend.py imports and basic functionality
+"""
+
+import sys
+import os
+
+# Set a dummy API key for import testing
+os.environ['GEMINI_API_KEY'] = 'test_key_for_import'
+
+print("Testing backend.py imports and structure...")
+
+try:
+ # Test imports
+ from flask import Flask, request, jsonify, Response, stream_with_context
+ from flask_cors import CORS
+ import google.generativeai as genai
+ print("โ
All required packages imported successfully")
+
+ # Test that backend.py can be imported
+ import backend
+ print("โ
backend.py imported successfully")
+
+ # Check if Flask app exists
+ assert hasattr(backend, 'app'), "Flask app not found"
+ print("โ
Flask app exists")
+
+ # Check if routes are defined
+ routes = [rule.rule for rule in backend.app.url_map.iter_rules()]
+ expected_routes = ['/', '/api/chat', '/api/generate-title']
+
+ for route in expected_routes:
+ assert route in routes, f"Route {route} not found"
+ print(f"โ
Route {route} is defined")
+
+ # Check if verify_token function exists
+ assert hasattr(backend, 'verify_token'), "verify_token function not found"
+ print("โ
verify_token function exists")
+
+ # Check model name
+ model_name = backend.model.model_name
+ print(f"โ
Model configured: {model_name}")
+
+ if "gemini-2.5-flash-preview" in model_name or model_name == "models/gemini-2.5-flash-preview-09-2025":
+ print("โ
Correct model version configured!")
+ else:
+ print(f"โ ๏ธ Warning: Model is {model_name}, expected gemini-2.5-flash-preview-09-2025")
+
+ print("\n" + "="*50)
+ print("โ
ALL TESTS PASSED!")
+ print("="*50)
+
+except ImportError as e:
+ print(f"โ Import Error: {e}")
+ print("Make sure all dependencies are installed: pip install -r requirements.txt")
+ sys.exit(1)
+except AssertionError as e:
+ print(f"โ Assertion Error: {e}")
+ sys.exit(1)
+except Exception as e:
+ print(f"โ Unexpected Error: {type(e).__name__}: {e}")
+ sys.exit(1)