# Artisan 2nd Brain — Namecheap cPanel Node.js (24.22.3) Deployment Package

Deploy **Artisan 2nd Brain** (`artisan.ljwellness.net`) directly on Namecheap cPanel Node.js—no Cloud Run or Docker required.

---

## 1. Files Required on cPanel (`artisan.ljwellness.net` Application Root)

Upload the project package (excluding `node_modules/` and `.git/`):
- `app.js` *(cPanel Passenger startup entrypoint — automatically forces `NODE_ENV=production` and runs `dist-server/server.cjs`)*
- `package.json` & `package-lock.json`
- `server.ts`, `index.html`, `vite.config.ts`, `tsconfig.json`, `firebase-applet-config.json`
- `src/`, `components/`, `lib/`, `public/`
- `dist/` and `dist-server/` *(required when uploading a locally built package; includes `dist/index.html` and `dist-server/server.cjs`)*
- `CPANEL_DEPLOYMENT_GUIDE.md`

Never include `node_modules/`, `.git/`, `.env*`, service-account JSON, private keys, or other credentials in the upload ZIP.

---

## 2. Namecheap cPanel → Setup Node.js App Settings

- **Node.js version:** `24.22.3`
- **Application mode:** `Production`
- **Application root:** e.g. `artisan.ljwellness.net` (or your chosen app folder above `public_html`)
- **Application URL:** `artisan.ljwellness.net`
- **Application startup file:** `app.js`

---

## 3. Build & Startup Commands

### If building on cPanel (via Terminal or **Run NPM Install** + SSH):
```bash
npm install --include=dev
npm run build
```
- `npm install --include=dev` installs build tools (`vite`, `esbuild`) even when `NODE_ENV=production` is active in cPanel.
- `npm run build` compiles:
  1. Static frontend bundle → `dist/` (`dist/index.html`, `dist/assets/*`)
  2. Standalone CommonJS Express server → `dist-server/server.cjs`

### Production Start Command:
- **cPanel Passenger:** Automatically runs **`app.js`** (which loads `dist-server/server.cjs`).
- **Manual / CLI test (`npm start`):**
  ```bash
  node app.js
  ```
- **Verify locally/over SSH after starting:**
  ```bash
  curl https://artisan.ljwellness.net/api/storefront/health
  ```

---

## 4. Required & Optional Environment Variables (Set in cPanel UI — Zero Secrets in Code)

Add required values under **cPanel → Setup Node.js App → Environment Variables**. Do not place a `.env` file or service-account JSON in the application root or upload ZIP.

| Variable Name | Required? | Purpose | Example / Notes |
|---|---|---|---|
| `NODE_ENV` | Yes | Enables static `dist/` serving & disables dev Vite middleware | `production` |
| `APP_URL` | Yes | Public origin for Artisan 2nd Brain & Storefront handoff | `https://artisan.ljwellness.net` |
| `ARTISAN_APP_DOMAIN` | Recommended | Canonical studio hostname | `artisan.ljwellness.net` |
| `GEMINI_API_KEY` | Yes (for AI agents) | Server-side Gemini API key (`@google/genai`) | Your Gemini API key |
| `FIREBASE_SERVICE_ACCOUNT_JSON` | Yes for server-side Firestore writes on cPanel | Lets Express persist Storefront events and internal records from outside GCP | Configure securely in cPanel; never commit or ZIP the value |
| `GOOGLE_APPLICATION_CREDENTIALS` | Alternative to above | Path to a private service-account file stored outside the web root | Keep the file outside `public_html`, restrict file permissions, and never ZIP it |
| `STOREFRONT_URL` | Yes | HTTPS origin of the Storefront website | `https://staging.ljwellness.net` or `https://ljwellness.net` |
| `STOREFRONT_BRIDGE_KEY` | Yes | Shared server-to-server `X-Bridge-Key` matching `STUDIOOS_BRIDGE_KEY` on Storefront | 32+ char random string |
| `STOREFRONT_HMAC_SECRET` | Yes | Shared HMAC-SHA256 secret matching `STUDIOOS_HMAC_SECRET` on Storefront (±300s replay guard) | 32+ char random string |
| `EXEC_OS_URL` | Optional | Personal Executive OS bridge URL | Existing Cloud Run URL |
| `EXEC_OS_BRIDGE_KEY` | Optional | Personal Executive OS partner key | Leave empty if unused |
| `BRIDGE_INBOUND_KEY` | Optional | Inbound key for `/api/bridge/inbound` | Leave empty if unused |
| `BRIDGE_HMAC_SECRET` | Optional | HMAC secret for `/api/bridge/*` | Leave empty if unused |
| `BRIDGE_APP_NAME` | Optional | Label returned in bridge metadata | `Artisan 2nd Brain (LJWellness)` |

> **Do NOT set `PORT` in cPanel** unless troubleshooting manually—Phusion Passenger automatically assigns `process.env.PORT` (port or UNIX socket), and `server.ts` now supports both natively.

The Firebase Admin SDK bypasses Firestore Security Rules. Use a dedicated service account with only the required Firestore data access (`roles/datastore.user`) and Firebase Authentication user lookup access (`roles/firebaseauth.viewer`). Do not grant Editor, Owner, or Firebase Admin. Store the credential in cPanel environment variables; never send it in chat or include it in a deployment ZIP. Keep the existing Firebase project and configured Firestore database ID unchanged.

All Storefront bridge URLs must use HTTPS. Artisan rejects HTTP URLs because bridge requests carry authentication headers.

---

## 5. Final 2-Minute Firebase Checklist (Free — No Cloud Run Needed)

1. **Authorized Domains (for Google Sign-In on `artisan.ljwellness.net`):**
   - Open Firebase Console (`Arts2Brain` · `gen-lang-client-0727187674`) → **Authentication → Settings → Authorized domains** → Add `artisan.ljwellness.net`.
2. **Staff Access Lock:**
   - The UI opens directly on a private **Sign-In Page** (`SignInPage.tsx`) gated to:
     - `mdominique1025@gmail.com`
     - `myrnad@ljwellness.net`
     - `info@ljwellness.net`
     - `artisan@ljwellness.net`
   - All `/api/storefront/*` bridge calls stay protected server-to-server by `X-Bridge-Key`, `X-Bridge-Timestamp` (±300s), and `X-Bridge-Signature` (HMAC-SHA256).
