# 🏥 HealthVibe Agency — Full Stack Web Project

A complete health agency platform built with **HTML, CSS, Bootstrap 5, Vanilla JavaScript, PHP (REST API), and MySQL**.

---

## 📁 Project Structure

```
healthagency/
├── frontend/                        ← All HTML/CSS/JS files
│   ├── index.html                   ← Home / Landing Page
│   ├── assets/
│   │   ├── css/style.css            ← Global design system
│   │   ├── js/api.js                ← Centralized API client + Cart
│   │   └── js/layout.js             ← Navbar + Footer injection
│   └── pages/
│       ├── about.html               ← About, Mission, Vision, Values
│       ├── events.html              ← Upcoming & past events
│       ├── classes.html             ← Online classes + Paystack enroll
│       ├── shop.html                ← Product listing + search/filter
│       ├── cart.html                ← Cart + Checkout + Paystack
│       ├── login.html               ← Login
│       ├── register.html            ← Register
│       ├── dashboard.html           ← User dashboard (classes + orders)
│       └── admin/
│           ├── index.html           ← Admin dashboard (stats)
│           ├── classes.html         ← Manage classes (CRUD)
│           ├── products.html        ← Manage products (CRUD)
│           ├── events.html          ← Manage events (CRUD)
│           ├── orders.html          ← Manage & update orders
│           └── users.html           ← View registered users
│
└── backend/                         ← PHP REST API
    ├── index.php                    ← Main router
    ├── .htaccess                    ← URL rewriting
    ├── config/
    │   ├── config.php               ← App config (JWT, Paystack keys)
    │   ├── database.php             ← PDO connection
    │   └── schema.sql               ← Full MySQL database schema
    ├── helpers/
    │   ├── response.php             ← sendSuccess() / sendError()
    │   └── jwt.php                  ← JWT encode/decode
    ├── middleware/
    │   ├── cors.php                 ← CORS headers
    │   └── auth.php                 ← requireAuth() / requireAdmin()
    └── api/
        ├── auth/AuthController.php  ← Register, Login, Me
        ├── events/EventController.php
        ├── classes/ClassController.php
        ├── products/ProductController.php
        ├── orders/OrderController.php
        ├── payments/PaymentController.php
        └── admin/AdminController.php
```

---

## ⚙️ WAMP Server Setup (Step by Step)

### Step 1 — Install WAMP
Download from: https://www.wampserver.com
Install and start WAMP. The icon in the system tray should turn **green**.

### Step 2 — Copy the project
Copy the entire `healthagency/` folder into:
```
C:\wamp64\www\healthagency\
```
Your folder should look like:
```
C:\wamp64\www\healthagency\frontend\
C:\wamp64\www\healthagency\backend\
```

### Step 3 — Enable Apache mod_rewrite
1. Click the WAMP icon in the system tray
2. Go to **Apache → Apache Modules**
3. Make sure **rewrite_module** is ticked ✅
4. WAMP will restart automatically

### Step 4 — Create the database
1. Open your browser and go to: http://localhost/phpmyadmin
2. Login (default: username = `root`, password = empty)
3. Click **New** on the left sidebar
4. Create a database called: `health_agency`
5. Click on the `health_agency` database
6. Click the **SQL** tab at the top
7. Open the file `backend/config/schema.sql` in a text editor
8. Copy all the SQL and paste it into phpMyAdmin
9. Click **Go** to run it

### Step 5 — Configure the backend
Open `backend/config/config.php` and update:
```php
define('JWT_SECRET', 'your-very-long-random-secret-string');
define('PAYSTACK_SECRET_KEY', 'sk_test_YOUR_KEY_HERE');
define('PAYSTACK_PUBLIC_KEY', 'pk_test_YOUR_KEY_HERE');
```
> Get Paystack test keys from: https://dashboard.paystack.com/#/settings/developers

### Step 6 — Update Paystack public key in frontend
Search and replace `pk_test_YOUR_PAYSTACK_PUBLIC_KEY_HERE` in:
- `frontend/pages/classes.html`
- `frontend/pages/cart.html`

### Step 7 — Test the project
Open your browser and visit:
```
http://localhost/healthagency/frontend/index.html
```

**Admin login:**
- Email: `admin@healthagency.com`
- Password: `Admin@1234`
- ⚠️ Change this after first login!

