🚀 Antigravity Migration & Remote Sync Guide

This guide explains how to use the built-in **Push/Pull Synchronization System** to move code, data, and assets between your Local Development (Localhost) and your Production Server.

---

#

🛠 1. Initial Setup (One-Time)

To connect your Localhost to your Production server, you must establish a secure handshake.

1. **On Production Server**:
* Navigate to `Admin > System > Backup & Migration`.
* Scroll to **Remote Sync Settings**.
* Enter a **Secret Sync Token** (e.g., `MyUltraSecretKey123`).
* Click **Save Settings**.
2. **On Localhost**:
* Navigate to `Admin > System > Backup & Migration`.
* Scroll to **Remote Sync Settings**.
* **Production Server URL**: Enter your live site URL (e.g., `https://yourdomain.com`).
* **Secret Sync Token**: Enter the **exact same token** you saved on Production.
* Click **Save Settings**.

---

#

📤 2. Pushing Updates (Localhost ➔ Production)

Use this when you have finished coding or added new products locally and want them live.

1. **Create Snapshot**:
* Click **Generate New Backup** and select **Full System**.
* This packages your `app`, `resources`, `routes`, `database` (JSON), and `uploads`.
2. **Push**:
* Locate the completed backup in the table.
* Click the **Green Cloud Icon (Push to Production)**.
3. **Automatic Deployment**:
* The system will transmit the package via API.
* The production server will automatically extract the code and merge the database records using the **Zero-Downtime Engine**.

---

#

📥 3. Pulling Data (Production ➔ Localhost)

Use this when you want to sync your local environment with the latest live customer data.

1. **On Production**: Generate a **Logical Backup** (Recommended for data-only pull).
2. **Download**: Click the download icon to save the ZIP.
3. **On Localhost**:
* In the **Migration Import** section, upload the ZIP.
* Click the **Blue Restore Icon** to sync your local database with live data.

---

#

🛡 System Integrity Rules (Laws of the Project)

To keep the Antigravity Sync system alive and prevent "Broken State" errors, always follow these rules:

1. **Migration-First Schema**: Never change database tables manually via phpMyAdmin. Always use `php artisan make:migration`. The sync system relies on consistent schema versions.
2. **No Core Tampering**: Avoid modifying `App\Services\SystemBackupService.php` unless you are updating the manifest logic. This is the heart of the deployment engine.
3. **Environment Variables**: The `.env` file is NOT synced for security. If you add new services (e.g., Stripe, Mailgun), manually update the `.env` on both environments.
4. **Vendor Policy**: Never include the `vendor` or `node_modules` folders in manual ZIPs. The system handles core logic; dependencies should be managed via `composer install`.
5. **Clean Uploads**: Keep the `public/uploads` directory organized. The sync engine packages this folder to ensure product images never break during migration.
6. **Token Rotation**: If you suspect a security breach, change the **Secret Sync Token** on both Production and Localhost immediately to kill all active API sync bridges.

---

**System Status**: 🟢 Operational | **Version**: 2.0.0 (API-Driven)