# VerifyMate — Namecheap cPanel Deployment Guide

## Prerequisites
- Namecheap hosting with **Node.js support** (Business or higher plan, or a VPS)
- cPanel access
- Your domain pointed to Namecheap nameservers

---

## Step 1: Enable Node.js in cPanel

1. Log into **cPanel** → find **"Setup Node.js App"**
2. Click **"Create Application"**
3. Configure:
   - **Node.js version**: 18.x or higher (20.x recommended)
   - **Application mode**: Production
   - **Application root**: `verifymate` (a folder in your home dir)
   - **Application URL**: your domain or subdomain (e.g. `verify.yourdomain.com`)
   - **Application startup file**: `src/app.js`
4. Click **Create** — cPanel creates a virtual environment

---

## Step 2: Upload the Application Files

### Option A — via cPanel File Manager
1. Zip the entire `verifymate` folder on your computer
2. cPanel → **File Manager** → navigate to your app root folder
3. Upload the zip → right-click → Extract
4. Make sure `src/`, `data/`, `package.json`, `.env` are all present

### Option B — via FTP/SFTP (FileZilla)
1. Connect using your cPanel FTP credentials
2. Upload all files to `/home/yourusername/verifymate/`

---

## Step 3: Configure Environment Variables

1. In cPanel → **Setup Node.js App** → click your app → **Environment Variables**
2. Add each variable (or create a `.env` file in the app root):

```
NODE_ENV=production
PORT=3000
SESSION_SECRET=<generate a 64-char random string>
APP_URL=https://yourdomain.com
```

**Generate a strong SESSION_SECRET:**
```bash
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
```

---

## Step 4: Install Dependencies

1. In cPanel → **Setup Node.js App** → click your app
2. Click **"Run NPM Install"** button  
   — OR via SSH terminal:
```bash
cd ~/verifymate
npm install --production
```

---

## Step 5: Create Required Directories

Via SSH or File Manager, ensure these exist inside your app folder:
```
verifymate/
  data/          ← JSON database files (auto-created)
  sessions/      ← Session storage (auto-created)
  uploads/       ← Temp uploads (auto-created)
```

The app creates these automatically on first run, but you can pre-create them.

---

## Step 6: Set File Permissions

Via SSH:
```bash
chmod 755 ~/verifymate
chmod 755 ~/verifymate/src
chmod 700 ~/verifymate/data
chmod 700 ~/verifymate/sessions
```

---

## Step 7: Start the Application

1. cPanel → **Setup Node.js App** → click your app → click **"Run"** / **Start**
2. Visit your domain — you should see the VerifyMate landing page

---

## Step 8: Configure SSL (HTTPS)

1. cPanel → **SSL/TLS** → **Let's Encrypt** (free)
2. Issue certificate for your domain
3. Enable **"Force HTTPS Redirect"** in cPanel
4. In your `.env`, set `NODE_ENV=production` so cookies are secure

---

## Step 9: Set Up Passenger (Reverse Proxy)

cPanel uses **Phusion Passenger** to run Node.js apps. It handles:
- Automatic restarts on crash
- Port forwarding from 80/443 → your app port
- Process management

No extra config needed — Passenger is activated automatically when you create a Node.js app.

---

## Keeping the App Running

### Restart after code changes:
1. cPanel → Setup Node.js App → your app → **Restart**
   — OR via SSH: touch the restart file:
```bash
touch ~/verifymate/tmp/restart.txt
```

### View logs:
```bash
# Via SSH
tail -f ~/logs/verifymate.log
```

---

## Directory Structure After Deployment

```
~/verifymate/
├── src/
│   ├── app.js              ← Entry point
│   ├── db.js               ← JSON file database
│   ├── middleware/
│   │   └── auth.js
│   ├── routes/
│   │   ├── landing.js
│   │   ├── auth.js
│   │   ├── dashboard.js
│   │   ├── teams.js
│   │   └── settings.js
│   ├── services/
│   │   └── verifier.js     ← Email verification engine
│   └── public/
│       ├── css/
│       │   ├── main.css
│       │   └── landing.css
│       └── favicon.svg
├── data/                   ← Auto-created; stores all app data as JSON
├── sessions/               ← Auto-created; session files
├── uploads/                ← Auto-created; temp CSV uploads
├── package.json
├── .env                    ← Your environment variables
└── sample_emails.csv
```

---

## Troubleshooting

| Problem | Fix |
|---------|-----|
| App won't start | Check Node.js version ≥ 18 in cPanel |
| 500 error on login | Ensure `sessions/` directory exists and is writable |
| File upload fails | Check `uploads/` directory permissions (755) |
| Sessions not persisting | Set a strong `SESSION_SECRET` in `.env` |
| SMTP errors on invite | Configure SMTP variables in `.env` |
| App crashes | Check cPanel error logs; run `node src/app.js` via SSH for details |

---

## Security Checklist Before Go-Live

- [ ] Change `SESSION_SECRET` to a strong random string
- [ ] Set `NODE_ENV=production`  
- [ ] Enable HTTPS / SSL certificate
- [ ] Set `data/` folder permissions to 700 (not publicly accessible)
- [ ] Change default admin password after first login
- [ ] Add your domain to `APP_URL` in `.env`

---

## Updating the App

```bash
# Via SSH
cd ~/verifymate
# Upload new files via FTP/File Manager
npm install --production
touch tmp/restart.txt   # triggers Passenger restart
```

---

*VerifyMate v1.0 — Built for Namecheap cPanel / Phusion Passenger*
