# Production Readiness Report — SMK Platform

**التاريخ:** 5 يونيو 2026  
**النطاق:** المرحلة A — Backend + Customer App + Merchant App + Production Infrastructure  
**الحالة:** مكتملة تقنياً — جاهزة للـ **Staging/Beta** — **Google Play Internal Testing** بعد checklist يدوي

---

## ملخص تنفيذي

| المكوّن | الجاهزية الفعلية | Hosting | Google Play | App Store |
|---------|------------------|---------|-------------|-----------|
| **Backend API** | **78%** | ✅ Staging | N/A | N/A |
| **Customer App** | **72%** | N/A | ⚠️ Internal Test | ❌ |
| **Merchant App** | **70%** | N/A | ⚠️ Internal Test | ❌ |
| **Production Infrastructure** | **75%** | ✅ بعد `.env` | ⚠️ | ❌ |

**الخلاصة:** المرحلة A **مُنفَّذة**. المشروع **جاهز للرفع على استضافة Staging/Production** بعد نسخ `.env.production.example` وتشغيل migrations. **Google Play Internal Testing** ممكن فوراً بعد checklist. **App Store** يحتاج APNs + TestFlight (لم يُنفَّذ في هذه المرحلة).

---

## 1. ما تم إصلاحه / تنفيذه

### Backend Laravel

| # | البند | الحالة |
|---|-------|--------|
| ✅ | `.env.example` شامل + `.env.production.example` + `.env.staging.example` | منفّذ |
| ✅ | `config/smk.php` — domain, HTTPS, rate limits, Sanctum | منفّذ |
| ✅ | `SMK_FORCE_HTTPS` + `ForceHttps` middleware + `URL::forceScheme` | منفّذ |
| ✅ | Rate limiting: login, register, password reset, checkout | منفّذ |
| ✅ | Checkout IDOR — `address_id` scoped to customer | منفّذ |
| ✅ | Sanctum token expiration (30 days default) | منفّذ |
| ✅ | Trust proxies | منفّذ |
| ✅ | `marketplace.order_statuses` — central logistics states | منفّذ |
| ✅ | إزالة `driver.rating: 4.9` الثابت | منفّذ |
| ✅ | Route drift — merchant `low-stock` route → query param; حذف `fetchCustomer` الميت | منفّذ |
| ✅ | PHPUnit: 9 tests, 37 assertions — **كلها PASS** | منفّذ |
| ✅ | E2E: register → checkout → accept → prepare → ready → send-to-central → commission | منفّذ |

### Customer App (`smk_customer`)

| # | البند | الحالة |
|---|-------|--------|
| ✅ | `SmkApiConfig` — dev / staging / production via `--dart-define=APP_ENV` | منفّذ |
| ✅ | `config/env/{dev,staging,production}.json` | منفّذ |
| ✅ | Release manifest — **بدون cleartext** (debug فقط) | منفّذ |
| ✅ | Release signing — keystore + `key.properties` (gitignored) | منفّذ |
| ✅ | AAB build config — `flutter build appbundle --dart-define=APP_ENV=production` | منفّذ |

### Merchant App (`smk_merchant`)

| # | البند | الحالة |
|---|-------|--------|
| ✅ | Firebase — `flutterfire configure`, `google-services.json`, `isConfigured=true` | منفّذ |
| ✅ | Google Services Gradle plugin | منفّذ |
| ✅ | Android Manifest — INTERNET, POST_NOTIFICATIONS | منفّذ |
| ✅ | Network security — cleartext في debug فقط | منفّذ |
| ✅ | Push — FCM + device register + deep link للطلبات | منفّذ (كود) |
| ✅ | `SmkApiConfig` + env JSON files | منفّذ |
| ✅ | Release signing + AAB config | منفّذ |
| ✅ | `docs/BETA_TESTING_CHECKLIST_MERCHANT.md` | منفّذ |

### Production Infrastructure

| # | البند | الحالة |
|---|-------|--------|
| ✅ | Shared keystore `android/smk-release.keystore` | منفّذ |
| ✅ | `android/README.md` — تعليمات التوقيع | منفّذ |
| ✅ | Gitignore — secrets, keystore, key.properties | تم |
| ✅ | `phpunit.xml` — `APP_URL=http://localhost` (إصلاح WAMP path في tests) | تم |

---

## 2. المشاكل المتبقية

### P1 — قبل Beta موسّعة

| # | المشكلة | التأثير |
|---|---------|---------|
| 1 | **Checklist يدوي** — لم يُنفَّذ على أجهزة حقيقية بعد | لا Go/No-Go رسمي |
| 2 | **FCM Service Account** على السيرفر — يحتاج رفع يدوي | Push production |
| 3 | **SPF/DKIM** للبريد | OTP قد لا يصل Gmail |
| 4 | **iOS** — APNs + `GoogleService-Info.plist` + TestFlight | App Store |
| 5 | **Pagination** في التطبيقين | قوائم كبيرة |
| 6 | **401 global handler** في Flutter | token منتهي |
| 7 | **Checkout error state** (عناوين) — Customer | UX |
| 8 | **إلغاء الطلب لا يُعيد المخزون** — Backend | stock leak |
| 9 | **Wallet top-up يدوي** | ops dependency |

### P2 — بعد Beta

