# Quick Start Guide - Backend Server

## Step 1: Install Dependencies

If you haven't already, install the Node.js dependencies:

```bash
cd backend
npm install
```

## Step 2: Create .env File

Create a `.env` file in the `backend` directory with the following content:

```env
# Server Configuration
PORT=5000
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=centralized_inquiry
DB_USER=root
DB_PASSWORD=

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-in-production-12345
JWT_EXPIRES_IN=7d

# Universal Bypass Password (for supplier admin access)
UNIVERSAL_BYPASS_PASSWORD=admin123

# Email Configuration (Optional - leave empty if not using)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=
EMAIL_PASS=
EMAIL_FROM=noreply@centralizedinquiry.com

# SMS Configuration (Optional - leave empty if not using)
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=

# Stripe Configuration (Optional - leave empty if not using)
STRIPE_SECRET_KEY=
STRIPE_PUBLISHABLE_KEY=
STRIPE_WEBHOOK_SECRET=

# File Upload Configuration
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=5242880

# Frontend URL
FRONTEND_URL=http://localhost:5173

# Profit Margin Configuration (percentage)
PROFIT_MARGIN_PERCENTAGE=10

# Commission Configuration (percentage)
COMMISSION_PERCENTAGE=5

# Cashback Configuration (percentage)
CASHBACK_PERCENTAGE=2

# Supplier Detail Unlock Price (in cents)
UNLOCK_PRICE_CENTS=500
```

## Step 3: Create MySQL Database

Make sure MySQL is running, then create the database:

```sql
CREATE DATABASE centralized_inquiry;
```

## Step 4: Start the Server

Run one of these commands:

**For development (with auto-reload):**
```bash
npm run dev
```

**For production:**
```bash
npm start
```

The server will:
- Connect to the database
- Create all tables automatically
- Start on port 5000

You should see:
```
✅ Database connection established successfully.
✅ Database models synchronized.
🚀 Server is running on port 5000
📝 Environment: development
```

## Step 5: (Optional) Create Admin User

In a new terminal, run:

```bash
node scripts/createAdmin.js
```

This creates an admin user:
- Email: `admin@example.com`
- Password: `admin123`

**⚠️ Change the password after first login!**

## Troubleshooting

### Port Already in Use
If port 5000 is already in use, change the PORT in `.env` file.

### Database Connection Error
- Make sure MySQL is running
- Verify database name, user, and password in `.env`
- Check MySQL port (default: 3306)

### Module Not Found
Run `npm install` again to ensure all dependencies are installed.

