# HƯỚNG DẪN TRIỂN KHAI HẠ TẦNG 1.000.000 CCU & ĐÓNG GÓI TESTFLIGHT IOS

## 1. TRIỂN KHAI CỤM MÁY CHỦ CHỊU TẢI TRIỆU CCU (KUBERNETES)

### 1.1. Yêu Cầu Tài Nguyên Cụm
- **Hạ Tầng Khuyến Nghị**: 50 Nodes máy chủ đám mây (AWS c6g.16xlarge hoặc GCP c3-standard-88, chip ARM64 / Graviton3 / AMD EPYC).
- **Hệ Thống Lưu Trữ Phân Tán**:
  - Redis Enterprise Cluster: In-memory spatial state & session cache.
  - Redpanda / Kafka Cluster: Event Sourcing transaction ledger bất biến.
  - ScyllaDB Cluster: Lưu trữ dữ liệu nhân vật ACID phân tán.

### 1.2. Các Lệnh Triển Khai
```bash
# 1. Tạo namespace
kubectl create namespace freeexile-prod

# 2. Áp dụng cấu hình Gateway & World Shard StatefulSet
kubectl apply -f deploy/k8s_million_ccu_cluster.yaml -n freeexile-prod

# 3. Kiểm tra trạng thái tải và scaling
kubectl get pods -n freeexile-prod -o wide
kubectl get hpa -n freeexile-prod
```

---

## 2. QUY TRÌNH ĐÓNG GÓI BẢN GOLD CHO IOS (APPLE TESTFLIGHT IPA)

### 2.1. Cấu Hình Xcode & Metal Pipeline
1. Mở dự án iOS trong Xcode (`platform/ios/FreeExile.xcodeproj`).
2. Xác nhận cấu hình Signing & Capabilities:
   - **Apple App Attest** (DeviceCheck framework enabled).
   - **Game Center** enabled.
   - **In-App Purchase (StoreKit 2)** enabled.
   - **Push Notifications (APNs)** enabled.
3. Target iOS Deployment: iOS 16.0+ (Tối ưu hóa ProMotion 120Hz và Metal).

### 2.2. Lệnh Build và Export IPA TestFlight
```bash
# 1. Tạo bản lưu trữ Xcode Archive
xcodebuild -project platform/ios/FreeExile.xcodeproj \
           -scheme FreeExile \
           -configuration Release \
           -archivePath build/FreeExile.xcarchive \
           archive

# 2. Xuất tệp IPA sẵn sàng cho TestFlight
xcodebuild -exportArchive \
           -archivePath build/FreeExile.xcarchive \
           -exportPath build/TestFlightOutput \
           -exportOptionsPlist deploy/ios_testflight_export.plist

# 3. Tải lên App Store Connect / TestFlight
xcrun altool --upload-app -f build/TestFlightOutput/FreeExile.ipa \
             -t ios --apiKey <APP_STORE_CONNECT_API_KEY> \
             --apiIssuer <ISSUER_ID>
```

---

## 3. QUY TRÌNH ĐÓNG GÓI BẢN GOLD CHO ANDROID (GOOGLE PLAY APP BUNDLE AAB)

### 3.1. Cấu Hình Android Studio & Google Play Console
1. Mở thư mục `platform/android/` trong Android Studio.
2. Kiểm tra `app/build.gradle.kts`:
   - `compileSdk = 35`, `targetSdk = 35`, `minSdk = 26`.
   - `applicationId = "com.freeexile.arpg"`.
   - Google Play Billing Library 7.0+ & Play Integrity API 1.4+.
   - R8 / ProGuard minification & resource shrinking đã kích hoạt (`isMinifyEnabled = true`).

### 3.2. Lệnh Build Android App Bundle (AAB) cho Google Play
```bash
cd platform/android

# Tạo Release Android App Bundle (AAB)
./gradlew bundleRelease

# File đầu ra nằm tại:
# platform/android/app/build/outputs/bundle/release/app-release.aab
```

