Architecture-00025 — Tenant Migration Admin Console Component Topology and Data Flow

By Engineering Team•October 11, 2026•6 min read

Metadata

Field Value
System Name ui-admin-application — Tenant Data Migration feature
Document ID ARCH-2026-MIG-002
Author Engineering Team
Status Implemented (gaps noted inline)

Realizes SR-030 under ADR-00046. Drives the backend pipeline documented in Architecture-00024.

Components

Component Role
MigrationPage.tsx Composition root — renders the three-tab Tabs/Tab shell, switches between IngestPage/MonitorPage/HistoryPage by ctrl.tab, and always mounts AuditDrawer (open/closed driven by ctrl.selectedBatchId).
MigrationController.ts (useMigrationController) The feature’s only stateful layer — owns all State (tab, upload/verify/execute progress, current batch, history list, drawer/errors-panel state, pending destructive action), the two bounded poll loops, the SSE stream lifecycle (streamCloserRef), and every handler the three sub-pages call.
MigrationRepository.ts The only file importing apiClient/openEventStream. Nine REST calls (fetchBatches, fetchBatch, verifyBatch, executeBatch, deleteBatch, cancelBatch, retryBatch, fetchBatchErrors) plus openMigrationStream, which wraps core/http/sseClient’s openEventStream and returns a close() the controller must call on unmount/tab change.
MigrationService.ts Pure functions: gating predicates (isVerifyReady, isExecuteReady, canRetryBatch, canDeleteBatch), status-to-color mapping (statusColor), and view-shaping (stageEntityRows, entitySummaryRows, verificationProgress). No React, no API calls.
MigrationTypes.ts MigrationBatch, MigrationBatchStages/MigrationBatchStage (the four fixed stage buckets mirroring SR-029’s wave-barrier plan), VerificationStep, EntitySummary, MigrationError/BatchErrorsResult — shared by every layer above.
pages/ingest/IngestPage.tsx Upload dropzone, upload-progress bar, the 3-step Verification panel, and the Verify/Execute Migration action buttons, gated by isVerifyReady/isExecuteReady.
pages/monitor/MonitorPage.tsx Renders ctrl.currentBatch’s overall status chip plus the four-stage entity breakdown (via stageEntityRows), or an empty state when no batch is currently selected for monitoring.
pages/history/HistoryPage.tsx The batch list (ctrl.batches), each row’s available actions (watchBatch/runExecute/requestHistoryAction) gated by the same MigrationService predicates used on Ingest.
pages/history/AuditDrawer.tsx Per-batch detail drawer — verification steps, entity summary cards (entitySummaryRows), and the collapsible MigrationErrorsPanel.
shared/StatusChip.tsx Renders a MigrationBatch['status'] as a colored MUI Chip using MigrationService.statusColor — the one place status-to-color mapping is consumed.
shared/MigrationErrorsPanel.tsx Paginated verification + execution error list for one batch, shown when getTotalFailed(batch) > 0 || batch.status === 'VERIFICATION_FAILED'.
features/media/MediaService.ts (getUploadPresignedUrls, uploadFileToStorage) Shared presigned-upload flow reused as-is from the Media feature — Migration does not have, and must not grow, its own upload mechanism.
core/http/sseClient.ts (openEventStream) Shared SSE client — attaches auth/App-Check headers and parses event frames; the reason openMigrationStream can’t just use the browser’s bare EventSource.
core/telemetry/tracing.ts traceparent/X-Correlation-ID injection on every Axios call via apiClient’s interceptor — no Migration-specific tracing code.
Backend: tenant-migration Receives the uploaded bundle via firebase-function’s Storage trigger, and serves every REST endpoint MigrationRepository.ts calls (verify/execute/cancel/retry/delete/list/get/errors/stream) — see Architecture-00024.

Diagram

Tenant Data Migration Admin Console — component topology and data flow from MigrationPage.tsx's three tabs through MigrationController.ts's state and poll/SSE lifecycle, to MigrationRepository.ts's REST/SSE calls against tenant-migration and the tenant's GCS staging bucket

