Skip to content

πŸ“‚ Refactor Report – Backend Folder Structure & Maintainability IssuesΒ #7

Description

@dipesh-y

πŸ”Ž Observed Issues

Mixed Concerns β†’ Database logic, routes, and JWT checks are all written together.

No Modularization β†’ Controllers, models, services, and middleware are not separated.

Hard to Debug β†’ Debugging and testing are complicated due to tightly coupled code.

Scaling Issues β†’ Adding new features will make the codebase messy and harder to maintain.

Onboarding Difficulty β†’ New developers may struggle to understand and contribute quickly.

🎯 Expected Behavior

Code should follow a clear and modular folder structure.

Routes should only handle API endpoints, delegating logic to controllers.

Database queries should be managed inside models or services.

Middleware (e.g., JWT authentication, validation) should be kept reusable and separate.

Project should be clean, scalable, and easy for new contributors to navigate.

βœ… Suggested Folder Structure
backend/
│── src/
β”‚ β”œβ”€β”€ config/ # DB connection, environment configs
β”‚ β”œβ”€β”€ models/ # Database models/schemas
β”‚ β”œβ”€β”€ controllers/ # Request handling logic
β”‚ β”œβ”€β”€ routes/ # API route definitions
β”‚ β”œβ”€β”€ middleware/ # JWT auth, validation, etc.
β”‚ β”œβ”€β”€ services/ # Business logic (optional, scalable)
β”‚ └── utils/ # Helper functions
β”‚
└── index.js # Entry point

πŸ’‘ Suggested Fixes

Refactor existing code into the above structure.

Keep routes minimal and delegate logic to controllers.

Move DB queries into models/services.

Separate JWT and validation logic into middleware/.

Update docs so contributors can quickly understand the project structure.

πŸ“Œ Type: Enhancement / Refactor
πŸ“Œ Priority: High

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions