How Ballast Powers Vesper’s Kotlin Multiplatform Architecture
See how Ballast powers Vesper’s Kotlin Multiplatform architecture across UI state, navigation, saved state, server queues, and scheduled jobs.
Ballast is a crucial part of the Vesper app's architecture, serving as the Kotlin-language interface to server-side schedules and background queue workloads. Written by the author, Ballast was designed to solve specific problems and has been the foundation for Vesper's production-grade Kotlin Multiplatform (KMP) app. The source material explains how Ballast differs from the popular Redux library by leveraging Kotlin's sealed interfaces and Coroutines, while maintaining safety and flexibility.
A Ballast Contract defines the State, Inputs, and Events for a screen, enabling a highly opinionated yet adaptable code structure. In the example of a Stopwatch, the Contract outlines the State (elapsedSeconds and isRunning), and Inputs (Start, Stop, Reset, and Tick). The InputHandler processes these inputs to update the State or schedule additional work, while the ViewModel coordinates the lifecycle using a CoroutineScope.
The code is explicit and directly navigable, avoiding the use of code generation or reflection, which can be uneven on Kotlin Multiplatform. This approach results in a consistent, debuggable, and easily modifiable codebase.
Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.