My recent go-to architecture for web/mobile apps h...
# kvision
r
My recent go-to architecture for web/mobile apps has been a typed backend API via graphql, consumed with Apollo multi-platform on mobile and Apollo Client on web. I'm starting a new side project and am considering other approaches, like KVision. One thing that scares me is that KVision moves me in a direction away from the "native frontend" approach that JetBrains/KMM is pushing. For example, I don't want to use Cordova for Android -- I want to use Compose. I'd like to experiment with Compose for web and potentially desktop as well. Is anyone using the RPC layer from KVision, but integrating that with native client UI?
r
In my opinion JB pushes KMP in two opposite directions at the same time ๐Ÿ™‚
r
How so?
r
One is "native frontend" (UI created with technology native to the target) and at the same time they are creating Compose, which works on multiple targets (compose-android, compose-desktop, compose-web).
It like flutter.
r
Compose components (at least for now) are not intended to be cross-platform. Its the architecture that is shared, not the components (unlike Flutter).
r
There are signs they are going to reimplement compose with skia to get shared ui components.
r
That may be true but in a way that just reinforces the need to keep my RPC logic separate from my client UI -- I want my client UI to use whatever tech is best for that platform, whereas my RPC layer is just business logic.
r
I would say KVision is native frontend UI for the web (just like swift ui for ios).
r
So you wouldn't recommend using KVision for just the RPC layer?
r
I'm not sure it will work, because you would have to create multiplatform client. There is no such client at the moment.
r
Its got everything I want for that layer. A type-safe RPC layer with the serialization essentially being an implementation detail. I don't need the API to be public so I don't want to pay the cost to design a REST or GraphQL layer -- its just not necessary. Would be a shame if I couldn't leverage that across native mobile and desktop apps as well as the web.
r
Have to go now but we can talk about it later.
๐Ÿ†— 1
r
I'm not sure it will work, because you would have to create multiplatform client. There is no such client at the moment.
Ah missed this. In general, what would be involved? I imagine most of the KVision code, such as serialization and coroutines, should work well in common code, but the networking layer would have to be multi-platform. Though that particular problem has been solved by libraries like Ktor client.
r
Writing generic clients for different platforms should be possible, but I don't really have any experience with native targets.
The other thing is extending current compiler plugin to support other platforms.
r
I have some experience with native targets, but I'm not sure much will actually be that necessary. What does KVision use for its networking calls? The compiler plugin generates code, I'm assuming? Is there any obvious reason that generated code couldn't be multi-platform? If you are willing to mentor me WRT kvision, I could try to tackle this in my spare time. Ideally, I'd like to see the KVision RPC layer pulled out into a separate multi-platform module that can be used by the KVision web client-side, but also independent of it on any Kotlin-supported platform.
r
KVision uses its own wrapper over Fetch API.
r
Ok, so we'd definitely have to abstract that. I doubt that will be too difficult.
r
The kvision-remote module is already independent from the rest of the project. It should be possible to just add other targets.
๐Ÿ‘ 1
r
Doesn't look like the compiler plugin is doing anything too complex -- seems like it would be easy enough to modify this to run against the additional targets
r
The one thing that raises my doubts is my current deserialization code. I'm using some very dirty hacks, which I have implemented to workaround issues I don't even remember well ๐Ÿ˜‰ Those are mostly Enum issues.
r
But there are also some direct references to JS built in types.
I should try to clean this code because those hacks could be no more necessary.
๐Ÿ‘ 1
It would be a lot easier to be sure standard serialization/deserialization just works ๐Ÿ™‚
r
For sure. Overall seems totally doable though. WDYT?
r
Would love to see this working ๐Ÿ™‚
r
The networking layer could be replaced with Ktor client, which is multi-platform and already uses the fetch api in the browser. But it also supports JVM, Android and iOS, and other native targets via various platform engines.
r
Ktor client for JS is currently unusable because of bundle size. I would definitely want to stay with my wrapper for JS. But it should be possible to use ktor on other targets.
r
Makes sense. Yeah, I see this issue: https://youtrack.jetbrains.com/issue/KTOR-1084.
r
I'm quite busy working for living lately, but I'll try to prepare for multiplatform rpc as soon as I find time. I'll let you know if you are willing to help ๐Ÿ™‚
r
Absolutely, feel free to reach out to me. I'm in the same situation, but I'd love to see this working for future projects I have in mind.
r
Just take any of the fullstack templates, remove all kvision frontend modules, add some other dependencies and you are probably ready to go.