Questions tagged [clean-architecture]

The Clean Architecture is a software architecture proposed by Robert C. Martin (better known as Uncle Bob). This architecture is similar to the Onion-Hexagonal-DCI-Architecture proposed by their respective authors. The base of this architecture is to follow and obey rules of the 'Dependency Rule'.

The Clean Architecture is proposed by Robert C. Martin, also known as Uncle Bob. This architecture is similar to the Onion, Hexagonal, Screaming, and DCI architectures. Though these architectures all vary somewhat in their details, they are very similar. They all have the same objective, which is the separation of concerns. They all achieve this separation by dividing the software into layers.

clean architecture diagram Robert C. Martin, The Clean Architecture, 2012

The foundation layers of The Clean Architecture are:

  • Entities (Enterprise Business Rules)
  • Use cases (Application Business Rules)
  • Interface Adapters
  • Frameworks and Drivers.

The rules are driven by The Dependency Rule, which states that:

...source code dependencies can only point inwards. Nothing in an inner circle can know anything at all about something in an outer circle. In particular, the name of something declared in an outer circle must not be mentioned by the code in the an inner circle. That includes, functions, classes. variables, or any other named software entity.

Finally, when obeying this rule and using this architecture it is proposed that:

By separating the software into layers, and conforming to The Dependency Rule, you will create a system that is intrinsically testable, with all the benefits that implies.

1110 questions
13
votes
1 answer

Clean architecture. What are the jobs of presenter?

I have been reading some articles about the clean architecture, and how it can be implemented in android. I saw the sample app which shows its Android Implementation. Also, I went through a nice talk on Clean architecture on Android So, I kind of…
user4260260
13
votes
1 answer

Android Clean Architecture UseCase for each method of repository?

Does we need to create UseCases for each method from Repository interface in domain layer? For example assume that I have such Repository interface interface ThingRepository { void create(Thing thing); void delete(Thing thing); …
Mike Herasimov
  • 1,319
  • 3
  • 14
  • 31
12
votes
3 answers

Factory methods vs inject framework in Python - what is cleaner?

What I usually do in my applications is that I create all my services/dao/repo/clients using factory methods class Service: def init(self, db): self._db = db @classmethod def from_env(cls): return…
12
votes
1 answer

Is use case depending on another use case anti pattern?

I have 2 use cases LoadA and LoadSettings, in LoadA I need to access the Settings returned from LoadSettings. The business is designed so that if Settings is not yet exist then a default Setting would be returned. The default initialization logic is…
Chinh Nguyen
  • 583
  • 1
  • 7
  • 14
12
votes
3 answers

Referencing ApplicationUser in the Infrastructure library from an entity in the ApplicationCore library using Clean Architecture

I am following the Microsoft Architecture Guide for creating an ASP.NET Core Web Application. The guide implements the clean architecture pattern which is pretty straight forward. If you look at the sample project which is using the clean…
12
votes
3 answers

Clean architecture: share same models/entities with different layers

In my clean architecture Android app setup, I have own Gradle module for each layer (data, domain, presentation). I also have own models/entities for each layers, which are converted from one layer to another using mappers. This leads to situation…
devha
  • 3,307
  • 4
  • 28
  • 52
12
votes
3 answers

Clean Architecture - Where does mapping of DTO to business model should happen?

I have a DTO that's managed by a Repository and in the end I want to map this DTO to a different type of object that's used by the Presentation layer. Should the mapping happen in the Repository or in the domain layer? ( Use case/ Interactor)
Nameless
  • 259
  • 2
  • 4
  • 15
12
votes
3 answers

Android: clean architecture with Room database and LiveData in DAO

I'm trying to apply clean-architecture approach to my project (Link: guide I'm currently referencing). I'm using Room database for local storage and I want it to be the single source of data in the application - this means that all data gathered…
11
votes
1 answer

Clean Architecture: Where to make API calls

I am currently creating a microservices project in which I implement the Clean Architecture pattern coined by Bob Martin. While my code works perfectly, I have a question about the clean architecture pattern, specifically the interfaces and…
Brandon Miller
  • 1,534
  • 1
  • 11
  • 16
11
votes
1 answer

How to share dependencies in a Modularized Android App

I have an Android project which is architectured in a Modularized way. I have modularized the projects by dividing their source code between multiple Gradle modules, following the clean Architecture. Here is the structure of the App. The top…
11
votes
1 answer

How do I access response headers while using RxJava2 and Retrofit2?

The Premise I'm working on a simple app where I want to list out a user's GitHub repos in a RecyclerView. I'm using this as my endpoint while building this. The Problem The problem I'm facing is that the GitHub API returns only 30 repos in one go.…
Ratik
  • 113
  • 2
  • 6
11
votes
4 answers

Use case containing the presenter or returning data?

Considering the Clean Architecture definition, and especially the little flow diagram describing relationships between a controller, a use case interactor, and a presenter, I'm not sure if I correctly understand what the "Use Case Output Port"…
swahnee
  • 2,661
  • 2
  • 24
  • 34
11
votes
1 answer

How do you implement one to many relationships in Clean Architecture

I'm having problems using Clean Architecture. For those of you who have read Fernando Cejas' blog post http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/, my question is based on it, and his code. His example project has only…
MikeWallaceDev
  • 1,458
  • 2
  • 14
  • 28
10
votes
1 answer

Use of CLEAN architecture in Android with Parceler

I'm using working on a project in the CLEAN architecture where the project is broken into the "Presentation", "Domain" and "Data" modules, where the Domain module hosts the "Entities" that are basically the data models specific to this project. An…
Billy
  • 1,374
  • 1
  • 17
  • 25
10
votes
1 answer

Not so Clean Architecture

I'm trying to code in C++ (C++11) a very simple example according to the Clean Architecture concept described by Uncle Bob Martin here (picture below): The idea is to read some text by a Controller and print it by a Presenter. I have done something…
RicLeal
  • 923
  • 9
  • 23
1 2
3
73 74