# 🚀 Rebrandly AI - Installation Guide

This guide explains how to use the **automated installation wizard** to set up Rebrandly AI.

---

## 📦 What's Included

Your installation package includes:

- ✅ **install.bat** - Windows installer (double-click to run)
- ✅ **install.sh** - Linux/Mac installer (run in terminal)
- ✅ **install.js** - Interactive installation wizard
- ✅ All application source code
- ✅ Database schema (`database/schema.sql`)

---

## 🖥️ System Requirements

**Required:**
- Node.js 18.x or higher ([Download here](https://nodejs.org))
- MySQL 5.7+ or MariaDB 10.3+
- 2GB RAM minimum
- 1GB free disk space

**Optional:**
- Groq API key (for AI rebranding)
- Stripe account (for payments)

---

## 🎯 Quick Start

### **Windows Users:**

1. **Double-click** `install.bat`
2. Follow the on-screen prompts
3. Enter your database credentials
4. Wait for installation to complete

### **Linux/Mac Users:**

1. Open terminal in the project folder
2. Run: `chmod +x install.sh`
3. Run: `./install.sh`
4. Follow the on-screen prompts

---

## 📋 Installation Steps

The wizard will guide you through:

### **Step 1: Database Configuration**
- MySQL host (usually `localhost`)
- MySQL port (usually `3306`)
- Database username
- Database password
- Database name

### **Step 2: Database Schema Import**
- Automatically imports all required tables
- Creates: users, sessions, analysis_runs, exports, billing_events, admin_logs

### **Step 3: Email Configuration (SMTP)**
- SMTP host (e.g., `business187.web-hosting.com`)
- SMTP port (usually `465` for SSL)
- Email username
- Email password
- From name

### **Step 4: Application Configuration**
- Application URL (e.g., `https://rebrandlyai.com`)
- Groq API key (for AI features)
- Auto-generates session secret

### **Step 5: Stripe Configuration (Optional)**
- Stripe secret key
- Stripe publishable key
- Stripe webhook secret
- Can be configured later

### **Step 6: Create Configuration File**
- Generates `.env` file with all settings
- Saves securely in project root

### **Step 7: Install Dependencies**
- Runs `npm install`
- Downloads all required packages
- Takes 2-5 minutes

### **Step 8: Build Application**
- Runs `npm run build`
- Compiles TypeScript to JavaScript
- Optimizes for production
- Takes 1-3 minutes

---

## ✅ After Installation

Once installation completes, you can:

### **Start the Application:**

**Development mode:**
```bash
npm run dev
```
Access at: `http://localhost:3000`

**Production mode:**
```bash
npm start
```
Access at: `http://localhost:3000`

**With PM2 (recommended for production):**
```bash
npm install -g pm2
pm2 start npm --name "rebrandly" -- start
pm2 save
pm2 startup
```

---

## 🔧 Manual Installation

If you prefer manual setup or the wizard fails:

### **1. Create Database**
```sql
CREATE DATABASE rebrandlyai_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'rebrandly_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON rebrandlyai_db.* TO 'rebrandly_user'@'localhost';
FLUSH PRIVILEGES;
```

### **2. Import Schema**
```bash
mysql -u rebrandly_user -p rebrandlyai_db < database/schema.sql
```

### **3. Create .env File**
Copy `.env.example` to `.env` and fill in all values:
```bash
cp .env.example .env
nano .env
```

### **4. Install Dependencies**
```bash
npm install
```

### **5. Build Application**
```bash
npm run build
```

### **6. Start Application**
```bash
npm start
```

---

## 🌐 Deployment to Hosting

### **Option 1: Namecheap VPS**

1. Upload files via SFTP or Git
2. SSH into server
3. Run installation wizard:
   ```bash
   ./install.sh
   ```
4. Configure Nginx reverse proxy
5. Set up SSL certificate (Let's Encrypt)
6. Start with PM2

### **Option 2: Namecheap Shared Hosting**

1. Upload files via cPanel File Manager
2. Go to **Setup Node.js App**
3. Configure:
   - Application root: `/home/username/public_html`
   - Application URL: Your domain
   - Application startup file: `server.js`
   - Node.js version: 18.x
4. Click **Create**
5. Add environment variables in cPanel
6. Click **Start App**

### **Option 3: Vercel (Recommended)**

1. Push code to GitHub
2. Connect repository to Vercel
3. Add environment variables in Vercel dashboard
4. Deploy automatically
5. Configure custom domain

---

## 🔐 Security Checklist

After installation:

- [ ] Change default MySQL password
- [ ] Use strong session secret (auto-generated)
- [ ] Enable HTTPS/SSL certificate
- [ ] Restrict database access to localhost
- [ ] Set up firewall rules
- [ ] Configure backup schedule
- [ ] Enable rate limiting
- [ ] Review `.env` file permissions (should be 600)

---

## 🐛 Troubleshooting

### **"Node.js not found"**
- Install Node.js from https://nodejs.org
- Restart terminal/command prompt
- Verify: `node --version`

### **"Database connection failed"**
- Check MySQL is running
- Verify credentials are correct
- Check database exists
- Ensure user has privileges

### **"npm install failed"**
- Clear npm cache: `npm cache clean --force`
- Delete `node_modules/` and retry
- Check internet connection
- Try: `npm install --legacy-peer-deps`

### **"Build failed"**
- Check all `.env` variables are set
- Ensure no TypeScript errors
- Delete `.next/` folder and retry
- Check Node.js version is 18+

### **"Email not sending"**
- Verify SMTP credentials
- Check port 465 is not blocked
- Test email login manually
- Try port 587 with TLS instead

### **"Port 3000 already in use"**
- Stop other Node.js processes
- Change port in environment: `PORT=3001`
- Or kill process: `npx kill-port 3000`

---

## 📞 Getting Help

**Documentation:**
- `README.md` - Project overview
- `QUICKSTART.md` - Quick start guide
- `DATABASE_SETUP.md` - Database reference
- `DEPLOYMENT_STEPS.md` - Detailed deployment

**Common Issues:**
- Check `.env` file has all required variables
- Ensure database schema is imported
- Verify Node.js version is 18+
- Check MySQL user has ALL PRIVILEGES

---

## 🎉 Success!

Your Rebrandly AI installation is complete when you see:

```
╔════════════════════════════════════════════════════════════╗
║                                                            ║
║          Installation Complete! 🎉                         ║
║                                                            ║
╚════════════════════════════════════════════════════════════╝
```

**Next steps:**
1. Start the application: `npm start`
2. Access in browser: `http://localhost:3000`
3. Create your first admin user
4. Configure Stripe for payments
5. Test all features

---

**Enjoy using Rebrandly AI!** 🚀
