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:

@netlify
Copy link

netlify bot commented Mar 6, 2026

Deploy Preview for roaring-ganache-c7465f failed. Why did it fail? →

Name Link
🔨 Latest commit a908e11
🔍 Latest deploy log https://app.netlify.com/projects/roaring-ganache-c7465f/deploys/69ad9192283737000879a4a1

@navin-oss
Copy link
Contributor Author

Hi @maintainer,

This PR involves a major backend refactor — extracting multiple services from the server.js file, restructuring architecture, and resolving related backend issues. Because of the scope and complexity, it would be more accurate to label this PR as hard instead of medium.

Could you please update the label to hard?

Thank you!

@vedhapprakashni
Copy link
Collaborator

@navin-oss pls resolve conflicts

Copy link
Owner

@Nitya-003 Nitya-003 left a comment

Choose a reason for hiding this comment

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

@navin-oss Can you please mention the issue number you are solving? Can you resolve the conflicts?

Image

@vedhapprakashni
Copy link
Collaborator

@navin-oss

@navin-oss
Copy link
Contributor Author

Resloved conflicts

Copy link
Owner

@Nitya-003 Nitya-003 left a comment

Choose a reason for hiding this comment

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

@navin-oss Closes #154 and Resolve the conflicts.

@vedhapprakashni vedhapprakashni linked an issue Mar 8, 2026 that may be closed by this pull request
@navin-oss
Copy link
Contributor Author

Resolved conflicts

@Nitya-003 Nitya-003 merged commit 85fba3c into Nitya-003:main Mar 8, 2026
0 of 8 checks passed
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