A unified Kotlin Multiplatform (KMP) project combining a Kobweb frontend with an http4k backend server.
This is a single-module KMP project with two targets:
- Location:
site/src/jsMain - Compose-based web UI built with Kobweb
- Compiles to JavaScript/WebAssembly
- Built artifacts:
site/build/dist/js/productionExecutable/public/
- Location:
site/src/jvmMain - HTTP server built with http4k framework
- Runs on Undertow server backend (port 8080)
- Serves API endpoints and static frontend files
Build all targets:
./gradlew buildRuns the jvmMain entry point:
./gradlew jvmRunThe server will start on http://localhost:8080
GET /api/ping- Returns "pong"GET /api/health- Returns "healthy"GET /orGET /index.html- Serves the frontend (after it's built)
All endpoints support CORS with the following headers:
Access-Control-Allow-Origin: *Access-Control-Allow-Headers: Content-TypeAccess-Control-Allow-Methods: GET, POST, PUT, DELETE
site/
├── src/
│ ├── jsMain/ # Kobweb frontend (compiles to JS)
│ │ └── kotlin/
│ └── jvmMain/ # http4k server (compiles to JVM bytecode)
│ └── kotlin/xyz/malefic/dynamicsite/server/
│ ├── Main.kt # Entry point
│ └── Http.kt # Routes & handlers
├── build.gradle.kts # KMP configuration
└── build/
└── dist/js/productionExecutable/public/ # Built frontend files
The advantages of this unified KMP structure:
- Single build system - One Gradle configuration for both targets
- Shared dependencies - Common code can be placed in commonMain (if needed)
- Type-safe APIs - Frontend and backend can share Kotlin data classes
- Simplified deployment - Single module to version control and distribute
- Clean separation - Platform-specific code stays in jsMain/jvmMain respectively