- "Because the frontend data structure is just different" -> Why is it different? Could it not just use the same structure as the backend? Because if it can, then you don't need a transformation at all.
- "Because the server stores the data in a different format" -> This is not something yourYour frontend needsdoes not need to know about the storage method your backend has decided to use, and therefore you need to convert it as close toyour frontend should not be responsible for transforming the actual storage logic as possibledata appropriately
- "Because the data structure used by the frontend's JS plugin is different from the backend API structure" -> Here it makes senseYour backend does not need to transformknow about the data before sending itplugin your frontend has decided to use, and therefore your frontend should be responsible for transforming the backenddata appropriately
There is a careful balance to strike here. You strike the appropriate balance by observing your situation. If your backend is a pure REST API which exposes your actual data entities, i.e. your backend is purely a database accessing service (where the backend API will inherently always expose the exact data entities without business logic inbetween), then a lot of complexity can be cut out. IfBut your backend performs its own business logic, then the necessity of separating your layers using DTOs becomes more important.