Balancing domain logic and interactive UI in a sales order system

I’m working on a sales order management system and I’m struggling with a design issue. Here’s my problem:

Our system lets users input orders with multiple lines. Each line can be in our base currency or a foreign one. If it’s foreign, we need to convert it using monthly exchange rates.

I think this conversion is a business rule and should be in the domain layer. But I also want the UI to be user-friendly. Ideally, when someone enters a foreign amount, the base currency amount would update automatically without submitting the form.

This seems to need some business logic in the frontend, which I’ve heard is a no-no. How can I keep the UI responsive while following good design principles? Any advice on handling this situation would be really helpful!

hey liam27, i’ve been there. try using js for a quick calc and update, but rely on server convrsn for final check. it keeps ui speedy and domain logic sound. hope it helps!

As someone who’s dealt with similar challenges, I’d suggest a hybrid approach. Implement a lightweight client-side calculation for immediate feedback, but keep the authoritative conversion logic server-side. You could expose an API endpoint that provides current exchange rates to the frontend. This way, your UI remains responsive, giving users instant updates as they input foreign amounts. However, the final conversion and validation would still occur on the server, preserving your domain logic integrity. This approach maintains a clear separation of concerns while enhancing user experience. Remember to clearly communicate to users that the displayed conversion is an estimate, subject to final server-side calculation upon submission. This strategy has worked well in my experience, balancing user-friendliness with robust business rule enforcement.

hey liam, interestin challenge! have u considered using a lightweight frontend calc for instant feedback, but keeping the heavy lifting on the server? maybe fetch current rates via API for client-side updates, then double-check everythin server-side? cud give u the best of both worlds. what do u think?