Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Database Logic From Service Layer (Proof of Concept) #281

Open
17 of 22 tasks
seansica opened this issue Aug 25, 2023 · 0 comments
Open
17 of 22 tasks

Separate Database Logic From Service Layer (Proof of Concept) #281

seansica opened this issue Aug 25, 2023 · 0 comments
Assignees

Comments

@seansica
Copy link
Contributor

seansica commented Aug 25, 2023

Objective:

Separate the database logic from the service layer to improve code modularity, maintainability, and facilitate testing.

Background:

Currently, our Express.js API directly performs database operations in the service layer. This intertwined structure can become a maintenance challenge and hinders the clarity and separability of concerns in our codebase.

Proposed Changes:

For each of the service layer modules, the following should be completed:

  1. Introduce a Repository Layer

    • Create a new layer (Repository or DAO) specifically for handling raw database operations.
    • Define methods in the repository layer like findWithAggregation, findMatrixById, and findOneMatrixById.
  2. Refactor Service Layer

    • The service layer should call the newly defined repository methods for database operations.
    • Retain business logic, such as handling transactions and complex computations, in the service layer.
  3. Unit Testing

    • Adjust unit tests (if any) to align with the new structure.
    • Mock the repository methods when testing the service layer.
  4. Update Controllers

    • Ensure controllers remain thin and only handle HTTP requests, input validation, and returning responses.
  5. Overhaul Error Handling

    • Implement and use custom exception classes hosted by the app/exceptions module.

Tasks

@seansica seansica self-assigned this Aug 25, 2023
@seansica seansica changed the title Separate Database Logic From Service Layer Separate Database Logic From Service Layer (Proof of Concept) Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant