# Balmy – Server deployment guide

Deploy Balmy on the **same VPS/cPanel server** as Bonik. Bonik uses port **3006**; Balmy uses port **3007**.

| Project | PM2 name | Port | Typical path on server |
|---------|----------|------|------------------------|
| Bonik   | `bonik`  | 3006 | `~/public_html/bonik`  |
| Balmy   | `balmy`  | 3007 | `~/public_html/balmy`  |

---

## 1. Before upload (local)

1. Copy `env.example` to `.env.production` and set values for your domain (see section 3).
2. Do **not** commit `.env.production` (ignored by `.gitignore`).

---

## 2. First-time server setup

SSH into the server (same account as Bonik, e.g. `markattystore`):

```bash
cd ~/public_html

# Upload or clone the project
git clone <your-balmy-repo-url> balmy
cd balmy

# Node 20+ recommended (same as Bonik)
npm install

# Production environment
cp env.example .env.production
nano .env.production   # set domain, JWT secrets, API URLs

# Build (loads .env.production when NODE_ENV=production)
npm run build

mkdir -p logs

# Start with PM2
npm run pm2:start
pm2 save
```

`pm2 status` should show both `bonik` (3006) and `balmy` (3007).

---

## 3. Environment variables (`.env.production`)

Minimum recommended:

```bash
NODE_ENV=production
PORT=3007

# Public site URL (your subdomain or domain for this storefront)
NEXT_PUBLIC_SITE_URL=https://your-balmy-domain.markatty.store
NEXT_PUBLIC_BASE_URL=https://your-balmy-domain.markatty.store
NEXT_PUBLIC_API_URL=https://your-balmy-domain.markatty.store

# Mobikul / Markatty (defaults in lib/config.ts point at balmy.markatty.com)
NEXT_PUBLIC_MOBIKUL_BASE_URL=https://balmy.markatty.com/mobikulhttp
NEXT_PUBLIC_MOBIKUL_API_TOKEN=your-token
NEXT_PUBLIC_COMPANY_ID=10007
NEXT_PUBLIC_MARKATTY_COMPANY_ID=10007
NEXT_PUBLIC_STORE_ID=9968
NEXT_PUBLIC_COMPANY_URL=https://balmy.markatty.com/

# Auth (change in production)
JWT_SECRET=your-long-random-secret
JWT_REFRESH_SECRET=your-long-random-refresh-secret
```

Rebuild after changing any `NEXT_PUBLIC_*` variable:

```bash
npm run build
npm run pm2:restart
```

---

## 4. Apache proxy (cPanel, same pattern as Bonik)

Bonik proxies `fantasylandtest.markatty.store` → `http://localhost:3006`.

For Balmy, create a **new subdomain** and point it to port **3007**:

1. **cPanel → Domains** → create subdomain (e.g. `balmy.markatty.store`).
2. Set document root to a new folder, e.g. `public_html/balmy-proxy`.
3. SSH:

```bash
mkdir -p ~/public_html/balmy-proxy
cat > ~/public_html/balmy-proxy/.htaccess << 'EOF'
DirectoryIndex disabled

RewriteEngine On
RewriteRule ^(.*)$ http://localhost:3007/$1 [P,L]
EOF
```

Requires `mod_proxy` and `mod_proxy_http` (same as Bonik; see Bonik `README.md`).

---

## 5. Deploy updates

```bash
cd ~/public_html/balmy
git pull
npm install
npm run build
npm run pm2:restart
```

---

## 6. PM2 commands

```bash
npm run pm2:start      # start balmy
npm run pm2:restart    # after code/env changes
npm run pm2:stop
npm run pm2:logs       # tail logs
pm2 status             # bonik + balmy
pm2 logs balmy
```

---

## 7. Troubleshooting

- **Port in use**: `ss -tlnp | grep 3007` or change `PORT` in `ecosystem.config.js` and `.htaccess` proxy URL.
- **502 / connection refused**: App not running — `pm2 status`, `npm run pm2:logs`.
- **Wrong API/data**: Check `.env.production` and run `npm run build` again after edits.
- **Bonik still works**: Each app has its own folder, port, and PM2 process; they do not conflict.
