Cross-Package Database Table Access #2472
KaveeshaPiumini
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
There are a few places in the backend where a package directly accesses tables that are conceptually owned by another domain/package. This weakens module boundaries and increases coupling between persistence layers.
Cross-domain table access identified
1. Theme management querying the
APPLICATIONtableTheme delete flow checks whether a theme is still referenced by applications.
Code:
References:
2. Layout management querying the
APPLICATIONtableLayout delete flow does the same check for layout references.
Code:
References:
3. Entity management querying group tables
The entity package directly reads
GROUP_MEMBER_REFERENCEand joinsGROUPto resolve direct and transitive memberships.Code:
Code:
References:
Why this is a concern
At the moment, some packages are directly reading tables that are primarily owned by other domains. That makes the package boundary less clear. This becomes a concern for a few reasons:
Ownership becomes unclear
When a package reads another package’s tables directly, it is harder to tell which package actually owns that data and its access rules.
For example, theme deletion currently depends on application storage details instead of asking application-owned logic:
Reference:
https://github.com/asgardeo/thunder/blob/main/backend/internal/design/theme/mgt/service.go#L243-L251
Schema changes can leak across domains
If the
APPLICATIONtable or group membership tables change, code in theme/layout/entity may also need to change even though those packages do not own those tables.That means a storage change in one domain can unexpectedly break another domain.
Business rules get tied to table structure
A domain should ideally depend on another domain’s behavior, not on its raw table shape.
Refactoring becomes harder
If this pattern grows, moving responsibilities later becomes more expensive because multiple packages start depending on each other’s tables directly.
Possible solution path
Introduce a neutral membership-read component or interface for group membership queries. Let
entitydelegate to that component first, and remove group-membership read responsibilities fromentity.Move
count applications by theme/layoutlogic behind a dedicated cross-domain query interface.Else update the Theme/Layout logic so that it should not directly query
APPLICATIONbefore theme/layout deletion.Open questions for the community
entityandgroupcase, should group membership be considered part of the group domain, or a shared domain that deserves its own package?Beta Was this translation helpful? Give feedback.
All reactions