Navigating the Confluence of Hexagonal and Clean Architecture in a Jetpack Compose Metropolis

In our last article, we discussed a layer-based architecture, now we are moving to explore a feature-based, multi-module approach. This time, we use a story to illustrate this technical concept and bring it to life.

Süleyman Başaranoğlu
6 min readJan 28, 2024

The Vision of Self-Sufficient Districts

Imagine entering a city where each district is complete with its regulations and amenities. This vision inspired the development of our application, with each feature crafted to be an independent ‘district’ within the app’s expansive ‘city.’

Our Application & Our City

This article will spotlight two critical infrastructures that sustain this vision: our multi-architectural(Clean Architecture with Hexagonal Architecture) approach and our independent Navigation Pattern with Jetpack Compose.
These underpinnings are crucial to our app’s functionality, ensuring that each district not only prospers independently but also integrates seamlessly into the city’s fabric.

The Story of Our City

In contrast to previous technical deep dives, this piece unfolds like a story, bringing to life the creation of a new feature & new district in our urban app landscape. Before diving into this narrative, I would advise readers interested in the more technical aspects to initially review the general framework of the project outlined and the Multi Module Hierarchy & System Design below.

System Design & Multi Module

New Feature Born: Districts and Their Layers

Envision the born of a new feature as the emergence of a new, district in our app city. It’s analogous to the opening of a unique café that instantly becomes the talk of the district, offering new flavors and experiences. Each district is comprised of layers mirroring the multifaceted neighborhoods of a city district.

District

P.S. It’s important to note that the choice to centralize shared structures in a Common&Core space depends on what’s most effective for your app’s ecosystem. Flexibility is essential, just as cities provide shared utilities for their districts, your app should offer shared services for each module to ensure a cohesive yet adaptable environment.

The Layers of Our Districts

Just as a district has neighborhoods like residential, commercial, and industrial, our modules are split into layers — Data, Domain, and Presentation.

Within Data, we further break it down into API, Persistence, and Domain-Implementation. It’s like having different streets within neighborhoods — each has a specific role to ensure the whole operation runs smoothly. For instance, Domain-Implementation acts as the diplomatic envoy of the Data district, solely liaising with the Domain neighborhood, akin to an embassy communicating on behalf of its nation. Below is the sample feature module image for more technical details.

Sample Feature Module

Thanks to Domain-Implementation, ensures that our Architectures and projects are Domain independent, which is our one of main goals.

This specialized layer serves as the communication hub between the Domain and other neighborhoods like Data. By handling the intricacies of interfacing with different layers, Domain-Implementation ensures that the Domain remains independent and self-contained, focused on its core principles without being influenced or dictated by external factors.

Lonely Neighborhood Domain
  • The API sector manages external communications with remote servers, akin to an international trade district.
  • The Persistence sector is like local markets and storage facilities, securing what’s needed close at hand.
  • And Domain Implementation? That’s where the magic happens — it’s the city planners, taking all the information and translating it into actionable plans.
Feature Module Layers

A Melting Pot of Architectural Styles

Our city’s districts are interconnected parts of a larger community. Combining Hexagonal and Clean architectures allows us to link these districts while protecting the core domain logic from the city’s hustle and bustle.

The evocative picture with Domain

The main purpose is to create a Domain with a native structure that does not depend on anywhere. Our app embraces the diversity of architectural styles, from the sleek high-rises of Clean Architecture to the robust civic centers of Hexagonal Architecture. Each team, or ‘district’, chooses what suits them best.

Hexagonal architecture opinion

Navigating the City: The Unseen Yet Vital Paths

Our app’s navigation mirrors the city’s underlying pathways, guiding residents from one district to another, invisible yet indispensable for the city’s dynamism.

With this Navigation Module & Navigation District, the interdependence of features, that is, neighborhoods, is eliminated. The Navigation Module & Navigation District does not know the features. It provides communication with an Interface located in our Core module, our main neighborhood.

Abstract Interface

The Navigation Hubs

Our Compose Activity (Root & Single Activity) serves as the city’s central station, directing you to different districts, each alive with its unique experiences. When you’re in the Home district and you click on a product or banner, it’s not just a transaction — it’s an invitation to another part of town.

Compose Activity

New Features Born in our Metropolis

Introducing a new district requires determining its nature — will it be a standalone park or a lively market needing information from elsewhere? This decision shapes how the district integrates into the city’s overall plan(2.2).

P.S. Please check picture 2.2 and the code base for better understanding.

New Module Born

The Essence of Our App City: More Than an Application

Our app is more than just a platform; it’s a living city that’s continuously growing and evolving. It’s not just built to last but designed to adapt, expand, and flourish through time. This means building a project that allows us to do forward-looking development while doing a project, that it can grow much more in the future, that different people will be integrated into the team, different domains will be added, and that each new person will make rapid development without making things difficult.

Independence and Interconnectivity: The Endgame

By eschewing a single architectural pattern, we enable each team to work autonomously and empower teams to work independently. fostering a cityscape where intuitive navigation and seamless inter-district cooperation are the norms.

We should not forget that each of these applications has advantages and disadvantages. I tried to write the advantages and disadvantages of each of these on Git Hub. Additionally, it is up to you to choose whether this article and the differences used will be compatible with your project, team, and dynamics. Please see more details of the project on GitHub I shared below.

For a more in-depth look at the methodologies employed, refer to our detailed analyses on GitHub.

For Jetpack Compose Fully Projects

Multi Module( Layer Based)with Clean Architecture & MVVM+MVIÂ

Boost Your Android App with CPU Profiling

Boost Your Android App with and Mastering with Memory Profiling

Enhancing Code Quality Lint with Custom Rules

Jetpack Compose Bad and Best Practices

--

--