Kodices
0.4.0indexedParses JSON models to describe user interfaces, featuring a reference GUI implementation and a sample application demonstrating usage.
Parses JSON models to describe user interfaces, featuring a reference GUI implementation and a sample application demonstrating usage.
Kodices is a Server-Driven UI framework for Kotlin Multiplatform. It allows you to define your user interfaces using JSON, which can be fetched from a server at runtime. This enables you to update your app's UI without shipping a new version to the app store. A reference implementation and an example that use Compose multiplatform are provided, however you can integrate Kodices with Native UI or other UI frameworks.
This repository contains different modules to help you get started:
+--------------+ +--------------------+ +-----------------+
| | | | | |
| KodexRenderer|---->| Kodices |---->| Piktographs |
| (JSON source)| | (Core functonality)| | (Reference UI) |
| | | | | |
+--------------+ +--------------------+ +-----------------+
To get started, clone the repository and build the project.
You can add Kodices to your own Kotlin Multiplatform project by adding the following dependencies to your build.gradle.kts file.
dependencies {
// Core parsing logic
implementation("com.iktwo:kodices:<latest_version>")
// Jetpack Compose UI rendering
implementation("com.iktwo:piktographs:<latest_version>")
}
Please replace <latest_version> with the latest version from the releases page.
Here is a minimal example of how to parse a JSON string and render it with Piktographs:
import com.iktwo.kodices.KodicesParser
import com.iktwo.piktographs.PageUI
import androidx.compose.runtime.Composable
@Composable
fun MyScreen(jsonString: String) {
// 1. Initialize the parser
val kodicesParser = KodicesParser()
// 2. Parse the JSON string into a Content object
val content = kodicesParser.parseJSONToContent(jsonString)
(content != ) {
PageUI(content)
}
}
KodexRenderer renders Kodices screens through Piktographs headlessly to PNG images served over HTTP, so an e-ink tablet can show a server-driven dashboard by polling for a picture (self-hosted, in the spirit of TRMNL). It is a separate JVM module because Compose UI cannot run on Kotlin/Native.
./gradlew :KodexRenderer:run # http://localhost:8090
./gradlew :KodexRenderer:renderSample # KodexRenderer/build/render/dashboard.png, no server
To add a screen, put <name>.json (any Kodices content, optionally wrapped as
{"content": ..., "data": ...}) in KodexRenderer/screens/; it is served at
with no restart. Screens can show the current date through the injected data, and bundled
images through URLs. Set to require a bearer token. Configuration,
Docker and the rendering details are in the .
explains how to write a screen, with the
JSON for every element and three sample dashboards.
KodexViewer shows the screens of any server that speaks the same JSON
protocol (GET /screens, GET /content/{screen}.json), natively and live: an operator dashboard
for your own service, or KodexRenderer's screens in color.
./gradlew :KodexViewer:run --args="--url http://localhost:8090" # desktop window
./gradlew :KodexViewer:wasmJsBrowserDistribution # static web bundle
git clone https://github.com/Iktwo/Kodices.git
cd Kodices
Build the project: This command will build all the modules and make them ready for use.
./gradlew build
Run the SampleApp:
The easiest way to see Kodices in action is to run the SampleApp on your desktop.
./gradlew :SampleApp:run
You should see a window with the sample application, which demonstrates various features of the Kodices framework.
| Endpoint |
|---|
GET /health | 200 ok |
GET /display?device=<id> | {"image_url": "/render/dashboard.png?width=954&height=1696&mode=gray16", "refresh_seconds": 900, "etag": "..."} |
GET /render/{screen}.png?width=&height=&mode= | PNG (mode = gray16 default, bw, color) with a strong ETag; 304 on a matching If-None-Match |
GET /render/{screen}.json | The screen's source JSON |
GET /screens, GET /content/{screen}.json, GET /assets/{path} | The same screens as JSON, for an app that renders them itself with Piktographs (the SampleApp's Dashboard tab) |
/render/<name>.pngnowasset:<file>KODEX_TOKENSurfaced from shared tags and platforms — no rankings paid for.