Hello, I recently discovered Kotlin and IDEA and b...
# getting-started
j
Hello, I recently discovered Kotlin and IDEA and been loving them both. i'm currently using Kotlin for a project where I have an API that handles the business logic and, apparently, people at administration don't fancy doing cURL requests and want a web and an android client to consume it. Am I better off doing the api and the two clients each in a separate project, for three total, or all in kotlin multiplatform?
I also have the api ktor server in a project and the business logic in another. Is it better to move the ktor implementation to the business logic, or move the business logic to the ktor server project?
p
that is a deep architectural question. In my experience, people usually have the server side stuff together, then have the android app be its own then. It depends entirely on the technology you’re using for the web. If you want the web to be a Single Page Application, you could build it separately and host it separately, or you can build and host it as part of the ktor application. I wouldn’t do an SPA in Kotlin/JS, though. Too much faff and learning curve at the moment.
a
I'd keep the service logic and the clients in separate projects personally. Separating server from business logic, from an arch and DDD perspective is actually a good thing, that way if you to change how that business logic is delivered at some point (say they want an android app that works offline), then you don't have to worry about breaking the business logic back out of the service logic if you happen to get another dev in there that breaks your encapsulation, they can't because it's different projects (and you can't either if somebody comes yelling about faster)
👍 1
but, like I love to say in architecture, everything is trade offs
j
That's what I thought. Also Multiplatform is in beta.
Which leaves the ktor question open, is that a question better suited for #ktor ?
p
Ktor is good
j
Oh, I meant the question above, I have business logic and the ktor server in separate projects, which one do I migrate to the other?
t
Personally I prefer to keep the web logic and the business logic next to each other. (In gradle I typically have a multi module project with two sub modules, where one keeps the business logic and the other one the web/ server logic)
a
yea, that works too, Architecturally speaking, as long as you can't accidentally reference them directly across, you're in a better spot
j
Yeah, I have them separate.
Now, for some reason when I added my business logic to the project, one data class I was using stopped serializing.
t
You are sure that the ktor server is exposing a data class and not a standard class?
j
Yeah, the server used to serialize the class no problem before.
It's a
@Serializable
data class Customer( blah blah)
t
And what does the exception look like?
j
Let me recompile, I was checking the code when it was just the server and it worke.d
kotlinx.serialization.SerializationException: Serializer for class 'Client' is not found. Mark the class as @Serializable or provide the serializer explicitly.
Only thing I can think of is I tricked the compiler to think there's another 'Client' class that's non-serializable when it's called.
t
Could you check your packages briefly? It might be the case that there are two kinds of clients in the same package due to some dependencies?
j
Maybe, that will have to wait until monday tho.
Just in case anyone wants to know, I was missing the kotlin serialization plugin in my gradle.build file!
K 1