Nav3 Generator
A powerful KSP-based navigation generator for Compose Multiplatform Navigation 3. It automates route definitions, polymorphic serialization, and screen mapping to provide a type-safe, boilerplate-free navigation experience across Android, iOS, Desktop, and Web.
It includes:
Versions

📦 Setup
Add to commonMain dependencies
implementation("io.github.the-best-is-best:nav3-annotations:1.1.0")
Add the KSP processor to your project:
dependencies {
add("kspCommonMainMetadata", "io.github.the-best-is-best:nav3-processor:1.1.0")
add("kspAndroid", "io.github.the-best-is-best:nav3-processor:1.1.0")
add("kspIosArm64", "io.github.the-best-is-best:nav3-processor:1.1.0")
add("kspIosSimulatorArm64", "io.github.the-best-is-best:nav3-processor:1.1.0")
}
To start generator
./gradlew :shared:assemble
🧩 Available Annotations
@NavGenerate
Attach to an interface to mark it as the base for generated routes.
@NavGenerate
interface Routes : NavKey
@NavDestination
Attach to a Composable function to generate a route for it.
@Target(AnnotationTarget.FUNCTION)
annotation class NavDestination(
val name: String = "",
val group: String = "",
val wrapper: String = ""
)
🛠️ Example Usage
1. Define your base interface
@NavGenerate
interface Routes : NavKey
2. Annotate your Screens
@Composable
@NavDestination(name = "Home", group = "Secure", wrapper = "SecureWrapper")
fun HomeScreen(
x: Int,
onDialogOpen: (Boolean) -> Unit
) {
Text("Home Screen with value $x")
}
3. Usage in App
@Composable
fun App() {
val backStack = rememberRoutesBackStack(initialKey = RoutesDestinations.Splash)
var isDialogOpen by remember { mutableStateOf(false) }
val homeActions = RoutesHomeActions(
onDialogOpen = { isDialogOpen = it },
onBack = { backStack.removeLastOrNull() }
)
CompositionLocalProvider(LocalRoutesHomeActions provides homeActions) {
NavDisplay<Routes>(
backStack = backStack,
onBack = { backStack.removeLastOrNull() },
entryProvider = { key -> routesEntryProvider(key) }
)
}
}
⚙️ Setup (Kotlin Multiplatform + KSP)
kotlin {
sourceSets.named("commonMain").configure {
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}
}
📍 Notes
- Generated code path:
build/generated/ksp/
🎉 Done