Skip to content

DO NOT MERGE, Refactor: ApiHandler Migration to Service Layer Architecture#1731

Draft
cakesoft-shashank wants to merge 2 commits intosprintfrom
migration/apiHandler
Draft

DO NOT MERGE, Refactor: ApiHandler Migration to Service Layer Architecture#1731
cakesoft-shashank wants to merge 2 commits intosprintfrom
migration/apiHandler

Conversation

@cakesoft-shashank
Copy link
Copy Markdown
Member

This PR migrates the monolithic ApiHandler class to a modular service layer architecture with dedicated services and React hooks. This refactoring improves code maintainability, testability, and follows React best practices by separating concerns.

The legacy ApiHandler class had grown to over 3,400 lines and violated several software engineering principles:

Architecture Changes

New Service Layer

Created six specialized services following the Single Responsibility Principle:

1. AuthService (src/services/auth/AuthService.ts)

  • User authentication and authorization
  • PIN/biometric verification
  • Session management
  • Replaced ApiHandler initialization with NodeService.initApi()

2. AppService (src/services/app/AppService.ts)

  • App setup and initialization
  • Release notes and version history
  • FCM topic management
  • Migrated from ApiHandler to use WalletService, NodeService, BackupService, and RgbService

3. WalletService (src/services/wallet/WalletService.ts)

  • Wallet creation and management
  • Transaction operations
  • Balance tracking
  • Profile updates
  • New implementations: receiveTestSats, updateProfile, removeWalletPicture
  • Migrated: getNodeOnchainBtcTransactions to use NodeService

4. RgbService (src/services/rgb/RgbService.ts)

  • RGB asset operations (NIA, CFA, UDA)
  • Asset issuance and transfers
  • Invoice generation
  • Channel management
  • New implementations: receiveAsset, searchAssetFromRegistry, handleTransferFailure

5. NodeService (src/services/node/NodeService.ts)

  • RGB node connection and management
  • Node API initialization
  • Node information retrieval
  • New implementation: getNodeOnchainBtcTransactions

6. BackupService (src/services/backup/BackupService.ts)

  • App backup and restore
  • Cloud backup management
  • File download operations

Custom React Hooks

Created six custom hooks for React components:

  • useAuth - Authentication operations
  • useApp - App-level operations
  • useWallet - Wallet operations
  • useRgb - RGB asset operations
  • useNode - Node management
  • useBackup - Backup operations

@cakesoft-shashank cakesoft-shashank marked this pull request as draft January 28, 2026 04:11
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.

1 participant