# BrightMinds Deployment Guide
## kids.dsolk.com + admin.kids.dsolk.com

---

## 1. cPanel: Create the Database

1. Log in to **dsolk.com cPanel**
2. Go to **MySQL Databases**
3. Create database: `dsolk_brightminds`
4. Create user: `dsolk_bmuser` (strong password)
5. Add user to database → give **ALL PRIVILEGES**
6. Go to **phpMyAdmin** → select `dsolk_brightminds`
7. Click **Import** → upload `db/install.sql` → click Go
8. Confirm the verification SELECT at the bottom shows correct row counts

---

## 2. Edit api/config.php

Open `api/config.php` and fill in your real credentials:

```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'dsolk_brightminds');
define('DB_USER', 'dsolk_bmuser');
define('DB_PASS', 'YOUR_REAL_PASSWORD');
define('JWT_SECRET',       'RANDOM_32_CHAR_STRING_CHANGE_THIS');
define('ADMIN_JWT_SECRET', 'DIFFERENT_RANDOM_STRING_FOR_ADMIN');
```

Generate random strings at: https://www.random.org/passwords/?num=1&len=40&format=plain

---

## 3. cPanel: Create Subdomains

### kids.dsolk.com
1. cPanel → **Subdomains**
2. Subdomain: `kids`, Domain: `dsolk.com`
3. Document Root: `public_html/kids`
4. Click Create

### admin.kids.dsolk.com
1. Subdomain: `admin.kids`, Domain: `dsolk.com`
2. Document Root: `public_html/kids-admin`
3. Click Create

---

## 4. Upload Files

### kids.dsolk.com → `public_html/kids/`

Upload these folders/files to `public_html/kids/`:

```
public_html/kids/
├── index.html          ← landing/index.html
├── .htaccess           ← landing/.htaccess
├── api/                ← entire api/ folder
│   ├── config.php      ← (with your real DB credentials)
│   ├── auth.php
│   ├── quiz.php
│   ├── user.php
│   ├── leaderboard.php
│   ├── admin.php
│   ├── genhash.php     ← UPLOAD, USE ONCE, THEN DELETE
│   └── .htaccess
└── app/                ← entire app/ folder
    ├── index.html
    ├── app.js
    ├── style.css
    ├── sw.js
    ├── manifest.json
    ├── .htaccess
    └── icons/
        ├── icon-192.png    ← add your own icon
        └── icon-512.png    ← add your own icon
```

### admin.kids.dsolk.com → `public_html/kids-admin/`

Upload:
```
public_html/kids-admin/
├── index.html          ← admin/index.html
└── .htaccess           ← admin/.htaccess
```

---

## 5. Fix the Admin Password

1. Visit: `https://kids.dsolk.com/api/genhash.php?pw=YourDesiredPassword`
2. Copy the hash
3. In phpMyAdmin, run:
```sql
UPDATE admins
SET password_hash = '$2y$12$...(paste hash here)...'
WHERE email = 'admin@dsolk.com';
```
4. **Delete** `genhash.php` from the server immediately!

---

## 6. Add App Icons

The app needs two icon files:
- `public_html/kids/app/icons/icon-192.png` (192×192 px)
- `public_html/kids/app/icons/icon-512.png` (512×512 px)

Use any image editor to create a simple star/book icon, or generate at:
https://realfavicongenerator.net/

---

## 7. Test Everything

### Checklist:
- [ ] Landing page loads: https://kids.dsolk.com/
- [ ] API health: https://kids.dsolk.com/api/quiz.php?action=streams
- [ ] App loads: https://kids.dsolk.com/app/
- [ ] Register a test student account
- [ ] Login works
- [ ] Browse stages → subjects → worksheets
- [ ] Take a quiz and see results
- [ ] Leaderboard shows up
- [ ] Admin panel loads: https://admin.kids.dsolk.com/
- [ ] Admin login works (after fixing password in Step 5)
- [ ] Admin dashboard shows stats
- [ ] Admin can bump version (Cache & Version page)
- [ ] After bumping, student app shows update banner

### Quick API test (paste in browser):
```
https://kids.dsolk.com/api/quiz.php?action=streams
```
Should return JSON with `"ok":true` and a list of streams.

---

## 8. Fix admin panel API URL

Open `admin/index.html`, line ~250:
```js
const API = 'https://kids.dsolk.com/api';
```
This is already correct — just confirm your domain matches.

---

## 9. Enable SSL (HTTPS)

1. cPanel → **SSL/TLS Status** or **Let's Encrypt**
2. Enable for: `kids.dsolk.com` and `admin.kids.dsolk.com`
3. Force HTTPS redirect (add to root `.htaccess`):
```apache
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

---

## File Structure Summary

```
dsolk.com cPanel:
└── public_html/
    ├── kids/                  ← kids.dsolk.com
    │   ├── index.html         (landing page)
    │   ├── .htaccess
    │   ├── api/               (PHP backend)
    │   └── app/               (student PWA)
    └── kids-admin/            ← admin.kids.dsolk.com
        ├── index.html         (admin panel)
        └── .htaccess
```

---

## Troubleshooting

| Problem | Fix |
|---------|-----|
| API returns "Database connection failed" | Check DB credentials in config.php |
| Admin login says "Incorrect credentials" | Run genhash.php and update the hash in DB |
| CORS error in browser console | Check ALLOWED_ORIGINS in config.php |
| 403 on /api/ | Check .htaccess, make sure PHP is enabled |
| Service worker not registering | Must be on HTTPS |
| Icons not showing (PWA install) | Add icon-192.png and icon-512.png to /app/icons/ |
