Complete guide to connecting AegisAI frontend and backend.
Browser β Gemini API (Direct)
Pros:
Cons:
Use When:
Browser β Backend API β Gemini API
β
Database (SQLite)
Pros:
Cons:
Use When:
cd backend
source venv/bin/activate # Windows: venv\Scripts\activate
python main.py
Verify: http://localhost:8000/health should return:
{"status":"healthy","components":{...}}
Edit frontend/src/constants.ts:
// Change this line:
ENABLE_BACKEND_API: false
// To this:
ENABLE_BACKEND_API: true
Edit frontend/.env.local:
VITE_API_URL=http://localhost:8000
cd frontend
npm run dev
Open http://localhost:3000
Look for two indicators in header:
SYSTEM ONLINE (green) - Frontend workingBACKEND (blue pulsing) - Connected to backendIf shows CLIENT-SIDE (orange) - Backend not connected
curl http://localhost:8000/health
Expected:
{
"status": "healthy",
"components": {
"database": "ok",
"vision_agent": "ok",
"planner_agent": "ok"
}
}
curl -X POST http://localhost:8000/api/analyze \
-H "Content-Type: application/json" \
-d '{"image":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="}'
Expected:
{
"incident": false,
"type": "normal",
"severity": "low",
"confidence": 80,
"reasoning": "...",
"subjects": [],
"recommended_actions": []
}
BACKEND (blue)Backend Terminal Should Show:
INFO: POST /api/analyze
INFO: Analysis complete: {"incident":true,...}
ββββββββββββββββββββββββββββ
β Browser (Port 3000) β
β β
β ββββββββββββββββββββββ β
β β React Frontend β β
β β β β
β β β (direct call) β β
β β β β
β β Gemini API β β
β ββββββββββββββββββββββ β
ββββββββββββββββββββββββββββ
Data Flow:
1. Capture frame
2. Call Gemini API directly
3. Display result
4. Store in browser memory (lost on refresh)
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β Browser (Port 3000) β β Backend (Port 8000) β
β β β β
β ββββββββββββββββββ β β ββββββββββββββββββ β
β β React Frontend β β POST β β FastAPI β β
β β ββββΌβββββββΌββΆβ β β
β β (UI only) β β β β Vision Agent β β
β ββββββββββββββββββ β β β β β β
β β β β Planner Agent β β
β β β β β β β
β β β β Actions β β
β β β β β β β
β β β β Database β β
β β β ββββββββββββββββββ β
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
Data Flow:
1. Capture frame
2. Send to backend API
3. Backend analyzes with Gemini
4. Backend saves to database
5. Backend executes actions
6. Return result to frontend
7. Display result
// frontend/src/constants.ts
ENABLE_BACKEND_API: false
Restart frontend:
npm run dev
Indicator: Shows CLIENT-SIDE (orange)
// frontend/src/constants.ts
ENABLE_BACKEND_API: true
Start backend first:
cd backend && python main.py
Then frontend:
cd frontend && npm run dev
Indicator: Shows BACKEND (blue)
Check:
.env.local:
VITE_API_URL=http://localhost:8000
Test:
curl http://localhost:8000/health
Error: Access-Control-Allow-Origin
Fix: Ensure backend .env has:
CORS_ORIGINS=["http://localhost:3000","http://localhost:5173"]
Restart backend.
Fix: Update backend to latest version with analyze endpoint.
Check:
curl http://localhost:8000/docs
Should list /api/analyze endpoint.
Check:
# Is it running?
curl http://localhost:8000/
# Check logs
# (Look at terminal where you ran python main.py)
Restart:
cd backend
python main.py
| Feature | Client-Side | Full Stack |
|---|---|---|
| Threat Detection | β | β |
| Real-time Analysis | β | β |
| Incident Storage | β | β |
| Action Execution | β | β |
| Multi-user | β | β |
| API Security | β | β |
| Database | β | β |
| Email Alerts | β | β |
| Historical Data | β | β |
| Load Balancing | β | β |
CLIENT-SIDE in headerBACKEND in header (blue)/health returns healthy# Build frontend only
cd frontend
npm run build
# Deploy to Vercel
vercel --prod
Environment Variables (Vercel):
VITE_GEMINI_API_KEY = your_keyBackend β Render:
git push render main
Frontend β Vercel:
cd frontend
vercel --prod
Environment Variables:
Render (Backend):
GEMINI_API_KEY = your_keyVercel (Frontend):
VITE_GEMINI_API_KEY = your_keyVITE_API_URL = https://your-backend.onrender.comENABLE_BACKEND_API: true in constants.ts| Aspect | Current State | After Integration |
|---|---|---|
| Default Mode | Client-Side | Client-Side |
| Can Use Backend | β No | β Yes |
| Toggle | N/A | ENABLE_BACKEND_API flag |
| Indicator | None | Blue "BACKEND" or Orange "CLIENT-SIDE" |
| Flexibility | One mode only | Switch anytime |
Key Point: You can now use BOTH modes! Switch by changing one flag in constants.ts.
Integration Complete! π