Pergunta

According to Robert C. Martin's "Clean Architecture" you should try to structure your system in such a way as to separate low-level concerns from high-level domain concepts.

Following this logic, Martin proposes, that

the Web is a delivery mechanism—an IO device—and [...]

therefore should be seen as a low-level concern. As a consequence, Web apps should only present data they receive from the domain.

In principle, a PWA could be seen as its own enclosed system with appropriate architectural boundaries, so that the app wouldn't need to have a backend which contains the domain logic. In that case, implementing the Clean Architecture would be a fairly trivial act.

But imagine your domain logic already exists on, say, a server. How would you then avoid duplicating your domain logic into the PWA if UX concepts such as offline availability are key to your product? What if your domain logic is quite sensitive and mustn't be exposed to end users under any circumstance? (e.g. by implementing it inside a PWA)

Another way to phrase the question would be: How do you build PWAs with rich UX, such as offline capability, without exposing your potentially sensitive domain logic by embedding it into the frontend?

Foi útil?

Solução

A PWA is nothing more than a Client. Clients and Servers have existed for decades, and often they share logic.

To handle shared logic the tried and tested methods are:

  • Literally share the logic as a library.
    • As web code is largely JavaScript based a Library of JavaScript
  • Duplicate the implementation, but have a single specification.
    • In short write comprehensive automation tests and run them against a PWA version, and against the Server version.
  • Break the requirement to share logic in the first place.
    • Are you certain that the logic is actually required in both places?
    • Are you 100% certain that the same forces of change are acting on both sides?
    • Are the x% of cases enabled worth the cost?

Also if you want the client to perform logic on the users computer, the logic must be exposed to that users computer. No two ways about it. So if its a strict no no for the users computer, its strictly an online only feature.

Licenciado em: CC-BY-SA com atribuição
scroll top