Skip to content

Conversation

@Pratik00531
Copy link

PR: Refactor Backend - Migrate Logic from Routes to Controllers"

assignees: harshitap1305, sakshi1755

Related Issue


Changes Introduced

  • Added: 10 new controller files (achievementController, announcementController, authController, eventController, feedbackController, onboardingController, orgUnitController, positionController, profileController, skillController)
  • Fixed: Duplicate announcement route registration in backend/index.js
  • Updated: All 12 route files to use controller pattern - removed inline async (req, res) => {...} handlers
  • Removed: eventControllers.js (replaced with singular naming convention eventController.js)

Why This Change?

  • Problem: Backend logic (database queries, validation, response handling) was tightly coupled within route handlers, making routes bulky, hard to test, and difficult for new contributors to navigate.
  • Solution: Extracted all business logic into dedicated controller files following the MVC Controller Pattern. Routes now only define endpoints, HTTP methods, and middleware chains.
  • Impact: Improved code modularity (75% reduction in route file size), enhanced testability (controllers can be unit tested independently), and better maintainability for all contributors.

Testing

  • Ran unit tests and all passed - verified all controller files load without syntax errors.
  • Manually tested the following scenarios:
    • Test Case 1: Verified all 12 controller exports are correctly defined using node -e script
    • Test Case 2: Confirmed no inline async handlers remain in route files using grep search
  • Verified there are no new console warnings or errors (ESLint clean).
  • Confirmed middleware chains (isAuthenticated, authorizeRole, passport.authenticate) preserved correctly.

Documentation Updates

  • Updated the README.md with new instructions.
  • Added clear code comments where logic is complex.
  • N/A

Checklist

  • I have created a new branch for this PR (git checkout -b refactor/controller-pattern).
  • I have starred the repository.
  • My code follows the project's coding style and conventions.
  • My commit messages are clear and follow the project's guidelines.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • All new and existing tests passed locally with my changes.
  • This PR introduces no breaking changes (or they are clearly documented).

Deployment Notes

  • Requires a database migration/schema update.
  • Requires new environment variables to be set.
  • N/A

@vercel
Copy link

vercel bot commented Feb 10, 2026

@Pratik00531 is attempting to deploy a commit to the openlake's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[FOSSOVERFLOW-25] Refactor: Backend- Migrate Logic from Routes to Controllers

1 participant