> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/navigation/v2/llms.txt)

# Modularization

The Navigation SDK's architecture follows a build-time modular design, which allows you to completely replace certain functionalities with custom implementations without increasing your project's binary-size.

The goal of modularization is to enable swapping SDK modules during compilation instead of exposing runtime configuration options and relying on third-party tools to remove unused code. The SDK streamlines independent units of code into modules where possible and uses interface contracts to connect the modules. Each module has a corresponding default implementation artifact that is shipped independently and referenced by the SDK. This means default implementations can be replaced with build system tools.

## Architecture overview

The [Navigation SDK's `MapboxNavigation` class](https://docs.mapbox.com/android/navigation/v2/guides/get-started/initialization/#create-the-mapboxnavigation-object) depends on three interface contracts: [`Router`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.route/-router/), [`TripNotification`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.notification/-trip-notification/), and `Logger`. The SDK composites the implementation of these contracts at runtime to receive or send the required information.

![A chart showing a simplified overview of the Navigation SDK for Android's architecture. 'Onboard Router (offline)' and 'Offboard Router (online)' feed into 'Router'. 'Router', 'Trip Notification', and 'Logger' feed into 'MapboxNavigation'.](https://docs.mapbox.com/android/assets/ideal-img/nav-overview-core-arch-simplified.bdc6fc5.480.png)

### `Router`

The Navigation SDK's [`Router`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.route/-router/) interface defines a contract to create a `DirectionsRoute`. This `DirectionsRoute` is eventually used to compute turn-by-turn instructions and visualize the route on the map.

By default, the Navigation SDK provides a hybrid router implementation that:

1.  Requests the route from [the Mapbox Directions API](https://docs.mapbox.com/api/navigation/#directions) if the connectivity is available.
    
2.  Generates the route locally on the device if the SDK had a chance to cache the routing resources. This is a fallback if there's no connectivity.
    
    ```kotlin
    group: "com.mapbox.navigation", module: "router"
    ```
    

### `TripNotification`

[`TripNotification`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.notification/-trip-notification/) is the contract definition that fuels the Navigation SDK's notifications. These notifications are required by the Android-system foreground service that's created whenever a trip session is started. While the default Mapbox-provided implementation does allow for a certain amount of customization, completely replacing the implementation makes it possible to provide a completely custom `Notification` layout with personalized action buttons.

```kotlin
group: "com.mapbox.navigation", module: "notification"
```

### `Logger`

By default, the Mapbox-provided implementation of the logger uses the `android.util.Log` class to log any info, warning, or error level log messages. Replacing the logger implementation allows for sending or processing this information by any third-party platform to provide more value and actionable debug data.

```kotlin
group: "com.mapbox.common", module: "logger"
```

## Replacing a module

The Mapbox Navigation SDK comes bundled with runtime dependencies for all the default module implementations. You don't have to take any action to receive the SDK's default features. If your application requires additional levels of customization, you can remove any module listed from the build and replace it with a custom implementation in three steps.

For example, here's how to use Gradle to replace the logger module:

1.  Exclude the module's default implementation from the Mapbox Navigation SDK artifact's dependencies by referencing the group and artifact IDs:
    
    ```kotlin
    implementation("com.mapbox.navigation:core:2.22.2") {
        exclude group: "com.mapbox.common", module: "logger"
    }
    ```
    
2.  Add the Mapbox Annotation Processor dependency:
    
    ```kotlin
    compileOnly("com.mapbox.base:annotations:0.8.0")
    kapt("com.mapbox.base:annotations-processor:0.8.0")
    ```
    
3.  Provide the custom logger implementation by creating and annotating a class that implements the contract:
    
    ```kotlin
    @MapboxModule(MapboxModuleType.CommonLogger)
    @Keep
    object MyLogger : Logger {
    ...
    }
    ```
    

Now, compiling the project will generate all the required classes and doesn't require any additional actions.

For more information and advanced usage examples, including testing and dependency injection, read the `@MapboxModule` annotation's documentation and visit the [Mapbox Base Android repository](https://github.com/mapbox/mapbox-base-android/).