# Quick Start Guide - Backend API

## 🚀 Get Started in 3 Steps

### 1. Install Dependencies
```bash
cd dashboard-backend

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install packages
pip install -r requirements.txt
```

### 2. Configure Environment
```bash
# Copy environment template
cp .env.example .env

# Edit .env file (update database password)
nano .env
```

**Required Configuration:**
```env
DB_PASSWORD=your-actual-password
```

### 3. Start the Server
```bash
# Option A: Use startup script
./run.sh

# Option B: Direct Python
python app.py
```

API will be available at: **http://localhost:5000**

## ✅ Verify Installation

### Test Health Endpoint
```bash
curl http://localhost:5000/health
```

Expected response:
```json
{
  "status": "healthy",
  "timestamp": "2024-11-25T10:30:00",
  "service": "Call Analytics Dashboard API"
}
```

### Test Business List
```bash
curl http://localhost:5000/list-businesses
```

### Test Calls Endpoint
```bash
curl "http://localhost:5000/calls/6840?limit=5"
```

## 🔌 Connect Frontend

Update the frontend API URL in `dashboard-frontend/src/services/api.js`:

```javascript
const API_BASE_URL = 'http://localhost:5000';
```

Then switch from mock data to real API:

```javascript
// Change from:
import { mockDataService } from '../services/api';

// To:
import { apiService } from '../services/api';
```

## 📊 Available Endpoints

| Endpoint | Description |
|----------|-------------|
| `GET /health` | Health check |
| `GET /list-businesses` | List all businesses |
| `GET /calls/:bid` | Get calls for business |
| `GET /calls/:bid/:callid` | Get call details |
| `GET /analytics/:bid/stats` | Get statistics |
| `GET /analytics/:bid/sentiment` | Sentiment analysis |
| `GET /analytics/:bid/intent` | Intent distribution |

## 🔧 Troubleshooting

**Database Connection Error?**
```bash
# Test connection
mysql -h 10.0.0.109 -u admin -p voicebot_cluster
```

**Port 5000 in use?**
```bash
# Change port in .env
FLASK_PORT=5001
```

**Module not found?**
```bash
# Reinstall dependencies
pip install -r requirements.txt
```

## 🚀 Production Deployment

```bash
# Install gunicorn
pip install gunicorn

# Run with 4 workers
gunicorn -w 4 -b 0.0.0.0:5000 app:app
```

## 📚 Full Documentation

See [README.md](README.md) for complete API documentation.

---

**Happy Coding! 🎉**
