README.md (6264B)
1 # Ada AI Coding Environment 2 3 A specialized AI coding assistant that helps with code analysis, debugging, and generation. 4 5 ## Features 6 7 - 🤖 **AI-Powered Code Assistant**: Uses Gemini 2.5 Flash Preview for intelligent code analysis 8 - 💬 **Real-time Chat**: Stream responses with markdown rendering 9 - 📝 **Code Editor**: Built-in CodeMirror editor with syntax highlighting 10 - 🔐 **Secure Authentication**: Firebase Auth with Google OAuth and Email/Password 11 - 💾 **Chat History**: Persistent storage in Firestore 12 - 🚀 **Code Compilation**: Direct integration with online compiler 13 - 📱 **Mobile Responsive**: Works seamlessly on desktop and mobile 14 15 ## Tech Stack 16 17 **Frontend:** 18 - Vanilla JavaScript (ES6+) 19 - Tailwind CSS 20 - CodeMirror (code editor) 21 - LZString (compression) 22 - Firebase SDK (Auth & Firestore) 23 - Marked.js (markdown rendering) 24 25 **Backend:** 26 - Python 3.x 27 - Flask 28 - Google Generative AI SDK (Gemini 2.5 Flash Preview) 29 - Firebase Admin SDK 30 - Flask-CORS 31 32 **Database:** 33 - Firebase Firestore (NoSQL) 34 35 ## Setup 36 37 ### Prerequisites 38 - Python 3.8+ 39 - Node.js (for frontend development) 40 - Firebase account 41 - Google AI API key 42 43 ### Backend Setup 44 45 1. Clone the repository: 46 ```bash 47 git clone https://github.com/notamitgamer/ada-web.git 48 cd ada-web 49 ``` 50 51 2. Install Python dependencies: 52 ```bash 53 pip install -r requirements.txt 54 ``` 55 56 3. Create a `.env` file (use `.env.example` as template): 57 ```bash 58 cp .env.example .env 59 ``` 60 61 4. Configure environment variables in `.env`: 62 ``` 63 GEMINI_API_KEY=your_actual_gemini_api_key 64 FIREBASE_CREDENTIALS={"type":"service_account",...} 65 PORT=5000 66 ``` 67 68 5. Run the backend: 69 ```bash 70 python backend.py 71 ``` 72 73 ### Frontend Setup 74 75 The frontend is a static HTML application. Simply open `index.html` in a browser or serve it using a local server: 76 77 ```bash 78 python -m http.server 5500 79 ``` 80 81 Then visit: `http://localhost:5500` 82 83 ## Firebase Configuration 84 85 ### Firestore Database Schema 86 87 ``` 88 users (collection) 89 ├─ {uid} (document) 90 ├─ email: string 91 ├─ displayName: string 92 ├─ photoURL: string 93 ├─ createdAt: timestamp 94 └─ chats (subcollection) 95 └─ {chatUUID} (document) 96 ├─ title: string 97 ├─ createdAt: timestamp 98 ├─ updatedAt: timestamp 99 └─ messages: array[ 100 { 101 role: "user" | "model", 102 content: string, 103 timestamp: timestamp 104 } 105 ] 106 ``` 107 108 ### Firebase Service Account 109 110 1. Go to [Firebase Console](https://console.firebase.google.com/) 111 2. Select project: `ada-ai-aranag` 112 3. Navigate to Project Settings > Service Accounts 113 4. Generate new private key 114 5. Use the downloaded JSON for `FIREBASE_CREDENTIALS` environment variable 115 116 ## API Endpoints 117 118 ### POST `/api/chat` 119 Streams AI responses for code queries. 120 121 **Headers:** 122 ``` 123 Authorization: Bearer <firebase_id_token> 124 Content-Type: application/json 125 ``` 126 127 **Body:** 128 ```json 129 { 130 "message": "Why is this loop infinite?", 131 "history": [], 132 "codeContext": "while(i > 0) { ... }", 133 "fileContext": "", 134 "sessionId": "uuid-v4" 135 } 136 ``` 137 138 ### POST `/api/generate-title` 139 Generates a short title for chat sessions. 140 141 **Headers:** 142 ``` 143 Authorization: Bearer <firebase_id_token> 144 Content-Type: application/json 145 ``` 146 147 **Body:** 148 ```json 149 { 150 "message": "First user message" 151 } 152 ``` 153 154 ## Deployment 155 156 ### Backend: Render.com 157 158 #### Quick Deploy 159 160 1. **Create a new Web Service** on [Render.com](https://render.com) 161 2. **Connect your GitHub repository**: `notamitgamer/ada-web` 162 3. **Configure the service**: 163 - **Name**: `ada-web-backend` (or your preferred name) 164 - **Region**: Choose closest to your users 165 - **Branch**: `main` 166 - **Build Command**: `pip install -r requirements.txt` 167 - **Start Command**: `gunicorn backend:app --workers 2 --threads 2 --timeout 120` 168 - **Plan**: Free (or paid for better performance) 169 170 4. **Set Environment Variables**: 171 - `GEMINI_API_KEY`: Your Gemini API key (get from https://aistudio.google.com/app/apikey) 172 - `FIREBASE_CREDENTIALS`: Full JSON string from Firebase service account 173 - `FLASK_DEBUG`: `False` (for production) 174 - `PYTHON_VERSION`: `3.11.0` (optional, auto-detected) 175 176 5. **Deploy!** Render will automatically deploy your backend. 177 178 #### Alternative: Using render.yaml 179 180 The repository includes a `render.yaml` file for automatic configuration. Simply connect your repo and Render will use this file for setup. 181 182 #### Health Check Endpoint 183 184 The backend provides a `/health` endpoint for monitoring: 185 - **URL**: `https://your-app.onrender.com/health` 186 - **Response**: `{"status": "healthy", "timestamp": "..."}` 187 188 #### Keep Backend Alive with UptimeRobot 189 190 Render's free tier spins down after 15 minutes of inactivity. Use [UptimeRobot](https://uptimerobot.com) to keep it alive: 191 192 1. **Create a free UptimeRobot account** 193 2. **Add New Monitor**: 194 - Monitor Type: `HTTP(s)` 195 - Friendly Name: `Ada Web Backend` 196 - URL: `https://ada-web.onrender.com/health` 197 - Monitoring Interval: `5 minutes` (free tier) 198 3. **Save** - UptimeRobot will ping your backend every 5 minutes to keep it alive! 199 200 ### Frontend (Static Hosting) 201 202 Deploy `index.html` to: 203 - GitHub Pages 204 - Netlify 205 - Vercel 206 - Any static hosting service 207 208 Update the API URL in `index.html`: 209 ```javascript 210 const API_URL = 'https://your-backend.onrender.com/api/chat'; 211 ``` 212 213 ## Development 214 215 ### Running Tests 216 217 ```bash 218 python test_backend.py 219 ``` 220 221 ### Code Style 222 223 - Python: Follow PEP 8 224 - JavaScript: ES6+ with consistent formatting 225 - Use meaningful variable names 226 - Comment complex logic 227 228 ## Security Features 229 230 ✅ Firebase ID Token verification on backend 231 ✅ CORS protection 232 ✅ Environment variable protection 233 ✅ Server-side authentication validation 234 ✅ Secure API key storage 235 236 ## Contributing 237 238 1. Fork the repository 239 2. Create a feature branch 240 3. Commit your changes 241 4. Push to the branch 242 5. Open a Pull Request 243 244 ## License 245 246 MIT License - see LICENSE file for details 247 248 ## Author 249 250 **Amit Dutta** 251 - Website: [amit.is-a.dev](https://amit.is-a.dev) 252 - Project: [Ada AI](https://ada.amit.is-a.dev) 253 254 ## Acknowledgments 255 256 - Google Gemini AI for powering the code assistant 257 - Firebase for authentication and database 258 - CodeMirror for the code editor 259 - The open-source community