# 🚀 Deploying PinBoostr on cPanel

## What You Need
- cPanel hosting with **Node.js App Manager** (most modern cPanel hosts have this)
- **File Manager** access
- A domain or subdomain pointed to your hosting

---

## Step-by-Step Deployment

### STEP 1 — Upload Files via File Manager

1. Login to **cPanel → File Manager**
2. Navigate to where you want the app (e.g. `home/yourusername/`)
3. Create a new folder called `pinboostr`
4. Click **Upload** → upload the `pinboostr.zip` file
5. Right-click the zip → **Extract** into the `pinboostr` folder
6. You should now have:
   ```
   /home/yourusername/pinboostr/
   ├── server.js
   ├── package.json
   ├── .env.example
   ├── src/
   ├── data/
   └── ...
   ```

---

### STEP 2 — Create Node.js App in cPanel

1. Go to **cPanel → Node.js App** (or "Setup Node.js App")
2. Click **Create Application**
3. Fill in the form:

   | Field | Value |
   |-------|-------|
   | Node.js version | **18.x** or **20.x** (choose highest available) |
   | Application mode | **Production** |
   | Application root | `pinboostr` (the folder you created) |
   | Application URL | Your domain or subdomain e.g. `yourdomain.com` or `app.yourdomain.com` |
   | Application startup file | `server.js` |

4. Click **Create**

---

### STEP 3 — Set Environment Variables

Still in the Node.js App screen, find the **Environment Variables** section and add:

| Key | Value |
|-----|-------|
| `NODE_ENV` | `production` |
| `SESSION_SECRET` | any long random string e.g. `xK92mPqL8vZ3nR7wT1` |
| `ANTHROPIC_API_KEY` | your Claude API key from console.anthropic.com |
| `PINTEREST_APP_ID` | your Pinterest app ID (optional) |
| `PINTEREST_APP_SECRET` | your Pinterest app secret (optional) |
| `PINTEREST_REDIRECT_URI` | `https://yourdomain.com/auth/pinterest/callback` |
| `WORDPRESS_URL` | `https://yourwordpresssite.com` (optional) |
| `WORDPRESS_USERNAME` | your WP username (optional) |
| `WORDPRESS_APP_PASSWORD` | your WP application password (optional) |

> 💡 **Alternative:** Instead of adding variables one by one, you can copy `.env.example` to `.env` in File Manager, edit it with your values, and it will be auto-loaded.

---

### STEP 4 — Install Dependencies

In the Node.js App screen:
1. Click the **"Run NPM Install"** button

   OR if your cPanel has a Terminal:
   ```bash
   cd ~/pinboostr
   npm install
   ```

Wait for it to finish (downloads ~5MB of packages).

---

### STEP 5 — Start the App

1. Click **Start App** (or the ▶ button)
2. The status should change to **Running**
3. Visit your domain — you should see the PinBoostr login page

---

### STEP 6 — First Login

- URL: `https://yourdomain.com`
- Username: `admin`
- Password: `admin123`

⚠️ **Change your password immediately** — go to Settings → Account tab.

---

## Troubleshooting

### App won't start / shows error page

1. In cPanel Node.js App, click **Restart**
2. Check the **error log** — in cPanel go to Logs → Error Log and look for Node.js errors
3. Make sure `server.js` is in the application root (not inside a subfolder)

### "Cannot find module" error

Run NPM install again — the `node_modules` folder may be missing.

### Session not working / keeps logging out

Make sure `NODE_ENV=production` is set in environment variables.

### Pinterest OAuth redirect fails

Make sure `PINTEREST_REDIRECT_URI` exactly matches the redirect URI you added in your Pinterest Developer App settings.

### 404 on all pages after login

Your `.htaccess` may be blocking Node.js. In File Manager, check if there's an `.htaccess` file in your domain's `public_html` that redirects everything — you may need to exclude your app subdomain.

---

## File Permissions

If you get permission errors for the `data/` folder:

1. Go to File Manager → `pinboostr/data/`
2. Select all files → Right-click → **Change Permissions**
3. Set to `644` for files, `755` for the folder

---

## Updating the App

1. Upload new files via File Manager (overwrite existing)
2. Go to cPanel → Node.js App
3. Click **Restart**

Your `data/` folder (pins, articles, settings) is **never overwritten** — it's separate from the app code.

---

## Domain Setup Tips

**Use a subdomain** (recommended):
- Create `app.yourdomain.com` in cPanel → Subdomains
- Point the Node.js app to that subdomain
- No conflict with your main WordPress site

**Use the main domain** (if not using WordPress on same host):
- Point the app root to `public_html` or a subfolder

---

## File Structure on Server

```
/home/yourusername/
└── pinboostr/              ← Application root (set in Node.js App)
    ├── server.js           ← Startup file
    ├── package.json
    ├── .env                ← Your API keys (create from .env.example)
    ├── node_modules/       ← Created by npm install
    ├── data/               ← Your data (pins, articles, settings)
    │   ├── settings.json   ← API keys saved from Settings page
    │   ├── pins.json
    │   ├── articles.json
    │   └── ...
    └── src/
        ├── routes/
        ├── services/
        ├── middleware/
        └── models/
```
