Hey guys, I was wondering if there is some “best practices” or how do you guys tend to organize domains and resources in Ash.
Here is how I do it right now:
project
|___ domain 1
| |___ resource A
| |___ resource B
|___ domain 2
|___ resource A (Shares same table from resource A in domain 1 but possibly with some different attributes and actions)
|___ resource C
So, all resources needs to be used in one, and only one, domain, if the resource needs to be used in another domain, a new resource is created inside the scope of that new domain and the attributes needed for it are copied over.
Advantages:
- IMO this makes things easier to understand since I have a guarantee that each resource in my system can only affect one domain;
- It is easier to navigate through code since I know all resources for that specific domain resides inside that domain directory.
Disadvantages:
- If you have a resource that needs to be used in multiple domains, it creates a bunch of duplicated code;
- When changing a resource attribute (and other stuff too), I always need to make sure that the change is done in all resources from other domains that share the same table.
Here are some other organization alternatives I though about:
- Have a “common” domain directory to move resources that are commonly used in multiple domains.
That would probably lower code duplication, specially for a resource likeuser
which is probably shared between a lot of domains. But, at the same time, it seems like a place where a dev would use to put anything inside just because it is “easier”, making the thing a mess in the end. - Have directories with resources that don’t have a domain associated to it. This one is similar to (1), but instead of having a “generic” common directory and put everything there, we would have directories that state the resources inside “business” clearly. For example, there could be an
account
directory with anuser
resource inside, and then I can have anauth
domain that will share thataccount/user
resource with other domains. - Break some resources between Spark parts and move the shared parts to a “common” place. For example, let’s say I have an
user
resource that needs to be shared by multiple domains. For each domain, the actions for that resource changes, but the attributes are the same. In that case, I could move the attributes part of that resource to a common place and create a new resource in each domain for theuser
and just “import” the attributes for it.
Anyway, these are just some of ideas I was thinking of. How do you normally organize these in your code? And what are the advantages and issues you found with your strategy?