# CoreERP — System Health Check

> **Run this checklist after every deployment and at least once per week in production.**  
> Date prepared: 2026-07-14

---

## How to use

Work through each item in order. Mark `[x]` when confirmed. Investigate and resolve any `[ ]` before declaring the system healthy.

---

## 1. Application Overview

```bash
php artisan about
```

**What to check:**
- Environment shows `production`
- Debug mode shows `false`
- Cache shows the configured driver (should be `database` or `redis`)
- Queue shows the configured driver

---

## 2. Migration Status

```bash
php artisan migrate:status
```

**What to check:**
- All migrations show `Ran` status.
- No migration shows `Pending` — if any are pending, run `php artisan migrate` after taking a database backup.

**Current state (2026-07-14):** 62 migrations — all `Ran`.

---

## 3. Route List Sanity Check

```bash
php artisan route:list
```

**What to check:**
- Routes are listed without errors.
- Dashboard route is present: `GET dashboard`.
- No duplicate or conflicting routes.

Quick dashboard check:

```bash
php artisan route:list | grep -i dashboard
```

---

## 4. Permission Cache Reset

```bash
php artisan permission:cache-reset
```

Run after:
- Any deployment that updated `PhaseOneSeeder`.
- Any role/permission change.
- After `php artisan optimize:clear`.

**Expected output:** `Permission cache flushed.`

---

## 5. Dashboard Login Test

- [ ] Navigate to `https://yourdomain.com/login`.
- [ ] Log in with a known user account.
- [ ] Confirm the dashboard loads without a 500 error.
- [ ] Confirm sidebar menu items are visible and match the user's role.
- [ ] Confirm sales, purchase, and inventory counts are displayed.

---

## 6. Storage Link Test

```bash
ls -la public/storage
```

**Expected output:** A symlink pointing to `../storage/app/public`.

If missing, recreate it:

```bash
php artisan storage:link
```

- [ ] Company logo visible in header (served from `public/storage/` or `public/company/`).
- [ ] File uploads (if any) accessible via the browser.

---

## 7. Print Document Test

Manually navigate to and print at least one of each critical document type:

- [ ] Tax Invoice print view loads without PHP errors.
- [ ] Delivery Note print view loads.
- [ ] Gate Pass print view loads.
- [ ] Purchase Order print view loads.
- [ ] All print pages use the correct company header/logo.

---

## 8. Backup Restore Test (Monthly)

At least once per month:

- [ ] Take a database dump using `scripts/backup_mysql_example.sh`.
- [ ] Restore the dump to a **local or staging** MySQL database.
- [ ] Boot the application against the restored database.
- [ ] Confirm key tables have expected row counts (customers, tax_invoices, stock_movements).
- [ ] Log in and check dashboard stats match expectations.

---

## 9. Browser Console Check (Dashboard Charts)

Open the dashboard in a browser and open Developer Tools (F12):

- [ ] No JavaScript errors in the Console tab.
- [ ] No failed network requests in the Network tab (look for 404 or 500 responses).
- [ ] Dashboard KPI charts and summary cards render correctly.
- [ ] No mixed-content warnings (if running HTTPS).

---

## 10. APP_DEBUG=false Verification

Trigger a deliberate 404 in the browser (e.g., visit `/this-page-does-not-exist`):

- [ ] A generic error page is shown — **not** a Laravel debug stack trace.
- [ ] No `.env` values, database credentials, or file paths are visible in the browser.

If a stack trace appears, `APP_DEBUG` is still `true` — set it to `false` immediately and run:

```bash
php artisan config:cache
```

---

## 11. Optional: Clear and Re-cache (After Config Changes)

```bash
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

---

## 12. Log Review

```bash
tail -n 100 storage/logs/laravel.log
```

- [ ] No `ERROR` or `CRITICAL` level entries from the current day.
- [ ] Recent entries are informational only.

---

## Health Check Summary Table

| # | Check | Status |
|---|-------|--------|
| 1 | `php artisan about` — production env, debug off | [ ] |
| 2 | `php artisan migrate:status` — all Ran | [ ] |
| 3 | `php artisan route:list` — dashboard route present | [ ] |
| 4 | `php artisan permission:cache-reset` — no errors | [ ] |
| 5 | Dashboard login works | [ ] |
| 6 | Storage symlink exists | [ ] |
| 7 | Print documents load correctly | [ ] |
| 8 | Backup restore tested (monthly) | [ ] |
| 9 | Browser console clean | [ ] |
| 10 | APP_DEBUG=false confirmed | [ ] |
| 11 | Caches rebuilt if config changed | [ ] |
| 12 | No errors in laravel.log | [ ] |

---

*Prepared as part of Phase 15A-15C — Backup & Deployment Preparation.*
