I've been reading articles on Hexagonal, Onion, Clean Architectures, and other Domain-Driven Designs. A common theme they emphasize is decoupling components. From what I gather, this means the UI should be decoupled from the domain/business logic.
However, when I try to apply this concept to our project, I'm struggling to envision how we can remove all the domain logic currently embedded in the UI layer.
Here are the key domain logics we have in the UI:
- Model/View: We use JSON files where the model is tightly coupled to the data objects that the backend understands.
- Validators: Simple validations are included in the JSON files (which our in-house framework processes), but more complex validations are implemented in JavaScript. These often access the model at deep levels and apply domain-specific rules.
- Event Handling: This logic can also be quite complex. For example, if field A changes, we need to check fields B and C, compare their values with domain-specific strings, and then set a value on field D.
One potential solution we are considering is fetching the model/view JSON files from the backend via a REST API. But we’re still facing challenges with validators and event handling. We've experimented with using json-logic-js
to send rules, but even with this, we still need to keep some logic (broken into generic pieces) in the UI code.
Does this approach seem clean? Or is there a better solution already out there?