Avoid `domain` package to follow odpf standard
Summary
ODPF project structure standard prefer to follow domain-driven structure where each domain is located inside its domain main package inside core package.
However in guardian, we still have a domain package that holds all domains. With the approach like this, it is more likely for the developers to not separate the concern well in the further development considering there is no restriction when adding a functionality for a domain. This can also lead to more complex spaghetti code that mixed logic between several domains.
We need to follow ODPF project structure standard slowly to have a design restriction so we can be more mindful when developing a new functionalities. I am also hoping this will simplify the code base and increase the readability & predictability.
Proposed solution
I have analyzed the codebase and found there are several domains defined: appeal, policy, approval, provider, resource.
-
Move
resourceto its own package Theresourcedomain is the "lowest-level" domain that does not depend to any other domain. We can safely move this to its own domain calledresource. -
providerpackage Theproviderstruct does not depend on any domain except for aresource. It is possible to move this to its own package. However the provider service depends on theAppealstruct, this makesproviderhighly coupled withappeal. There are two options.
- Option 1
- Move ValidateAppeal to appeal
domain - Currently the
plugins/providersdepend onappealtoo as its argument. Instead of doing this, It is better for the provider plugin to have its own payload struct as a new abstraction and thenappealpackage translatesappealto the defined struct. This will avoidproviderandproviderplugins to have dependency toappeal.
- Move ValidateAppeal to appeal
- Option 2
- Move
providerstruct toproviderpackage andproviderservice to aproviderproxypackage. This might be the fastest solution to decouple in the meantime since there is no logic changed.
- Move
- Highly coupling between
appeal,policy, andapproval
- The least destructive attempt to move from
domainpackage for these packages are to club them into a single package calledappeal. - However we can do further more, decoupling
approvalandappeal & policy. The problem with current design isappealdepends on severalapprovals butapprovaldepend onappealin our domain. We can make removeappealfromapprovalto break this circular dependencies. Howeverapprovalgrpc response still needsappealas a part of its response. We could resolve this appeal in the handler layer usingappealService