End-to-end flow

  1. Operator opens the Tenant Data Migration feature; MigrationPage.tsx mounts on the ingest tab by default, and useMigrationController’s initial effect calls loadHistory() so the Historical Audits list is already populated if the operator switches tabs (SR-030 FR-10).
  2. On Ingest, selectFile stores the chosen ZIP in controller state; startUpload generates a client-side batchId (batch_${Date.now()}), calls MediaService.getUploadPresignedUrls with transactionName: 'migration_bundle' and transactionId: batchId, then uploadFileToStorage PUTs the file directly to the tenant’s staging bucket, reporting progress back into uploadProgress (SR-030 FR-01).
  3. Once the PUT resolves, startUpload begins pollForBatch — a bounded 1.5s-interval poll (BATCH_POLL_INTERVAL_MS × BATCH_POLL_MAX_ATTEMPTS) against GET /migration/batches/:batchId, waiting for firebase-function’s Storage trigger and tenant-migration’s MigrationBatchCreatedReceiver to materialize the migration_batches document server-side (SR-030 FR-02, FR-03; see ADR-00046’s Decision 2 for why this wait is a bounded poll rather than SSE).
  4. Once the batch appears, IngestPage shows the Verification panel with all three steps PENDING and an enabled Verify button, gated by isVerifyReady (status === 'UPLOADED') (SR-030 FR-04).
  5. startVerify calls POST /migration/verify/:batchId, then begins pollForVerification — the second bounded poll, ending the moment the batch reaches VERIFIED or VERIFICATION_FAILED (SR-030 FR-05).
  6. On VERIFIED, isExecuteReady gates the Execute Migration button open; on VERIFICATION_FAILED, the same panel instead surfaces the failed step inline, and MigrationErrorsPanel becomes visible (SR-030 FR-06, FR-16).
  7. startExecute calls POST /migration/execute/:batchId, switches tab to monitor, and opens the SSE stream via openMonitorStream/openMigrationStream scoped to this batchId (SR-030 FR-07, FR-08).
  8. MonitorPage renders every SSE-pushed MigrationBatch frame — the overall status chip plus, via stageEntityRows, each of the four fixed stage buckets’ entity types with their queued/processed/failed counts and blockedBy annotations, mirroring the backend’s wave-barrier plan (Architecture-00024 step 10) (SR-030 FR-09).
  9. The stream is closed explicitly — on tab switch away from monitor (setTab’s closeStream() call) and on controller unmount — via the streamCloserRef single-connection guard, which also prevents a second stream opening while one is already active for the same batch (SR-030 FR-08).
  10. On Historical Audits, HistoryPage lists every batch from loadHistory’s fetchBatches call, each row showing per-batch actions gated by the same MigrationService predicates: watchBatch (re-open Monitor’s SSE stream for an in-flight batch), runExecute (resume a VERIFIED batch straight to Execute — the only path back to Execute once currentBatchId is lost to a page refresh, per the runExecute code comment) (SR-030 FR-07), and requestHistoryAction for retry/delete/cancel (SR-030 FR-12, FR-13, FR-14).
  11. A destructive history action (retry/delete/cancel) goes through requestHistoryAction → a confirmation step → confirmPendingHistoryAction, which dispatches to runRetry/runDelete/runCancel only after the operator confirms (SR-030 FR-15).
  12. openAuditDrawer opens AuditDrawer for a selected batch, rendering its verification steps, entitySummaryRows’ per-entity-type detail (totals, file list, validation checks), and — when getTotalFailed(batch) > 0, or the batch is VERIFICATION_FAILED — the paginated MigrationErrorsPanel, backed by fetchBatchErrors’s page/pageSize parameters (SR-030 FR-17).

What this does not yet guarantee

  • The client-generated batchId (batch_${Date.now()}) has millisecond resolution and no collision check before being used as the idempotency key’s transactionId — two uploads issued by different browser tabs within the same millisecond would silently collide at the backend’s idempotent batch-creation step. See TD-00024.
  • MigrationRepository.ts has no DEV_MOCK_* fallback, unlike every other feature in this admin app — the console cannot be exercised without a running tenant-migration backend. See TD-00024.
  • entitySummaryRows/stageEntityRows surface each entity type’s raw enum string (e.g. PRODUCT_OPENING_ENTRY_PROCESS) directly — MigrationService.ts humanizes stage names (STAGE_LABELS) but has no equivalent mapping for entity-type names. See TD-00024.