# Royal Wellness Center — Full-Stack Project

A complete healthcare & wellness clinic website: **React (Vite + Tailwind + shadcn-style UI)** frontend, **Laravel 11** API backend, structured as one repo so it's easy to run locally and deploy to a single cPanel hosting account later.

```
royal-wellness-center/
├── frontend/        React app — public website + booking UI
├── backend/          Laravel API — admin panel + public data endpoints
├── scripts/          Build tooling (copies frontend build into Laravel's public/)
└── package.json      Root scripts that run both projects together
```

## Why this structure

Most shared cPanel hosting gives you **one document root**. Rather than needing two separate domains/subdomains, this repo is set up so a production build compiles the React app and drops it straight into `backend/public/` — Laravel then serves the website *and* the API from a single domain. Locally, they run as two separate dev servers (Vite + `artisan serve`) talking over CORS, so you still get hot-reload during development.

## Local Development

**Requirements:** Node 18+, PHP 8.2+, Composer, MySQL (or compatible).

```bash
# 1. Clone and install everything
git clone <your-repo-url> royal-wellness-center
cd royal-wellness-center
npm install                # installs root tooling (concurrently)
npm run setup               # installs frontend deps + backend deps, migrates DB, seeds data

# 2. Configure environment
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env
# edit backend/.env with your local MySQL credentials, then:
cd backend && php artisan key:generate && cd ..

# 3. Run both servers together
npm run dev
```

This starts:
- **Frontend** → `http://localhost:5173` (Vite dev server, hot reload)
- **Backend** → `http://localhost:8000` (Laravel API)

The frontend's `VITE_API_URL` in `frontend/.env` points at `http://localhost:8000/api` during development.

**Default seeded admin login** (change immediately):
- `admin@royalwellness.lk` / `ChangeMe123!`

## Building for Production (single-domain cPanel deploy)

```bash
npm run build
```

This runs `vite build` inside `frontend/`, then copies the compiled output into `backend/public/` — Laravel's own files (`index.php`, `.htaccess`, the `storage` symlink) are preserved, only previous build assets are cleared first. After this, `backend/` is a fully self-contained, deployable Laravel app that also happens to serve your React site.

## Deploying to cPanel

1. **Database**: create a MySQL database + user in cPanel → "MySQL Databases", note the credentials.
2. **Domain root**: in cPanel → "Domains", point your domain's document root at `backend/public` (this is the standard way to deploy Laravel on cPanel — never point the domain at the Laravel project root itself).
3. **Get the code onto the server** — two common options:
   - **Git Version Control** (cPanel → "Git Version Control"): point it at your repo, deploy to a path *outside* `public_html`, then symlink/configure the document root to that path's `backend/public`.
   - **Upload via File Manager / FTP**: zip the `backend/` folder (after running `npm run build` locally) and upload its contents into the directory cPanel uses as your domain root's parent.
4. **Environment**: upload `backend/.env` (based on `.env.production.example`, with your real DB credentials and `APP_URL` set to your domain) — **never commit `.env` to git**.
5. **Install PHP dependencies on the server** (via cPanel Terminal or SSH, if available):
   ```bash
   cd ~/path-to-backend
   composer install --no-dev --optimize-autoloader
   php artisan key:generate
   php artisan migrate --seed --force
   php artisan storage:link
   php artisan config:cache
   php artisan route:cache
   ```
   If your cPanel plan has no terminal/SSH access, run `composer install --no-dev` locally and upload the generated `vendor/` folder instead — just make sure the PHP version matches what cPanel runs.
6. **PHP version**: in cPanel → "MultiPHP Manager", set your domain to PHP 8.2 or higher.
7. **Permissions**: ensure `storage/` and `bootstrap/cache/` are writable by the web server (`chmod -R 775` is usually enough on cPanel).
8. **Cron** (optional, for Laravel's scheduler if you add any later): add `* * * * * cd /path-to-backend && php artisan schedule:run >> /dev/null 2>&1` under cPanel → "Cron Jobs".

After this, visiting your domain serves the React site; `https://yourdomain.com/api/*` serves the Laravel API; and `https://yourdomain.com/api/admin/*` is the authenticated admin panel API (you'd build or point an admin SPA at these same endpoints — the routes are all there and documented in `backend/README.md`).

## Updating the live site later

Whenever you push changes:
```bash
git pull
npm run build              # rebuilds frontend, re-copies into backend/public
cd backend
composer install --no-dev --optimize-autoloader   # if backend deps changed
php artisan migrate --force                          # if you added migrations
php artisan config:cache
```

## Project-specific docs

- `frontend/README.md` — component structure, design tokens, page-by-page breakdown
- `backend/README.md` — full API reference, module-by-module backend notes, security details (e.g. the gallery consent safeguard)
