Skip to content

refactor: decouple workflow core into template, consignment, and preconsignment packages#270

Draft
sthanikan2000 wants to merge 1 commit intoOpenNSW:mainfrom
sthanikan2000:clean-workflow-pkg
Draft

refactor: decouple workflow core into template, consignment, and preconsignment packages#270
sthanikan2000 wants to merge 1 commit intoOpenNSW:mainfrom
sthanikan2000:clean-workflow-pkg

Conversation

@sthanikan2000
Copy link
Copy Markdown
Member

Summary

This PR decouples domain-specific concerns from the workflow engine by extracting template, consignment, and pre-consignment logic into dedicated packages. The workflow package is reduced to orchestration core responsibilities, and bootstrap wiring is updated to compose the new modules directly.

The goal is to improve maintainability, reduce package coupling, and make future changes to domain behavior independent from workflow internals.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Other (please describe):

Changes Made

  • Extracted template logic from internal/workflow/service into new package:
    • internal/template/interfaces.go
    • internal/template/service.go
    • internal/template/service_test.go
    • Updated template provider flow parameter to string for decoupling from workflow domain types.
  • Extracted consignment domain logic into new package:
    • internal/consignment/model.go
    • internal/consignment/service.go
    • internal/consignment/cha_service.go
    • internal/consignment/hscode_service.go
    • internal/consignment/handler.go
    • internal/consignment/cha_handler.go
    • internal/consignment/hscode_handler.go
  • Extracted pre-consignment domain logic into new package:
    • internal/preconsignment/model.go
    • internal/preconsignment/service.go
    • internal/preconsignment/handler.go
  • Updated workflow manager construction to internalize node service creation:
    • modified internal/workflow/manager/manager.go
  • Moved workflow node service implementation into workflow manager package:
    • internal/workflow/manager/node_service.go
  • Updated bootstrap wiring in internal/app/bootstrap/app.go to use new domain packages and handlers.
  • Removed legacy workflow service/router layers:
    • deleted internal/workflow/service/*
    • deleted internal/workflow/router/*
  • Removed domain models from workflow model package:
    • deleted internal/workflow/model/cha.go
    • deleted internal/workflow/model/consignment.go
    • deleted internal/workflow/model/hs_code.go
    • deleted internal/workflow/model/pre_consignment.go
  • Updated internal/workflow/model/workflow_template_map.go:
    • changed ConsignmentFlow field type to string
    • removed direct HSCode relation
  • Updated workflow model table-name tests in internal/workflow/model/model_test.go to align with moved models.
  • Migrated service-level tests out of workflow service package into extracted domain packages.
  • Added new handler tests for extracted packages:
    • internal/consignment/handler_test.go
    • internal/consignment/hscode_handler_test.go
    • internal/preconsignment/handler_test.go

Testing

  • I have tested this change locally
  • I have added unit tests for new functionality
  • I have tested edge cases
  • All existing tests pass

Executed locally:

  • cd backend && go build ./...
  • cd backend && go test ./...
  • cd backend && go vet ./...

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked that there are no merge conflicts

Screenshots/Demo

N/A (backend/refactor-only PR)

Additional Notes

  • This refactor keeps behavior consistent while improving package boundaries.
  • internal/workflow now primarily represents orchestration core concerns (manager + workflow-specific models).

Deployment Notes

No special deployment steps required.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 significantly refactors the application's architecture by extracting domain-specific logic related to templates, consignments, and pre-consignments into their own distinct packages. This change aims to enhance modularity, reduce tight coupling within the workflow core, and improve overall maintainability, allowing for more independent evolution of domain behaviors.

Highlights

  • Architectural Decoupling: Decoupled domain-specific logic (template, consignment, pre-consignment) from the core workflow engine into new, dedicated packages to improve modularity and reduce coupling.
  • Workflow Core Simplification: The workflow package has been streamlined to focus solely on orchestration core responsibilities, with domain logic moved out.
  • Module Re-composition: Updated the application's bootstrap wiring to directly compose the newly created domain modules, reflecting the new architectural structure.
  • Model and Service Migration: Migrated domain models, their associated services, and handlers out of the workflow package into their respective new domain packages.
  • Legacy Code Removal: Removed legacy workflow/service and workflow/router layers, along with their associated tests, as their functionalities are now handled by the new domain packages.
  • Enhanced Test Coverage: Introduced new unit tests for the extracted handler logic within the consignment and preconsignment packages, ensuring continued reliability.
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.

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
Copy Markdown
Contributor

@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

The pull request successfully refactors the workflow core by decoupling domain-specific logic into dedicated template, consignment, and preconsignment packages. This significantly improves modularity, reduces package coupling, and enhances maintainability. The changes involve renaming packages, moving files, updating imports, and adjusting type references across the codebase. New unit tests have been added for the extracted handlers and services, ensuring continued test coverage. A notable improvement is the template package's GetWorkflowTemplateByHSCodeIDAndFlow method, which now accepts a generic string for the flow parameter and includes explicit validation, further enhancing decoupling and robustness.

Comment on lines +30 to +32
if flow != allowedFlowImport && flow != allowedFlowExport {
return nil, fmt.Errorf("invalid consignment flow: %s", flow)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The addition of explicit validation for the flow parameter in the GetWorkflowTemplateByHSCodeIDAndFlow method is a good practice. By accepting a generic string and then validating it against known constants, the template package maintains its independence from the consignment package's specific ConsignmentFlow enum, while still ensuring data integrity. This enhances the robustness and reusability of the template service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant