# Pep's Restaurant — Production Deployment Guide
## Subdomain: peps.impactcareerpoint.com

---

## Credentials Summary
| Item | Value |
|------|-------|
| cPanel User | `impactca_peps` |
| Database Name | `impactca_pepspizza` |
| DB User | `impactca_peps` |
| Subdomain | `peps.impactcareerpoint.com` |

---

## Step 1 — Upload Files

Upload the contents of `peps_pizza_production/` to your hosting.
Recommended structure on the server:
```
/home/impactca_peps/
  peps_pizza/
    backend/
    frontend/
```

---

## Step 2 — Create the MySQL Database (cPanel)

1. Log into cPanel → **MySQL Databases**
2. Create database: `impactca_pepspizza`
3. Create user: `impactca_peps` with a strong password
4. Add user to database with **ALL PRIVILEGES**

---

## Step 3 — Configure Backend

1. In `backend/`, rename `.env.production` → `.env`
2. Fill in:
   - `DB_PASSWORD` — the password you set in cPanel
   - `JWT_SECRET` — run this to generate one:
     ```bash
     node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
     ```
   - `CORS_ORIGIN` — `https://peps.impactcareerpoint.com`

3. Install dependencies:
   ```bash
   cd backend
   npm install --omit=dev
   ```

4. Run database migrations + seed:
   ```bash
   npm run db:migrate
   npm run db:seed
   ```
   This creates all tables and seeds the admin user (`admin` / `Admin@1234`) and menu items.

5. **Change the admin password** after first login!

---

## Step 4 — Configure Frontend

1. In `frontend/`, the `.env.production.local` file is already configured.
2. Update `NEXT_PUBLIC_WA_NUMBER` with the real WhatsApp number.
3. Install dependencies and build:
   ```bash
   cd frontend
   npm install --omit=dev
   npm run build
   ```

---

## Step 5 — Start the Backend (Node.js App)

In cPanel → **Node.js App** (or use PM2 if available):

```bash
cd backend
npm start
```

With PM2 (recommended for production):
```bash
npm install -g pm2
pm2 start server.js --name "peps-backend"
pm2 save
pm2 startup
```

---

## Step 6 — Start the Frontend (Next.js)

```bash
cd frontend
npm start
# Runs on port 3000 by default
```

With PM2:
```bash
pm2 start "npm start" --name "peps-frontend" --cwd ./frontend
pm2 save
```

---

## Step 7 — Configure Subdomain & Reverse Proxy

In cPanel → **Subdomains**, create:
- Subdomain: `peps`
- Domain: `impactcareerpoint.com`
- Document root: `/home/impactca_peps/peps_pizza/frontend`

Then in cPanel → **.htaccess** or **Apache/Nginx config**, add a reverse proxy:

```apache
# .htaccess for Next.js reverse proxy
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:3000/$1 [P,L]
```

For the API, add to your Node.js app config or `.htaccess`:
```apache
RewriteRule ^api/(.*)$ http://localhost:4000/api/$1 [P,L]
```

---

## Default Admin Credentials
- **URL**: `https://peps.impactcareerpoint.com/admin`
- **Username**: `admin`
- **Password**: `Admin@1234`
- ⚠️ Change this immediately after first login!

---

## File Structure on Server
```
backend/
  src/
    config/
      popups.json        ← popup settings (writable)
      reviews.json       ← customer reviews (writable)
      reviews-config.json ← display mode (writable)
  public/
    uploads/             ← menu item images (writable)
  .env                   ← production env (never commit)

frontend/
  .next/                 ← built output (after npm run build)
  public/
    logo.jpeg            ← restaurant logo
  .env.production.local  ← production env (never commit)
```

---

## Important Notes

1. The `backend/src/config/` folder must be **writable** by the Node.js process (for popups, reviews, announcements).
2. The `backend/public/uploads/` folder must be **writable** for menu image uploads.
3. Always use **HTTPS** in production — get a free SSL cert via cPanel → Let's Encrypt.
4. The `next.config.js` proxy rewrites are for development only. In production, the frontend calls `NEXT_PUBLIC_API_URL` directly.
