subhadipbhowmik / 30-Days-Of-CPP

30 days of CPP programming challenge is a step by step guide to learn CPP programming language in 30 days. Happy Coding.
https://subhadipbhowmik.github.io/30-Days-Of-CPP/
MIT License
53 stars 139 forks source link

Improvement in backend file structure. #356 #369

Closed divyansh-2005 closed 2 weeks ago

divyansh-2005 commented 3 weeks ago

closes #356

Here's a short summary of the changes made to the project structure and organization:

  1. File Organization:

    • Introduced separate directories (config, models, routes, controllers, middleware) to organize different components of the application logically.
  2. Configuration (config/config.js):

    • Centralized configuration variables (JWT_SECRET, mongoURI) into a dedicated file (config/config.js).
  3. User Model (models/user.js):

    • Defined the Mongoose schema and model for the User entity in models/user.js.
  4. Routing (routes/router.js and routes/auth.js):

    • Created a main router file (routes/router.js) to combine all route modules and mount them under /api.
    • Implemented authentication routes (/signup and /login) in routes/auth.js.
  5. Controllers (controllers/authController.js):

    • Separated route handling logic into controller functions (signup and login) within controllers/authController.js.
  6. Middleware (middleware/authMiddleware.js):

    • Added JWT authentication middleware (middleware/authMiddleware.js) to verify and decode JWT tokens.
  7. Main Application Entry (index.js):

    • Consolidated Express setup, middleware registration, MongoDB connection, route mounting, and server initialization in index.js.
    • Included error handling middleware (errorHandler.js) for centralized error management.
  8. .gitignore:

    • Created a basic .gitignore file to exclude commonly ignored files and directories from being tracked by Git.

These changes aim to improve maintainability, separation of concerns, and overall organization of the Node.js application, following best practices for project structure and module separation. Each component (models, routes, controllers, middleware, config) now handles specific responsibilities, enhancing code clarity and scalability.

divyansh-2005 commented 3 weeks ago

Kindle Review and merge Pull request.

github-actions[bot] commented 2 weeks ago

🎉 Your pull request has been successfully merged! 🎉 Thank you for your contribution to our project. Your efforts are greatly appreciated. Keep up the fantastic work! 🚀