# Quick Start Guide

## 🚀 Get Started in 5 Minutes

### Prerequisites
- PHP 8.0+ installed
- Composer installed
- Your Spring Boot backend running on port 8084

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

### Step 2: Configure Environment
```bash
cp .env.example .env
# Edit .env and add your API keys
```

Required environment variables:
- `OPENROUTER_API_KEY` - Get from https://openrouter.ai
- `WHATSAPP_PHONE_NUMBER_ID` - Optional, only for WhatsApp integration
- `WHATSAPP_TOKEN` - Optional, only for WhatsApp integration
- `WHATSAPP_VERIFY_TOKEN` - Optional, only for WhatsApp integration

### Step 3: Start the Services
```bash
./start.sh
```

This will start:
- MCP Server on port 8085
- API Server on port 3000

### Step 4: Test It!
```bash
curl -X POST http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Show me the database schema"}'
```

## 🐳 Docker Quick Start

Even faster with Docker:

```bash
# 1. Create .env file
cp .env.example .env
# Edit .env with your credentials

# 2. Start with Docker Compose
docker-compose up -d

# 3. Test
curl http://localhost:3000/health
```

## 📝 Example Queries

Try these queries:

```bash
# Get schema
curl -X POST http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "What tables exist in the database?"}'

# Query data
curl -X POST http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Show me all users"}'

# Insert data
curl -X POST http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Add a new user named John Doe with email john@example.com"}'

# Update data
curl -X POST http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Update the email of user with ID 1 to newemail@example.com"}'
```

## 🔧 Troubleshooting

### Port Already in Use
```bash
# Kill processes on ports
lsof -ti:3000 | xargs kill -9
lsof -ti:8085 | xargs kill -9
```

### Composer Not Found
```bash
# Install Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
```

### PHP Version Too Old
```bash
# Check PHP version
php -v

# Update PHP (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install php8.2
```

## 📚 Next Steps

1. Read the full [README.md](README.md) for detailed documentation
2. Check [MIGRATION.md](MIGRATION.md) to understand differences from Node.js
3. Customize the system prompt in `chat.php`
4. Add authentication to your endpoints
5. Set up WhatsApp webhook for chatbot functionality

## 🎯 What This Does

This application:
1. ✅ Receives natural language queries
2. ✅ Converts them to SQL using AI
3. ✅ Executes queries on your database
4. ✅ Returns results in plain English
5. ✅ Supports WhatsApp integration
6. ✅ Maintains conversation context

## 💡 Tips

- Use descriptive table and column names for better AI understanding
- The AI will automatically call `get_schema` when needed
- Complex queries might take multiple rounds of tool calling
- Check logs in `mcp.log` and `api.log` for debugging

## 🆘 Getting Help

If you encounter issues:
1. Check the logs: `tail -f mcp.log api.log`
2. Verify Spring Boot backend is running: `curl http://localhost:8084/health`
3. Test MCP server: `curl http://localhost:8085/tools`
4. Verify API server: `curl http://localhost:3000/health`

Happy coding! 🎉