---

## 🌐 cPanel / Live Hosting Setup

### Step 1 — Upload files
Upload the entire `healthagency/` folder to your hosting `public_html/` directory via FTP or File Manager.

### Step 2 — Create MySQL Database
1. Go to cPanel → **MySQL Databases**
2. Create a new database: e.g. `youruser_healthagency`
3. Create a database user and assign it to the database with **All Privileges**
4. Import `backend/config/schema.sql` via cPanel → phpMyAdmin

### Step 3 — Update database credentials
Edit `backend/config/database.php`:
```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'youruser_healthagency');  // your cPanel DB name
define('DB_USER', 'youruser_dbuser');        // your DB username
define('DB_PASS', 'your_db_password');       // your DB password
```

### Step 4 — Update API base URL
Edit `frontend/assets/js/api.js`, change line 7:
```js
// From:
const API_BASE = 'http://localhost/healthagency/backend';

// To:
const API_BASE = 'https://yourdomain.com/healthagency/backend';
```

### Step 5 — Update CORS
Edit `backend/config/config.php`:
```php
define('ALLOWED_ORIGINS', [
    'https://yourdomain.com',
]);
```

---

## 🔑 API Endpoints Reference

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | /auth/register | ❌ | Register new user |
| POST | /auth/login | ❌ | Login, returns JWT |
| GET | /auth/me | ✅ | Get logged-in user info |
| GET | /events | ❌ | List events (?status=upcoming\|past) |
| GET | /events/{id} | ❌ | Single event |
| GET | /classes | ❌ | List all active classes |
| GET | /classes/{id} | ❌ | Single class detail |
| POST | /classes/enroll | ✅ | Enroll (with payment_ref) |
| GET | /classes/mine | ✅ | My enrolled classes |
| GET | /products | ❌ | List products (?search=&category=&featured=1) |
| GET | /products/{id} | ❌ | Single product |
| POST | /orders | ✅ | Create order (with payment_ref) |
| GET | /orders/mine | ✅ | My orders |
| POST | /payments/verify | ✅ | Verify Paystack payment |
| GET | /admin/stats | 🔐 | Dashboard stats |
| GET/POST | /admin/classes | 🔐 | List/create classes |
| PUT/DELETE | /admin/classes/{id} | 🔐 | Update/delete class |
| GET/POST | /admin/products | 🔐 | List/create products |
| PUT/DELETE | /admin/products/{id} | 🔐 | Update/delete product |
| GET/POST | /admin/events | 🔐 | List/create events |
| PUT/DELETE | /admin/events/{id} | 🔐 | Update/delete event |
| GET | /admin/orders | 🔐 | List all orders |
| PUT | /admin/orders/{id} | 🔐 | Update order status |
| GET | /admin/users | 🔐 | List all users |

> ✅ = Requires user JWT | 🔐 = Requires admin JWT

---

## 💳 Paystack Payment Flow

1. User clicks **Enroll** or **Checkout**
2. Paystack popup opens (handled by `PaystackPop.setup()`)
3. User pays with card/bank/USSD
4. Paystack calls `callback` with a `reference`
5. Frontend sends `reference` to the PHP API
6. PHP calls `https://api.paystack.co/transaction/verify/{reference}`
7. If verified → enrollment/order is created in DB ✅

---

## 🛡️ Security Features

- Passwords hashed with `password_hash()` (bcrypt, cost 12)
- JWT tokens for stateless authentication
- PDO prepared statements (SQL injection protection)
- Admin routes protected with `requireAdmin()` middleware
- CORS configured per environment
- Client-side prices **never trusted** — prices always fetched from DB

---

## 🎨 Design Colors

| Variable | Color | Usage |
|----------|-------|-------|
| `--primary` | `#1a7f5e` | Main green brand color |
| `--accent` | `#f4a24a` | Orange accent / CTAs |
| `--dark` | `#0f1c17` | Dark backgrounds |
| `--text` | `#2d3b35` | Body text |

---

## 📦 Dependencies (all CDN — no npm needed)

- Bootstrap 5.3.3
- Bootstrap Icons 1.11.3
- Paystack JS (`https://js.paystack.co/v1/inline.js`)
- Google Fonts (Playfair Display + DM Sans)

---

Built for **WAMP / cPanel hosting** with pure PHP — no Laravel, no Composer required.
