# SIM Management Page - API Data Flow & System Architecture *Technical documentation explaining the API integration and data flow for the SIM Management interface* **Purpose**: This document provides a detailed explanation of how the SIM Management page retrieves, processes, and displays data through various API integrations. **Audience**: Management, Technical Teams, System Architects **Last Updated**: September 2025 --- ## πŸ“‹ Executive Summary Change Log (2025-09-05) - Adopted official Freebit API names across all callouts (e.g., "Add Specs & Quota", "MVNO Plan Change"). - Added Freebit API Quick Reference (Portal Operations) table. - Documented Top‑Up Payment Flow (WHMCS invoice + auto‑capture then Freebit AddSpec). - Listed additional Freebit APIs not used by the portal today. The SIM Management page integrates with multiple backend systems to provide real-time SIM data, usage statistics, and management capabilities. The system uses a **Backend-for-Frontend (BFF)** architecture that aggregates data from Freebit APIs and WHMCS, providing a unified interface for SIM management operations. ### Key Systems Integration: - **WHMCS**: Subscription and billing data - **Freebit API**: SIM details, usage, and management operations - **Customer Portal BFF**: Data aggregation and API orchestration --- ## πŸ—οΈ System Architecture Overview ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Customer Portal Frontend β”‚ β”‚ (Next.js - Port 3000) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ SIM Management Page Components: β”‚ β”‚ β€’ SimManagementSection.tsx β”‚ β”‚ β€’ SimDetailsCard.tsx β”‚ β”‚ β€’ DataUsageChart.tsx β”‚ β”‚ β€’ SimActions.tsx β”‚ β”‚ β€’ SimFeatureToggles.tsx β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ HTTP Requests β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Backend-for-Frontend (BFF) β”‚ β”‚ (Port 4000) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ API Endpoints: β”‚ β”‚ β€’ /api/subscriptions/{id}/sim β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/details β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/usage β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/top-up β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/top-up-history β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/change-plan β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/features β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/cancel β”‚ β”‚ β€’ /api/subscriptions/{id}/sim/reissue-esim β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ Data Aggregation β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ External Systems β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ WHMCS β”‚ β”‚ Freebit API β”‚ β”‚ β”‚ β”‚ (Billing) β”‚ β”‚ (SIM Services) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Subscriptions β”‚ β”‚ β€’ SIM Details β”‚ β”‚ β”‚ β”‚ β€’ Customer Data β”‚ β”‚ β€’ Usage Data β”‚ β”‚ β”‚ β”‚ β€’ Billing Info β”‚ β”‚ β€’ Management β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ“Š Data Flow by Section ### 1. **SIM Management Actions Section** **Purpose**: Provides action buttons for SIM operations (Top Up, Reissue, Cancel, Change Plan) **Data Sources**: - **WHMCS**: Subscription status and customer permissions - **Freebit API**: SIM type (physical/eSIM) and current status **API Calls**: ```typescript // Initial Load - Get SIM details for action availability GET /api/subscriptions/{id}/sim/details ``` **Data Flow**: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend β”‚ β”‚ BFF β”‚ β”‚ Freebit API β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ SimActions.tsx │───▢│ /sim/details │───▢│ /mvno/getDetail/β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Check SIM β”‚ β”‚ β€’ Authenticate β”‚ β”‚ β€’ Return SIM β”‚ β”‚ type & status β”‚ β”‚ β€’ Map response β”‚ β”‚ details β”‚ β”‚ β€’ Enable/disableβ”‚ β”‚ β€’ Handle errors β”‚ β”‚ β€’ Status info β”‚ β”‚ buttons β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Action-Specific APIs**: - **Top Up Data**: `POST /api/subscriptions/{id}/sim/top-up` β†’ Freebit `/master/addSpec/` - **Reissue eSIM**: `POST /api/subscriptions/{id}/sim/reissue-esim` β†’ Freebit `/mvno/esim/addAcnt/` - **Cancel SIM**: `POST /api/subscriptions/{id}/sim/cancel` β†’ Freebit `/mvno/releasePlan/` - **Change Plan**: `POST /api/subscriptions/{id}/sim/change-plan` β†’ Freebit `/mvno/changePlan/` --- ### 2. **eSIM Details Card (Right Sidebar)** **Purpose**: Displays essential SIM information in compact format **Data Sources**: - **WHMCS**: Subscription product name and billing info - **Freebit API**: SIM technical details and status **API Calls**: ```typescript // Get comprehensive SIM information GET /api/subscriptions/{id}/sim ``` **Data Flow**: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend β”‚ β”‚ BFF β”‚ β”‚ External β”‚ β”‚ β”‚ β”‚ Systems β”‚ β”‚ Systems β”‚ β”‚ SimDetailsCard │───▢│ /sim │───▢│ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ WHMCS β”‚ β”‚ β”‚ β€’ Phone number β”‚ β”‚ β€’ Aggregate β”‚ β”‚ β”‚ β€’ Product β”‚ β”‚ β”‚ β€’ Data remainingβ”‚ β”‚ data from β”‚ β”‚ β”‚ name β”‚ β”‚ β”‚ β€’ Service statusβ”‚ β”‚ multiple β”‚ β”‚ β”‚ β€’ Billing β”‚ β”‚ β”‚ β€’ Plan info β”‚ β”‚ sources β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β€’ Transform β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ responses β”‚ β”‚ β”‚ Freebit β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Handle errors β”‚ β”‚ β”‚ β€’ ICCID β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ MSISDN β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Status β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Plan code β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Data Mapping**: ```typescript // BFF Response Structure { "details": { "iccid": "8944504101234567890", // From Freebit "msisdn": "08077052946", // From Freebit "planCode": "PASI_50G", // From Freebit "status": "active", // From Freebit "simType": "esim", // From Freebit "productName": "SonixNet SIM Service", // From WHMCS "remainingQuotaMb": 48256 // Calculated } } ``` --- ### 3. **Data Usage Chart (Right Sidebar)** **Purpose**: Visual representation of data consumption and remaining quota **Data Sources**: - **Freebit API**: Real-time usage statistics and quota information **API Calls**: ```typescript // Get usage data GET /api/subscriptions/{id}/sim/usage ``` **Data Flow**: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend β”‚ β”‚ BFF β”‚ β”‚ Freebit API β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ DataUsageChart │───▢│ /sim/usage │───▢│ /mvno/getTrafficβ”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Info/ β”‚ β”‚ β€’ Progress bar β”‚ β”‚ β€’ Authenticate β”‚ β”‚ β”‚ β”‚ β€’ Usage stats β”‚ β”‚ β€’ Format data β”‚ β”‚ β€’ Today's usage β”‚ β”‚ β€’ History chart β”‚ β”‚ β€’ Calculate β”‚ β”‚ β€’ Total quota β”‚ β”‚ β€’ Remaining GB β”‚ β”‚ percentages β”‚ β”‚ β€’ Usage history β”‚ β”‚ β”‚ β”‚ β€’ Handle errors β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Data Processing**: ```typescript // Freebit API Response { "todayUsageMb": 748.47, "totalQuotaMb": 51200, "usageHistory": [ { "date": "2025-01-04", "usageMb": 1228.8 }, { "date": "2025-01-03", "usageMb": 595.2 }, { "date": "2025-01-02", "usageMb": 448.0 } ] } // BFF Processing const usagePercentage = (usedMb / totalQuotaMb) * 100; const remainingMb = totalQuotaMb - usedMb; const formattedRemaining = formatQuota(remainingMb); // "47.1 GB" ``` --- ### 4. **Plan & Service Options** **Purpose**: Manage SIM plan and optional features (Voice Mail, Call Waiting, International Roaming, 4G/5G). **Data Sources**: - **Freebit API**: Current service settings and options - **WHMCS**: Plan catalog and billing context **API Calls**: ```typescript // Get current service settings GET /api/subscriptions/{id}/sim/details // Update optional features (flags) POST /api/subscriptions/{id}/sim/features // Change plan POST /api/subscriptions/{id}/sim/change-plan ``` **Data Flow**: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend β”‚ β”‚ BFF β”‚ β”‚ Freebit API β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ SimFeatureToggles│───▢│ /sim/details │───▢│ /mvno/getDetail/ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Apply Changes │───▢│ /sim/features │───▢│ /master/addSpec/ (flags) β”‚ β”‚ Change Plan │───▢│ /sim/change-plan│───▢│ /mvno/changePlan/ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Validate β”‚ β”‚ β€’ Authenticate β”‚ β”‚ β€’ Apply changes β”‚ β”‚ β€’ Update UI β”‚ β”‚ β€’ Transform β”‚ β”‚ β€’ Return resultCode=100 β”‚ β”‚ β€’ Refresh data β”‚ β”‚ β€’ Handle errors β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` Allowed plans and mapping - The portal currently supports the following SIM data plans from Salesforce: - SIM Data-only 5GB β†’ Freebit planCode `PASI_5G` - SIM Data-only 10GB β†’ `PASI_10G` - SIM Data-only 25GB β†’ `PASI_25G` - SIM Data-only 50GB β†’ `PASI_50G` - UI behavior: The Change Plan action lives inside the β€œSIM Management Actions” card. Clicking it opens a modal listing only β€œother” plans. For example, if the current plan is `PASI_50G`, options will be 5GB, 10GB, 25GB. If the current plan is not 50GB, the 50GB option is included. - Request payload sent to BFF: ```json { "newPlanCode": "PASI_25G" } ``` - BFF calls MVNO Plan Change with fields per the API spec (account, planCode, optional globalIP, optional runTime). --- ### 5. **Top-Up Payment Flow (Invoice + Auto-Capture)** When a user tops up data, the portal bills through WHMCS before applying the quota via Freebit. Unit price is fixed: 1 GB = Β₯500. Endpoints used - Frontend β†’ BFF: `POST /api/subscriptions/{id}/sim/top-up` with `{ quotaMb, campaignCode?, expiryDate? }` - BFF β†’ WHMCS: `createInvoice` then `capturePayment` (gateway-selected SSO or stored method) - BFF β†’ Freebit: `PA04-04 Add Spec & Quota` (`/master/addSpec/`) if payment succeeds Pricing - Amount in JPY = ceil(quotaMb / 1000) Γ— 500 - Example: 1000MB β†’ Β₯500, 3000MB β†’ Β₯1,500 Happy-path sequence ``` Frontend BFF WHMCS Freebit ────────── ──────────────── ──────────────── ──────────────── TopUpModal ───────▢ POST /sim/top-up ───────▢ createInvoice ─────▢ (quotaMb) (validate + map) (amount=ceil(MB/1000)*500) β”‚ β”‚ β”‚ invoiceId β–Ό β”‚ capturePayment ───────────────▢ β”‚ β”‚ paid (or failed) β”œβ”€β”€ on success ─────────────────────────────▢ /master/addSpec/ β”‚ (quota in MB) └── on failure ──┐ └──── return error (no Freebit call) ``` Failure handling - If `capturePayment` fails, BFF responds with 402/400 and does NOT call Freebit. UI shows error and invoice link for manual payment. - If Freebit returns non-100 `resultCode`, BFF logs, returns 502/500, and may void/refund invoice in future enhancement. BFF responsibilities - Validate `quotaMb` (1–100000) - Price computation and invoice line creation (description includes quota) - Attempt payment capture (stored method or SSO handoff) - On success, call Freebit AddSpec with `quota` in MB (string) and optional `expire` - Return success to UI and refresh SIM info Freebit PA04-04 (Add Spec & Quota) request fields - `account`: MSISDN (phone number) - `quota`: integer MB (string) (100MB–51200MB) - `quotaCode` (optional): campaign code - `expire` (optional): YYYYMMDD Notes - Scheduled top-ups use `/mvno/eachQuota/` with `runTime`; immediate uses `/master/addSpec/`. - For development, amounts and gateway can be simulated; production requires real WHMCS gateway configuration. --- ## πŸ”„ Real-Time Data Updates ### Automatic Refresh Mechanism ```typescript // After any action (top-up, cancel, etc.) const handleActionSuccess = () => { // Refresh all data refetchSimDetails(); refetchUsageData(); refetchSubscriptionData(); }; ``` ### Data Consistency - **Immediate Updates**: UI updates optimistically - **Background Sync**: Real data fetched after actions - **Error Handling**: Rollback on API failures - **Loading States**: Visual feedback during operations --- ## πŸ“ˆ Performance Considerations ### Caching Strategy ```typescript // BFF Level Caching - SIM Details: 5 minutes TTL - Usage Data: 1 minute TTL - Subscription Info: 10 minutes TTL // Frontend Caching - React Query: 30 seconds stale time - Background refetch: Every 2 minutes ``` ### API Optimization - **Batch Requests**: Single endpoint for comprehensive data - **Selective Updates**: Only refresh changed sections - **Error Recovery**: Retry failed requests with exponential backoff --- ## πŸ›‘οΈ Security & Authentication ### Authentication Flow ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend β”‚ β”‚ BFF β”‚ β”‚ External β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Systems β”‚ β”‚ β€’ JWT Token │───▢│ β€’ Validate JWT │───▢│ β€’ WHMCS API Key β”‚ β”‚ β€’ User Context β”‚ β”‚ β€’ Map to WHMCS β”‚ β”‚ β€’ Freebit Auth β”‚ β”‚ β€’ Permissions β”‚ β”‚ Client ID β”‚ β”‚ β€’ Rate Limiting β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Data Protection - **Input Validation**: All user inputs sanitized - **Rate Limiting**: API calls throttled per user - **Audit Logging**: All actions logged for compliance - **Error Masking**: Sensitive data not exposed in errors --- ## πŸ“Š Monitoring & Analytics ### Key Metrics Tracked - **API Response Times**: < 500ms target - **Error Rates**: < 1% target - **User Actions**: Top-up frequency, plan changes - **Data Usage Patterns**: Peak usage times, quota consumption ### Health Checks ```typescript // BFF Health Endpoints GET /health/sim-management GET /health/freebit-api GET /health/whmcs-api ``` --- ## πŸš€ Future Enhancements ### Planned Improvements 1. **Real-time WebSocket Updates**: Live usage data without refresh 2. **Advanced Analytics**: Usage predictions and recommendations 3. **Bulk Operations**: Manage multiple SIMs simultaneously 4. **Mobile App Integration**: Native mobile SIM management ### Scalability Considerations - **Microservices**: Split BFF into domain-specific services - **CDN Integration**: Cache static SIM data globally - **Database Optimization**: Implement read replicas for usage data --- ## πŸ“ž Support & Troubleshooting ### Common Issues 1. **API Timeouts**: Check Freebit API status 2. **Data Inconsistency**: Verify WHMCS sync 3. **Authentication Errors**: Validate JWT tokens 4. **Rate Limiting**: Monitor API quotas ### Debug Endpoints ```typescript // Development only GET /api/subscriptions/{id}/sim/debug GET /api/health/sim-management/detailed ``` --- ## πŸ“‹ **Summary for Your Managers** This comprehensive documentation explains: ### **πŸ—οΈ System Architecture** - **3-Tier Architecture**: Frontend β†’ BFF β†’ External APIs (WHMCS + Freebit) - **Data Aggregation**: BFF combines data from multiple sources - **Real-time Updates**: Automatic refresh after user actions ### **πŸ“Š Key Data Flows** 1. **SIM Actions**: Button availability based on SIM type and status 2. **SIM Details**: Phone number, data remaining, service status 3. **Usage Chart**: Real-time consumption and quota visualization 4. **Service Options**: Voice mail, call waiting, roaming settings ### **πŸ”§ Technical Benefits** - **Performance**: Caching and optimized API calls - **Security**: JWT authentication and input validation - **Reliability**: Error handling and retry mechanisms - **Monitoring**: Health checks and performance metrics ### **πŸ’Ό Business Value** - **User Experience**: Real-time data and intuitive interface - **Operational Efficiency**: Automated SIM management operations - **Data Accuracy**: Direct integration with Freebit and WHMCS - **Scalability**: Architecture supports future enhancements This documentation will help your managers understand the technical complexity and business value of the SIM Management system!