Anyone have a demo or some guidance on how to comb...
# multiplatform
e
Anyone have a demo or some guidance on how to combine server and mobile app code into one project? I was hoping to share data models between server and mobile apps, but have app-related view models just compile with the Android an iOS versions. Basically, I want to share code between two parts: a JVM server app and a mobile app, where the mobile app has its own shared code and Android- and iOS-specific Kotlin code.
c
I'm not sure exactly what you're looking for, but here's a demo I wrote for a few colleagues of mine: https://github.com/CLOVIS-AI/Demo-Kounters
It's a bit of setup to learn how to create Gradle modules, but once you get the hang of it, you can create essentially any structure you want
I usually go with:
Copy code
core/ ← domain objects, shared between client and server

app/ ← the UI
app-android/ ← Android-specific UI stuff
app-ios/

http-common/ ← DTOs for the HTTP API
http-server/ ← server-side route declarations
http-client/ ← client-side route calls

backend ← just the main method that instantiates everything server-side
e
Thanks. I think the repo might be private, because I'm getting a 404 on your demo. Luckily, I think I found a repository that shows
client
code sharing as well as code shared between client and server. Just had to look a little harder.
I think I just need to practice and learn gradle more thoroughly
c
Ah, sorry 😐 This repository is public, but it's a full project, not just a demo. https://gitlab.com/opensavvy/formulaide Although the project structure is somewhat regular, the actual code is quite unusual, so keep that in mind you want to take inspiration.
e
This is super interesting. Thank you!
c
The repository you found looks good, but I'm not a fan that it uses the domain objects directly in the API instead of using DTOs.
I prefer having another shared module for DTOs instead of having them in
domain
. But the Gradle setup looks good, if that's what you're looking for
(it's written in Groovy syntax, and not Kotlin though)
e
I will keep the idea of separating DTOs in mind, thanks!
a
hi @Evan Foster you need to do multi-module multiplatfom project here is a project start you can use this will give you a kmp sdk setup , but you can teak it for kmm project needed modules : •
andoirdApp
iOSApp
jvmApi
models
<------ this is shared by backend/frontend
e
Thanks! I actually managed to get the whole thing set up, at least just with some simple greeting example code. My structure looks like this •
androidApp
iosApp
server
<— JVM Server App •
domain
<— Shared by all •
sharedApp
<— Shared by iOS and Android
It took a while to figure it all out, but I successfully ran all three apps, though they’re just simple things
a
one more, mine also combines all targets in 1 repo: https://github.com/Wavesonics/hammer-editor