Skip to content

Refactor/extract services from server#172

Merged
Nitya-003 merged 3 commits intoNitya-003:mainfrom
navin-oss:refactor/extract-services-from-server
Mar 8, 2026
Merged

Refactor/extract services from server#172
Nitya-003 merged 3 commits intoNitya-003:mainfrom
navin-oss:refactor/extract-services-from-server

Conversation

@navin-oss
Copy link
Contributor

Successfully refactored the backend/server.js "God file" into dedicated services following the Separation of Concerns principle. The new branch refactor/extract-services-from-server has been pushed to the remote.

Created Services:

1. BlockchainService

  • Handles blockchain initialization, validation, and transactions
  • Methods: createBatchOnChain(), updateBatchOnChain(), getBatchFromChain(), simulateHash()
  • Integrates with existing blockchain.js config

2. BatchService

  • Handles all batch business logic (CRUD operations)
  • Methods: generateBatchId(), generateQRCode(), createBatch(), getBatch(), updateBatch(), recallBatch(), getAllBatches(), calculateStats(), getDashboardStats()
  • Handles MongoDB transactions and integrates with blockchain and notification services

3. NotificationService

  • Handles all notifications and alerts
  • Methods: alertRecall(), sendRecallNotification(), notifyBatchCreated(), notifyBatchUpdated(), notifySecurityEvent(), notifyError()
  • Includes placeholders for email and push notifications

4. Refactored server.js

  • Simplified route handlers by delegating to services
  • Reduced code from ~680 lines to ~380 lines
  • Clean separation of middleware, routes, and business logic

Benefits:

  • Improved testability - Services can be unit tested independently
  • Easier debugging - Clear separation of concerns
  • Scalable architecture - Services can be modified independently
  • Follows Single Responsibility Principle

Branch Details:

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor to Service-Oriented Architecture (SOA)

3 participants