SnapLedger is a local-first receipt and expense tracker I built for the KotlinConf Student Coding Competition. It targets Android, iOS, and Desktop, with a standalone server and an embedded Desktop LAN Hub for synchronization. I measured the shared-code ratio with the repository’s own ./scripts/shared-code-ratio.sh: 7,396 shared production Kotlin lines out of 8,160 client lines, or 90.64%.
The high-level module layout is intentionally small:
:core pure domain logic :app:shared Compose Multiplatform app and data layer :app:androidApp Android shell :app:desktopApp Desktop JVM shell :sync-host embedded LAN sync engine :server standalone Ktor backend Module boundaries did most of the work
The biggest architectural decision was keeping :core free from Android and UI dependencies. That module contains domain models and deterministic logic such as SpendAnalytics, CSV generation, HTML report generation, receipt parsing, and Last-Write-Wins synchronization rules.
For example, SpendAnalytics computes the primary currency, totals, billable ratio, and category slices from ledger entries. HtmlReportExporter turns the same domain data into a self-contained, HTML-escaped report. Both are pure Kotlin, so their behavior and tests do not need platform forks.
This is the lesson I would emphasize: do not wait until the end of a project to separate domain logic from Compose and platform glue. Enforce the boundary at the Gradle module level on day one. A clean module dependency graph makes shared code the default instead of an extraction project you postpone until the deadline.
Receipt persistence and image decoding are real platform work
File I/O and image handling are where many KMP demos quietly become platform-specific—or leave one target stubbed. SnapLedger keeps the contract shared through ReceiptImageStore, then provides actual Android and iOS implementations. Android writes under the app’s private receipts directory with path-containment checks, symlink rejection, and atomic moves. iOS uses NSFileManager and atomic NSData writes in the documents directory.
The platform boundary for decoding is deliberately thin. Android uses BitmapFactory; Desktop and iOS use Skia’s Image.makeFromEncoded. Shared Compose code loads thumbnails off the main thread and applies a bounded preview size. FileKit 0.17.0 handles cross-platform file picking and export flows, while receipt storage remains behind the repository abstraction.
Local-first binary sync over LAN
I chose a Desktop LAN Hub instead of making a cloud backend mandatory. The result is a faster offline-first workflow with no cloud lock-in: the phone and Desktop can exchange ledger data directly on the local network.
A sync cycle has four phases. First, the client posts pending ledger entries and applies Last-Write-Wins reconciliation. Next, it best-effort uploads locally available receipt images with idempotent PUT requests. It then downloads missing images with GET. Finally, receipt-transfer failures remain isolated from a successful ledger sync and can be retried on the next cycle. The protocol also exposes a WebSocket event stream for live connection status.
That separation matters. A missing image should not roll back a valid ledger update or corrupt local state.
Your browser does not support embedded video. [Watch the SnapLedger demo](https://media.affirmi.tech/social/snapledger-demo.mp4).Guardrails against hackathon spaghetti
The quality gate runs Spotless, Detekt, tests, Kover verification, Desktop compilation, and an Android debug build. Detekt caps cyclomatic complexity at 10 and requires documentation for public APIs. A custom checkFileLength task rejects Kotlin files over 300 lines. The project also avoids unsafe nullable calls and keeps coverage thresholds enforced rather than lowering them to make CI pass.
The honest KMP lesson is that shared code is not achieved by hiding platform work. It comes from putting most business behavior in pure modules, isolating the unavoidable platform seams, and measuring the result with a reproducible definition.
Source: SnapLedger on GitHub