Code cuisine: A recipes app built using the latest Android architecture (2024)
This project aims to showcase many of the latest tools and best coding practices recently introduced by Google for Android development.
Welcome to Simple Recipes.
This app simplifies the way you discover and manage your favorite recipes. It provides a user-friendly interface made using Jetpack Compose and ensures effortless navigation and accessibility of data for both an online and offline experience.
This project aims to showcase many of the latest tools and best coding practices recently introduced by Google for Android development. It demonstrates the latest architecture that should now be the standard for all new apps. Implementing this foundation in any new project can instantly address several problems from past development practices. These include boilerplate code, unresponsive UI, tightly coupled components, and a lack of testability and scalability.
Setting the stage with flavorful Kotlin and Gradle
At the core of this app is a pure Kotlin codebase. With Gradle as our build system, managing dependencies using version catalogs allows us to add and centralize dependencies and plugins in a scalable way. A fresh configuration or migration are both made easy when using a TOML file for version catalog. This specifies libraries, plugins, and version comprehensively to avoid hardcoding dependency names and scattered versions in individual files. The build process is further accelerated by using the new Kotlin KSP API, which enhances the power of Kotlin. Unlike KAPT, KSP can processes annotations directly in Kotlin code, which enables annotation processors to run up to 2x faster.
For more info, see: Github/KSP
Separation and prep for cooking success
Emphasizing the modular approach to app development, the code is separated into distinct layers. The domain layer contains the business logic, entities, and use cases. The data layer handles data access, manipulation, and interactions with remote and local data sources. Finally, the UI layer focuses on data presentation and event handling.
Koin plays a crucial role in facilitating this approach by providing dependency injection. This promotes modularity and testability by decoupling components and excellent management of component dependencies.
Whipping up connectivity with Retrofit
In a world that vastly relies on networking, Retrofit reigns supreme. For a number of years, Retrofit has stood strong as the leading, most developer-trusted library to simplify the process of making HTTP requests and parsing responses.
By transforming complex networking into straightforward reusable methods, it enhances readability and maintainability. In a well-structured architecture, only the data layer is aware of data sources. This ensures that changes to the data fetching logic do not affect the UI layer, which simply only makes the data requests. Further, Kotlin Coroutines cohesively works alongside Retrofit to ensure a responsive user experience by streamlining background tasks.
Spicing up storage with room
With Room, managing recipe data becomes a piece of cake (Pun maybe intended, maybe not). As a powerful ORM solution, Room has become the industry-leading solution for managing persistent data in modern Android applications. Configuring Room starts with creating a database class that specifies entities. Next, entities are defined as data classes where each field represents a column in the table. Finally, a DAO (Data Access Object) manages all the requied database operations.
Room has introduced robust capabilities to perform database operations asynchronously, and compile time verification of SQL queries never seen before in the world of Android. It seamlessly integrates with other Jetpack components such as ViewModel and StateFlows, and enables a reactive data flow to ensure that the UI remains up to date with the underlying data, and ensures a truly responsive user experience.
Composing the cherry on top
Jetpack Compose has transformed the way UIs are crafted. Gone are the days of boilerplate XML layout, with forced view binding and a non-responsive layout. With Compose, UI becomes an art form. Components are carefully designed and provide excellent scalability to be reused throughout the app. With its declarative approach and intuitive APIs, UI updates are seamlessly ingrained and straightforward animations empower the developers to bring their UI visions to life.
Please explore the complete application by visiting the following link: Simple Recipes
For developers interested in elevating this architecture for their own apps, a skeleton can be found on this link: Android Starter Code (2024)