| # | المشكلة |
|---|---------|
| 1 | وصف المنتج في API |
| 2 | Merchant: رفع مستندات KYC UI |
| 3 | Merchant: timeline على تفاصيل الطلب |
| 4 | Store listing (screenshots, privacy URL) |
| 5 | Feature tests إضافية (rate limit, push mock) |

---

## 3. نسب الجاهزية التفصيلية

### Customer App — **72%**

| المحور | % |
|--------|---|
| Features / E2E path | 95% |
| Production API config | 90% |
| Android release packaging | 85% |
| Push (Android) | 80% |
| iOS production | 20% |
| QA checklist executed | 0% |
| Store listing | 10% |

### Merchant App — **70%**

| المحور | % |
|--------|---|
| Features / API coverage | 85% |
| Firebase / Push setup | 85% |
| Production API config | 90% |
| Android release packaging | 85% |
| iOS production | 20% |
| QA checklist executed | 0% |
| Store listing | 10% |

### Backend API — **78%**

| المحور | % |
|--------|---|
| API completeness | 90% |
| Security hardening (Phase A) | 80% |
| Order workflow | 95% |
| Automated tests | 55% |
| Production env docs | 90% |
| Ops (mail, queue, monitoring) | 50% |

### Production Infrastructure — **75%**

| المحور | % |
|--------|---|
| Env templates | 95% |
| HTTPS enforcement config | 90% |
| Signing / AAB | 85% |
| Server deployed | 0% (يحتاج رفع) |
| CI/CD | 0% |
| Monitoring / backups | 30% |

---

## 4. هل جاهز للرفع على الاستضافة؟

### ✅ **نعم — Staging/Production** بعد:

1. نسخ `.env.production.example` → `.env` على السيرفر
2. `php artisan key:generate`
3. `php artisan migrate --force`
4. `php artisan storage:link`
5. رفع FCM credentials إلى `storage/app/firebase/`
6. ضبط `APP_URL=https://api.smkiraq.com` (document root = `public/`)
7. SSL certificate على `api.smkiraq.com`

**ملاحظة WAMP → Production:**  
- Dev: `https://domain/smk/public/api/v1`  
- Production: document root = `public/` → `https://api.smkiraq.com/api/v1`  
- Flutter: `--dart-define=APP_ENV=production`

---

## 5. هل جاهز لـ Google Play؟

### ⚠️ **Internal Testing — نعم** | **Production — لا بعد**

**جاهز:**
- Release AAB signing (keystore)
- Production API config
- Firebase Android (كلا التطبيقين)
- Cleartext disabled in release

**مطلوب قبل Production track:**
- [ ] تشغيل `BETA_TESTING_CHECKLIST.md` + `BETA_TESTING_CHECKLIST_MERCHANT.md`
- [ ] 0 crash في مسار الطلب الكامل
- [ ] Push E2E على جهاز حقيقي
- [ ] Store listing + privacy policy URL
- [ ] Play Console — app content, data safety

**أوامر البناء:**

```bash
cd smk_customer
flutter build appbundle --dart-define=APP_ENV=production --release

cd ../smk_merchant
flutter build appbundle --dart-define=APP_ENV=production --release
```

---

## 6. هل جاهز لـ App Store?

### ❌ **لا**

- iOS Firebase configured (merchant + customer options exist)
- **APNs key** not uploaded / not tested
- **TestFlight** not configured
- Push on iOS not verified

**Estimated effort:** 3–5 days after Android Beta success.

---

## 7. اختبارات E2E المنفّذة (Automated)

```
PASS  CheckoutSecurityTest — IDOR blocked
PASS  OrderLifecycleE2ETest — full merchant workflow + commission 1000 IQD
PASS  OrderLifecycleE2ETest — customer register + login
PASS  OrderLifecycleE2ETest — merchant register
PASS  OrderPricingServiceTest
PASS  MerchantOrderWorkflowTest
```

**إجمالي:** 9 tests, 37 assertions — **100% pass**

---

## 8. أوامر سريعة

```bash
# Backend tests
cd c:\wamp64\www\smk && php artisan test

# Customer dev
cd smk_customer && flutter run --dart-define=APP_ENV=dev

# Customer LAN
flutter run --dart-define=APP_ENV=dev --dart-define=API_HOST=http://192.168.x.x

# Merchant production AAB
cd smk_merchant && flutter build appbundle --dart-define=APP_ENV=production --release
```

---

## 9. المرحلة التالية (خارج Phase A)

**لا تبدأ قبل إكمال checklist Beta:**

1. Beta مغلقة (Android) — 1–2 أسبوع
2. إصلاح P1 bugs من checklist
3. **ثم** تطبيق الوجستك المركزي + محافظات

---

## 10. ملفات مرجعية

| المستند | المسار |
|---------|--------|
| Customer Beta Checklist | `docs/BETA_TESTING_CHECKLIST.md` |
| Merchant Beta Checklist | `docs/BETA_TESTING_CHECKLIST_MERCHANT.md` |
| Firebase Setup | `docs/FIREBASE_SETUP.md` |
| Keystore | `android/README.md` |
| Env production | `.env.production.example` |
| Customer env | `smk_customer/config/env/` |
| Merchant env | `smk_merchant/config/env/` |

---

**توقيع المرحلة A:** ✅ مكتملة — في انتظار Beta checklist على أجهزة حقيقية.
