Skip to content

Can't implement cross-domain 2-dimensional checks due to current design #245

@sdurnov

Description

@sdurnov

Is your feature request related to a problem? Please describe.
I'm submitting this feature request because I found myself unable to set up NX enforce module boundaries and Sheriff to do 2-dimensional check on relations between my project's libraries.
I have a project, which kinda follows strategic design described in many Angular Architects articles.
I use NX, where I have domains, subdomains, and domain libraries of following types:

  • api
  • data-access
  • domain
  • data (when data-access is combined together with domain for simplicity)
  • feature
  • shell
  • ui
  • util

Each domain might have libraries of some or all of the types above.

I have restrictions on relationships between libraries within the domain, and that is a functionality which is possible implement with NX enforce module boundaries and Sheriff.

But I also gotta have separate rules for libraries relation between domains. I need to make sure any library in domain A can use API library from domain B, but can't use API library from its own domain.
I also want to let any library from any (or certain) domains use any library from shared domain.
For example, in shared/ I have Auth subdomain, and other libs might only use auth/api lib, but also in shared I have UI library, which can be used by certain libraries in other domains, etc.

Anyway, as you see, those restrictions can't be described by what currently NX and Sherif allow to do within 1 rule.

Describe the solution you'd like
I would like to be able to do few things:

  • define dep rule this way or similar (sorry, this syntax is ugly and dumb, but I hope you'll get the point):
tags: 'type:api && domain:<domain>': '(type:data or type:data-access or type:domain or type:feature or type:ui or type:util) and domain:<domain>',
tags: '(type:data or type:data-access) && domain:<domain>': '(type:domain or type:util) and domain:<domain>',
tags: 'type:domain && domain:<domain>': '!domain:<domain>',
tags: 'type:feature && domain:<domain>': '!type:api and !type:shell and domain:<domain>',
tags: 'type:shell && domain:<domain>': '!type:api and domain:<domain>',
tags: 'type:ui && domain:<domain>': '(type:data or type:domain or type:util) and domain:<domain>',
tags: 'type:util && domain:<domain>': 'type:domain && domain:<domain>',
//restrictions between domains
tags: 'type:app': 'type:api or type:shell or ((type:ui or type:util or type:domain) && domain:shared)',
tags: '!type:app && domain:<domain> && !domain:shared': 'type:api && !domain:<domain>',
tags: '!type:app && !domain:shared': '(type:api or type:ui or type:domain or type:util) && domain:shared',
tags: 'domain:shared': 'domain:shared:<subdomain> or domain:shared',
tags: 'domain:shared:<subdomain>': 'domain:shared:<subdomain>'
  • or just give user a single function instead of all rules, maybe together with some types and helper functions to write rules instead of direct operations with arrays and strings
(from: string | string[], to: string | string[]): boolean => {
    if (...) {
        ...
    }
}

Describe alternatives you've considered
I've checked first source code for NX rule hoping maybe I can do a quick modification to allow to define some logical expressions instead of single tag or hard combination of tags, and maybe to combine rules during checking, not cancelling previous rule with the next one, but I gave up the idea for now, hoping maybe that Sherif has something not obvious to cover my needs, or planned it for the near future

Additional context
Here is a small part of my project graph in NX. it shows job applications domain, which has libs of type:shell, type:data-access, type:domain, type:util, several type:feature (though type:shell one is named incorrectly as feature-wizard-shell). There's also shared libs, where we have plain type:ui and type:util libs, as well as a whole auth subdomain with its set of libs resembling a typical domain. And here you can see I forbidden link - someone referenced auth-feature-auth-v3 directly, instead of reexporting something he needed via auth-api lib.
There are also few connections going ouside to the app, which is cut off the screenshot

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions