# Quick Start Guide - Rebrandly AI

Get your Rebrandly AI application running in 15 minutes.

---

## ⚡ Prerequisites Checklist

Before starting, ensure you have:

- [ ] Namecheap hosting account with cPanel access
- [ ] MySQL database access
- [ ] SMTP email account (Namecheap Private Email or Gmail)
- [ ] Stripe account
- [ ] OpenAI API key
- [ ] Node.js 18.x or 20.x installed (for local development)

---

## 🚀 Installation Steps

### Step 1: Install Dependencies (2 minutes)

```bash
# Navigate to project directory
cd /path/to/rebrandlyai

# Install packages
npm install
# or if using pnpm
pnpm install
```

### Step 2: Database Setup (3 minutes)

1. **Create database in cPanel**:
   - Database name: `rebrandlyai_db`
   - User: `rebrandly_user`
   - Password: (generate strong password)
   - Grant ALL PRIVILEGES

2. **Import schema**:
   - Open phpMyAdmin
   - Select your database
   - Import `database/schema.sql`

### Step 3: Configure Environment (5 minutes)

```bash
# Copy environment template
cp .env.example .env

# Edit with your credentials
nano .env
```

**Minimum required variables**:
```env
# App
NEXT_PUBLIC_APP_URL=https://rebrandlyai.com
SESSION_SECRET=<run: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))">

# Database
MYSQL_HOST=localhost
MYSQL_USER=rebrandly_user
MYSQL_PASSWORD=your_db_password
MYSQL_DATABASE=rebrandlyai_db

# Email
SMTP_HOST=mail.privateemail.com
SMTP_PORT=587
SMTP_USER=noreply@rebrandlyai.com
SMTP_PASS=your_email_password
SMTP_FROM_EMAIL=noreply@rebrandlyai.com

# Stripe
STRIPE_SECRET_KEY=sk_test_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

# OpenAI
OPENAI_API_KEY=sk-...
```

### Step 4: Build Application (3 minutes)

```bash
# Build for production
npm run build
```

### Step 5: Start Application (1 minute)

```bash
# Start the server
npm start

# Or for development
npm run dev
```

### Step 6: Verify Installation (1 minute)

1. Visit `http://localhost:3000` (or your domain)
2. Sign up for an account
3. Check email for verification
4. Login to dashboard

---

## 🔧 Quick Tests

### Test Database Connection

```bash
node -e "
const mysql = require('mysql2/promise');
require('dotenv').config();
mysql.createConnection({
  host: process.env.MYSQL_HOST,
  user: process.env.MYSQL_USER,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DATABASE
}).then(() => console.log('✅ Database OK')).catch(e => console.error('❌', e.message));
"
```

### Test Email

```bash
node -e "
const nodemailer = require('nodemailer');
require('dotenv').config();
nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: process.env.SMTP_PORT,
  auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
}).verify().then(() => console.log('✅ Email OK')).catch(e => console.error('❌', e.message));
"
```

---

## 👤 Create Admin User

After signing up normally:

```sql
-- In phpMyAdmin, run this query with your email:
UPDATE users 
SET is_admin = TRUE, 
    email_verified = TRUE, 
    plan = 'platinum' 
WHERE email = 'your-email@example.com';
```

---

## 🌐 Deploy to Namecheap

### Shared Hosting

1. Upload files via FTP to `public_html`
2. In cPanel → Setup Node.js App:
   - Node version: 20.x
   - App root: your directory
   - Startup file: leave default
3. Click "Run NPM Install"
4. Click "Start App"

### VPS Hosting

```bash
# Install PM2
npm install -g pm2

# Start app
pm2 start npm --name "rebrandly" -- start

# Save configuration
pm2 save
pm2 startup
```

---

## 📋 Post-Installation Checklist

- [ ] Application starts without errors
- [ ] Can access homepage
- [ ] Sign up works
- [ ] Verification email received
- [ ] Login works
- [ ] Dashboard accessible
- [ ] Admin panel accessible (if admin)
- [ ] Database has data
- [ ] Stripe test payment works

---

## 🆘 Common Issues

### "Cannot find module"
```bash
rm -rf node_modules package-lock.json
npm install
```

### "Database connection failed"
- Check `.env` credentials
- Verify database exists
- Test connection in phpMyAdmin

### "Email not sending"
- Verify SMTP credentials
- Check port (587 for TLS, 465 for SSL)
- Try different SMTP provider

### "Port already in use"
```bash
# Find process
lsof -i :3000
# Kill it
kill -9 <PID>
```

---

## 📚 Next Steps

1. **Configure Stripe Products**: Create subscription plans in Stripe Dashboard
2. **Set Up Webhook**: Add webhook endpoint in Stripe
3. **SSL Certificate**: Install Let's Encrypt certificate
4. **Domain DNS**: Point domain to your server
5. **Test Full Flow**: Sign up → Verify → Subscribe → Use app

---

## 📖 Full Documentation

- **Deployment**: `NAMECHEAP_DEPLOYMENT.md`
- **Database**: `DATABASE_SETUP.md`
- **General**: `README.md`

---

## 🎉 You're Ready!

Your Rebrandly AI application is now running. Visit your domain and start using the platform!

**Need help?** Check the troubleshooting sections in the full documentation.
