So, I was exploring newest kotlin js features. And it gave me following idea.
Let’s say I have simple frontend app on kotlin/js+react, and an it’s API backend on jvm kotlin. Frontend and backend apps are connected by HTTP REST API. There are some domain models in this REST API in the form of data classes. And they are existing in both, frontend and backend, repositories, in the same way.
So I wanna get rid of those data classes code coupling and share domain models between apps like library, compiled both for js and jvm, accessible for frontend SPA and backend API apps accordingly.
And I still can’t figure out how do I do this. Is there a possibility now for such code sharing? Which build plugins should I use for those shared data classes? What is the best way to organize repositories in this situation?
You are describing Kotlin Multiplatform, where you can share common code between the frontend and the backend. This way you can create fullstack web applications with Kotlin. You can find many example fullstack projects in GitHub - rjaros/kvision-examples: KVision examples repository (created with KVision framework).
Thanks for answer!
I’ve got a second case. I have a frontend app written on typescript, and I want to reuse API backend models in it by compiling them to js, packaging into bundle and publishing like a dependency to npm. Is this doable now?