Skip to content

refactor: Phase 1 — split xstateUtilsV5.ts into focused modules#1345

Open
rlho wants to merge 1 commit intomainfrom
xstate-phase1-split
Open

refactor: Phase 1 — split xstateUtilsV5.ts into focused modules#1345
rlho wants to merge 1 commit intomainfrom
xstate-phase1-split

Conversation

@rlho
Copy link
Copy Markdown
Collaborator

@rlho rlho commented Mar 26, 2026

Summary of Changes

Phase 1 of the XState refactoring plan (see docs/xstate-refactoring-plan.md).

Splits the 2,001-line xstateUtilsV5.ts God Object into 4 focused modules:

File Lines Responsibility
xstateTypes.ts 14 Type definitions (PersistedXStateData, PreApprovalUpdateData)
xstateEffects.ts 781 Side effects (emails, calendar updates, timestamp writes)
xstatePersistence.ts 569 Firestore snapshot save/restore/migration, machine selection
xstateTransitions.ts 667 Public API (executeXStateTransition, getAvailableXStateTransitions)
xstateUtilsV5.ts 1 Barrel re-export — external callers are unaffected

Also updates docs/xstate-refactoring-plan.md with goals and risk assessment.

What this does NOT change

  • No runtime behavior changes
  • No state machine logic changes
  • No external API changes (barrel re-export maintains compatibility)

Checklist

  • I checked for existing implementations and confirmed there is no duplication
  • I thoroughly tested this feature locally
  • I added or updated unit tests (or explained why not in the PR description)
    • No new tests needed — only file splitting. All 83 test files (1,318 tests) pass.
  • I attached screenshots or a video demonstrating the feature
  • I incorporated Copilot's feedback (or explained why not in the PR description), and marked conversation as resolved
  • I confirmed my PR passed all unit and end-to-end (E2E) tests
  • I confirmed there are no conflicts
  • I requested a code review from at least one other teammate

Screenshots / Video

N/A — no UI changes.

Copilot AI review requested due to automatic review settings March 26, 2026 22:19
Split the 2,001-line God Object into 4 focused modules:

- xstateTypes.ts (14 lines) — PersistedXStateData, PreApprovalUpdateData
- xstateEffects.ts (781 lines) — handleStateTransitions, sendCanceledEmail
- xstatePersistence.ts (569 lines) — snapshot save/restore/migration,
  machine selection, status mapping
- xstateTransitions.ts (667 lines) — executeXStateTransition,
  getAvailableXStateTransitions

xstateUtilsV5.ts becomes a 1-line barrel re-export so external callers
are unaffected.

No runtime behavior changes. All 83 test files (1,318 tests) pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rlho rlho force-pushed the xstate-phase1-split branch from 664efa4 to 1bcb34c Compare March 26, 2026 22:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Phase 1 refactor of the XState “god object” (xstateUtilsV5.ts) into smaller, responsibility-focused modules while keeping external callers stable via a barrel re-export.

Changes:

  • Replaced xstateUtilsV5.ts implementation with a barrel export to preserve the existing import path/API.
  • Introduced focused modules for types, persistence, effects, and transition APIs.
  • Updated the XState refactoring plan document to reflect revised goals and the phased approach.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
booking-app/lib/stateMachines/xstateUtilsV5.ts Converts the former monolith into a barrel re-export to preserve compatibility.
booking-app/lib/stateMachines/xstateTypes.ts Extracts shared type definitions used across the refactored modules.
booking-app/lib/stateMachines/xstatePersistence.ts Hosts Firestore snapshot creation/restoration and related helpers.
booking-app/lib/stateMachines/xstateEffects.ts Hosts transition side effects and state-change handling logic.
booking-app/lib/stateMachines/xstateTransitions.ts Hosts the public transition API and wires persistence/effects together.
booking-app/docs/xstate-refactoring-plan.md Updates the refactoring plan narrative and Phase 3 framing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants