<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mark Harper on Medium]]></title>
        <description><![CDATA[Stories by Mark Harper on Medium]]></description>
        <link>https://medium.com/@markharper.sa?source=rss-eb00faa17d4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wxO0MRvESON4GEsOLC2GjQ.jpeg</url>
            <title>Stories by Mark Harper on Medium</title>
            <link>https://medium.com/@markharper.sa?source=rss-eb00faa17d4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:51:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@markharper.sa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From UI to API: Full Stack Kotlin with Compose Multiplatform + Ktor]]></title>
            <link>https://levelup.gitconnected.com/from-ui-to-api-full-stack-kotlin-with-compose-multiplatform-ktor-19a0a253ee0d?source=rss-eb00faa17d4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19a0a253ee0d</guid>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ktor]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mark Harper]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 07:40:00 GMT</pubDate>
            <atom:updated>2025-07-14T01:33:31.216Z</atom:updated>
            <content:encoded><![CDATA[<p>Sharing code and logic across platforms with Compose and Ktor</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gdfKQpqRU0vvLCM4DTA4Ag.png" /></figure><p>It’s rare to find a tech combo that feels just right. With Compose and Ktor, full-stack dev felt less like work, more like flow.</p><p>In this post, I’ll walk you through how I combined Compose Multiplatform for the UI and Ktor for the backend to build a little demo app I call Backpack Life Sim. It’s a Kotlin-powered experience from front to back, which makes it perfect if you’re just getting started with Compose or Ktor — or if you’re just curious about building full-stack apps in Kotlin.</p><p>Whether you’re a solo dev, a Kotlin enthusiast, or just tired of juggling multiple languages and frameworks, you’ll find something useful here.</p><h3>🚧<strong>Building the App: Compose + Ktor in Action</strong></h3><p>My goal with this project was to have a shared Kotlin codebase powering both the UI (via Compose Multiplatform) and the backend logic (via Ktor). Here’s how.</p><h4>🧱Project Structure Overview</h4><p>Here’s how the app is split:</p><pre>📁 composeApp   // Android + IOS + Desktop Compose UI<br>📁 shared       // Shared KMP logic (models, use cases, etc)<br>📁 server       // Ktor backend</pre><ul><li>composeApp uses Jetpack Compose Multiplatform to show the UI and interact with the server.</li><li>shared is where we keep our common models like Item, Backpack and networking interfaces.</li><li>server runs a local Ktor server that delivers the daily items and choices for the backpack.</li></ul><h4>📦Core Dependencies (Quick Peek)</h4><p>You can find the full `libs.versions.toml` and setup in <a href="https://github.com/markxh/Backpack-Life-Sim/blob/main/gradle/libs.versions.toml">the Github repo</a>, but here’s the core stack:</p><pre>// Shared module (KMM)<br>implementation(libs.kotlinx.serialization.json)<br>implementation(libs.kotlinx.datetime)<br><br>// Server<br>implementation(libs.ktor.server.core)<br>implementation(libs.ktor.server.netty)<br>implementation(libs.ktor.serialization.kotlinx.json)<br><br>// Compose Multiplatform<br>implementation(libs.compose.runtime)<br>implementation(libs.compose.foundation)<br>implementation(libs.compose.ui)<br><br>// Dependency Injection (optional)<br>implementation(libs.koin.core)<br>implementation(libs.koin.ktor)</pre><p>Note: I’m using version catalogs for cleaner dependency management. Check out how that’s structured <a href="https://github.com/markxh/Backpack-Life-Sim/blob/main/shared/build.gradle.kts">in the repo</a>.</p><h4>🧑‍🤝‍🧑<strong>Shared Models, One Language</strong></h4><p>Both the client and server use the same data models which we defined in a shared Kotlin module. That means no duplication, no JSON mapping headaches, and full type safety across the stack.</p><pre>@Serializable<br>data class Backpack(<br>    val date: String,<br>    val items: List&lt;Item&gt;<br>)</pre><pre>@Serializable<br>data class Item(<br>    val name: String,<br>    val description: String,<br>    val type: ItemType,<br>    val rarity: Rarity,<br>    val effect: String,<br>    val imageUrl: String<br>)</pre><p>No need to redefine this in your backend or client — it’s the same class, compiled and used by both.</p><h4>🔌Communicating with the Server</h4><p>On the backend, I set up a simple Ktor server with endpoints like /backpack/today and /life-path.</p><pre>routing {<br>    get(&quot;/backpack/today&quot;) {<br>        call.respond(<br>            generateBackpack(),<br>            typeInfo = typeInfo&lt;Backpack&gt;()<br>        )<br>    }<br>}</pre><p>On the client side (Compose Multiplatform), I use Ktor’s HTTP client to fetch the backpack:</p><pre>private val httpClient = HttpClient {<br>    install(ContentNegotiation) {<br>        json(Json {<br>            ignoreUnknownKeys = true<br>            prettyPrint = true<br>            isLenient = true<br>        })<br>    }<br>}<br><br>//use this for testing locally on emulator instead of localhost<br>private val baseUrl = &quot;http://10.0.2.2:8080&quot;<br><br>suspend fun fetchBackpack(): Backpack {<br>    return httpClient.get(&quot;$baseUrl/backpack/today&quot;).body()<br>}</pre><h4>🎒The Backpack</h4><p>Once the backpack is loaded, the UI renders a list of items for the day. The user picks what to Keep, Use, or Toss. Those choices get POSTed back to the server, which stores those decisions and returns a generated life path based on them:</p><pre>suspend fun submitChoices(choices: List&lt;Choice&gt;): Result&lt;Unit&gt; {<br>    return runCatching {<br>        httpClient.post(&quot;$baseUrl/backpack/choose&quot;) {<br>            contentType(ContentType.Application.Json)<br>            setBody(choices)<br>        }<br>    }<br>}<br><br>suspend fun fetchLifePath(): LifePath {<br>    return httpClient.get(&quot;$baseUrl/life-path&quot;).body()<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*zUHnWonOwIA4GYjX-mMnJg.png" /></figure><h4>🧬 The Life Path</h4><p>Every decision — whether you keep your broken compass, or toss your moldy apple — affects your simulated journey. The server keeps track of your choices and generates a “life path” summary.</p><p>Here’s a simplified model:</p><pre>@Serializable<br>data class LifePath(<br>    val events: List&lt;LifeEvent&gt;<br>)</pre><p>And the output might look like:</p><p>“You wandered through the woods guided by your compass. Sadly, the moldy apple that you tossed could’ve saved you from a bear.”</p><h4>🧠 Why Compose + Ktor Just Works</h4><p>Here’s what I loved about this tech stack:</p><ul><li><strong>No context switching — </strong>One language means faster iteration and fewer mistakes.</li><li><strong>Shared types</strong> — When a field changes in one of your models, both your frontend and backend know about it.</li><li><strong>Kotlin for both sides— </strong>Compose for UI is declarative and modern; Ktor is flexible.</li><li><strong>Version catalogs + KMP = clean code — </strong>Keeping dependencies tidy across platforms was much easier.</li></ul><h4>🔄 What I’d Do Differently Next Time</h4><p>Some lessons and ideas for v2:</p><ul><li>Add auth or basic user profiles</li><li>Deploy the backend to Docker or similar</li><li>Add caching</li><li>Cleaner animations for cards and UI for lifepath</li></ul><h4>✨ Final Thoughts</h4><p>Using Compose Multiplatform and Ktor felt like what seamless full-stack should be. Whether you’re building a prototype or complete app, this combo gives you flexibility and simplifies development.</p><p>If you’re tired of juggling several languages and frameworks just to ship an MVP, this stack is worth exploring.</p><p>Got questions? Suggestions? Cool ideas?<br><strong>Leave a comment — I’d love to hear from you!</strong></p><p><a href="https://github.com/markxh/Backpack-Life-Sim">https://github.com/markxh/Backpack-Life-Sim</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19a0a253ee0d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/from-ui-to-api-full-stack-kotlin-with-compose-multiplatform-ktor-19a0a253ee0d">From UI to API: Full Stack Kotlin with Compose Multiplatform + Ktor</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>