This recipe demonstrates how to structure a multi-module application using Navigation 3 and Koin for dependency injection. The goal is to create a decoupled architecture where navigation is defined and implemented in separate feature modules. It relies on the koin-compose-navigation3 artifact.
The application is divided into several Android modules:
-
appmodule: This is the main application module. Itincludes()the feature modules and initializes a commonNavigator. -
commonmodule: This module contains the core navigation logic used by both the application module and the feature modules. Namely, it defines aNavigatorclass that manages the back stack. -
Feature modules (e.g.,
conversation,profile): Each feature is split into two sub-modules:apimodule: Defines the public API for the feature, including its navigation routes. This allows other modules to navigate to this feature without needing to know about its implementation details.implmodule: Provides the implementation of the feature, including its composables and KoinModule. The Koin module uses thenavigationDSL to define the entry provider installers for the feature module.
This modular approach allows for a clean separation of concerns, making the codebase more scalable and maintainable. Each feature is responsible for its own navigation logic, and the app module only combines these pieces together.