Skip to content

refactor(resource-app)[Backend] Refactor Resource Domain to Domain-Driven Design (DDD)#51

Open
saknarajapakshe wants to merge 2 commits intoLSFLK:mainfrom
saknarajapakshe:refactor/resourceapp-backend
Open

refactor(resource-app)[Backend] Refactor Resource Domain to Domain-Driven Design (DDD)#51
saknarajapakshe wants to merge 2 commits intoLSFLK:mainfrom
saknarajapakshe:refactor/resourceapp-backend

Conversation

@saknarajapakshe
Copy link
Contributor

Overview

This PR completes the Domain-Driven Design (DDD) refactor for the Resource bounded context. It introduces a proper repository layer, decouples resource.Service from GORM, and keeps existing /api/resources behavior unchanged.


What Changed

✅ Core Refactor

  • Added resource.Repository interface to abstract data access
  • Implemented GormRepository as the concrete GORM-backed repository
  • Refactored resource.Service to depend on the repository interface instead of *gorm.DB

✅ Route/Handler Wiring

  • Updated cmd/server/main.go to compose:
    • GormRepositoryresource.Service → handler functions
  • Kept all /api/resources handler signatures unchanged

✅ Database Migration

  • Updated internal/db/db.go to auto-migrate resource.Resource

How to Test Locally

  1. Ensure MySQL is running and configured per .env
  2. Run the server:
    cd resource-app/backend
    go run ./cmd/server/main.go
  3. Verify endpoints:
    • GET http://localhost:8082/api/resources
    • POST http://localhost:8082/api/resources
    • PUT http://localhost:8082/api/resources/{id}
    • DELETE http://localhost:8082/api/resources/{id}

Closes #50

@saknarajapakshe saknarajapakshe requested review from a team and Copilot March 13, 2026 07:18
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request completes a significant refactor of the Resource domain, aligning it with Domain-Driven Design (DDD) principles. The primary goal was to introduce a clear separation of concerns by establishing a dedicated repository layer, thereby decoupling the resource service from direct GORM interactions. This change enhances maintainability and testability without altering the external behavior of the /api/resources endpoints.

Highlights

  • Core Refactor: Introduced a resource.Repository interface to abstract data access, implemented GormRepository as the concrete GORM-backed repository, and refactored resource.Service to depend on this new repository interface instead of *gorm.DB.
  • Route/Handler Wiring: Updated cmd/server/main.go to compose GormRepository with resource.Service and then with the handler functions, ensuring all existing /api/resources handler signatures remain unchanged.
  • Database Migration: Modified internal/db/db.go to correctly auto-migrate the new resource.Resource model.
Changelog
  • resource-app/backend/cmd/server/main.go
    • Imported the new resource package.
    • Initialized GormRepository and resource.Service.
    • Updated the /api/resources routes to utilize the new resource.Service handlers.
    • Commented out the /api/stats route.
  • resource-app/backend/internal/api/handlers.go
    • Removed all resource-related handler functions (HandleGetResources, HandleAddResource, HandleUpdateResource, HandleDeleteResource).
    • Commented out the HandleGetStats function.
  • resource-app/backend/internal/db/db.go
    • Imported the new resource package.
    • Updated the AutoMigrate call to reference resource.Resource instead of models.Resource.
  • resource-app/backend/internal/models/models.go
    • Removed the Resource struct definition from this file.
  • resource-app/backend/internal/store/db_store.go
    • Imported the new resource package.
    • Removed all resource-specific data access methods (GetResources, AddResource, UpdateResource, DeleteResource, GetResourceByID).
    • Updated references to models.Resource in CreateBooking and RescheduleBooking to resource.Resource.
    • Commented out the GetUtilizationStats function and related ResourceUsageStats struct.
  • resource-app/backend/resource/handlers.go
    • Added a new file containing the API handler functions for resources (HandleGetResources, HandleAddResource, HandleUpdateResource, HandleDeleteResource), which now interact with the resource.Service.
  • resource-app/backend/resource/models.go
    • Added a new file to define the Resource struct, moving it from internal/models.
  • resource-app/backend/resource/repository.go
    • Added a new file defining the Repository interface and its GORM implementation, GormRepository, for resource data operations.
  • resource-app/backend/resource/services.go
    • Added a new file defining the Service struct, which encapsulates the business logic for resources and depends on the Repository interface.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of introducing a repository layer to abstract data access for the resource domain, which is a foundational step in a Domain-Driven Design refactor. The separation of concerns is much clearer now.

My review includes a couple of suggestions to further align the implementation with DDD principles. Specifically, I've pointed out opportunities to move business logic from the HTTP handlers into the newly created resource.Service. This will make the service layer more meaningful by having it orchestrate the domain logic (like generating IDs), rather than just acting as a simple pass-through to the repository. This will strengthen the domain layer and make the handlers cleaner.

Overall, this is a solid refactoring. Addressing the feedback will help complete the transition to a more robust, domain-centric design.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the DDD refactor for the Resource bounded context by introducing a repository + service layer in the resource package and rewiring the server to use it, while migrating the Resource model out of internal/models.

Changes:

  • Introduces resource.Repository + resource.GormRepository and refactors resource.Service to depend on the repository interface.
  • Moves resource CRUD HTTP handlers into the resource package and wires /api/resources routes to the new service in cmd/server/main.go.
  • Migrates the Resource model from internal/models to resource and updates DB auto-migration + booking-time row-locking to use the new model.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
resource-app/backend/resource/services.go Adds Service that delegates to a repository interface.
resource-app/backend/resource/repository.go Adds repository interface and GORM-backed implementation.
resource-app/backend/resource/models.go Defines the resource.Resource GORM model.
resource-app/backend/resource/handlers.go Implements /api/resources handlers using *resource.Service.
resource-app/backend/internal/store/db_store.go Removes resource CRUD from DBStore; updates booking locking to use resource.Resource; stats code commented out.
resource-app/backend/internal/models/models.go Removes models.Resource (resource model moved to resource package).
resource-app/backend/internal/db/db.go Auto-migrates resource.Resource instead of models.Resource.
resource-app/backend/internal/api/handlers.go Removes legacy resource handlers; stats handler commented out.
resource-app/backend/cmd/server/main.go Composes GormRepository -> Service -> resource handlers; stats route commented out.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…pository layers

refactor(resource): remove redundant comment from Resource model
@saknarajapakshe saknarajapakshe force-pushed the refactor/resourceapp-backend branch from 8a1500f to b00da67 Compare March 13, 2026 09:05
refactor(resource): remove redundant resource creation logic in HandleAddResource
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.

[ResourceApp][Backend][REFACTOR] Refactor Resource Domain to Domain-Driven Design (DDD)

2 participants