# Quick Start Guide - Dubai DLD Analytics API

## Prerequisites ✅

- **Node.js** 16+ installed
- **MySQL** 8.0+ installed and running
- **Dubai DLD database** with provided schema

## Installation (3 Steps) 🚀

### Step 1: Install Dependencies
```bash
npm install
```

### Step 2: Configure Database
Create a `.env` file in the project root:
```env
DB_HOST=localhost
DB_PORT=3306
DB_NAME=dubai_dld
DB_USER=root
DB_PASSWORD=your_password
```

Import the database schema:
```bash
mysql -u root -p < 2.sql
```

### Step 3: Start the Server
```bash
npm run dev
```

The server will start on `http://localhost:3000`

## Testing the API 🧪

### Health Check
```bash
curl http://localhost:3000/health
```

### Sample Query - Rental Trend
```bash
curl -X POST http://localhost:3000/api/query \
  -H "Content-Type: application/json" \
  -d '{"query": "Give me the last 6 months rental price trend for Business Bay"}'
```

### Predefined Queries
```bash
# Top areas
curl http://localhost:3000/api/queries/top-areas

# Project summary
curl http://localhost:3000/api/queries/project-summary

# Commercial leasing
curl http://localhost:3000/api/queries/commercial-leasing
```

## Frontend Demo 🎨

Open `public/index.html` in your browser to see the interactive dashboard with Chart.js visualizations.

## Available Endpoints 📡

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/query` | POST | Custom natural language queries |
| `/api/queries/rental-trend/:area` | GET | Rental trends for area |
| `/api/queries/top-areas` | GET | Top areas by transactions |
| `/api/queries/project-summary` | GET | Project summaries |
| `/api/queries/commercial-leasing` | GET | Commercial leasing analysis |
| `/api/queries/residential-leasing` | GET | Residential leasing analysis |
| `/health` | GET | Health check |
| `/api/database/info` | GET | Database statistics |

## Common Queries 💡

### Rental Analysis
- "Give me the last 6 months rental price trend for Business Bay"
- "Show me rental prices for apartments in Downtown"
- "What's the average rental price in Dubai Marina?"

### Project Analysis
- "Brief about the Project"
- "List of fast moving projects in last 6 months"
- "Which areas have off-plan projects?"

### Area Performance
- "Which area is having more rental transactions?"
- "Top 5 areas for Commercial leasing and why?"
- "Avg price of 3BHK apartment by area in last 6 months"

## Troubleshooting 🔧

### Database Connection Error
```bash
# Check if MySQL is running
mysql -u root -p -e "SELECT 1"

# Verify database exists
mysql -u root -p -e "SHOW DATABASES LIKE 'dubai_dld'"
```

### Port Already in Use
```bash
# Change PORT in .env file
PORT=3001
```

### Module Not Found
```bash
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
```

## Project Structure 📁

```
dubai-dld-analytics/
├── src/
│   ├── app.js                 # Main application
│   ├── models/
│   │   └── database.js        # MySQL connection
│   ├── services/
│   │   ├── nlpService.js      # NLP parsing
│   │   ├── sqlGenerator.js    # SQL generation
│   │   └── chartFormatter.js  # Chart.js formatting
│   ├── routes/
│   │   └── api.js            # API routes
│   └── middleware/
│       └── validation.js     # Request validation
├── public/
│   └── index.html            # Demo dashboard
├── tests/
│   └── api.test.js           # API tests
├── package.json
├── 2.sql                      # Database schema
└── README.md
```

## Next Steps 🎯

1. **Customize Queries**: Add your own query templates in `sqlGenerator.js`
2. **Extend NLP**: Improve parsing in `nlpService.js`
3. **Add More Charts**: Enhance chart visualization in `chartFormatter.js`
4. **Deploy**: Deploy to production (Vercel, Heroku, AWS, etc.)

## Need Help? 💬

Check the full documentation in `README.md` or review the code examples in the services directory.

Happy analyzing! 📊

