Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [clean-architecture]

Clean Architecture is a book by Robert C. Martin that contains solutions to architecting software solutions. Collectively these concepts are referred to as "Clean Architecture".

Filter by
Sorted by
Tagged with
0 votes
0 answers
59 views

Clean Architecture: How to decouple the Repository from a CommandHandler?

We are just starting with event driven (and clean) architecture. So far we have two main entrypoints, a consumer (reader from a Redis Stream / Kafka Topic), and an API. As this is almost a modular ...
user avatar
2 votes
2 answers
135 views

What is the alternative to checked exceptions in API/interface design?

Despite checked exceptions being generally bad practice and anti-pattern, I find one feature very useful: having list of checked exceptions part of function signature. Checked exceptions are "...
user avatar
  • 129
-1 votes
2 answers
67 views

Should similar use cases be splitted or combined in clean architecture?

In Clean architecture Suppose I have two actions (approve/deny) a request. Should I create a use case for approve and another for deny? or both in one use case (RespondToRequestUseCase) and I ...
user avatar
1 vote
1 answer
41 views

How to integrate Androidx Paging-3 in Clean Architecture?

This blog on "Clean Architecture" describes how to build a modular Android application along with using Clean Architecture. In that example project, the author places the business logic in a ...
user avatar
0 votes
1 answer
134 views

How to conform two repositories that work on the same entity but have different methods?

I have to implement 2 use cases, the first one is going to create a Company profile from its document number, so inside the use case, it reaches out to the third party API that contains information ...
user avatar
1 vote
1 answer
258 views

Is the use of a catch block as a "rollback mechanism" a bad thing?

I have a service that performs a series of actions based on user information (name, address, etc), one of the problems is that the User entity comes from a legacy third party API (as a repository) ...
user avatar
0 votes
1 answer
74 views

Verbs in Use Case name "Create User" [closed]

I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what ...
user avatar
0 votes
3 answers
207 views

How should you start applying TDD in a clean architecture?

I'll be using Uncle Bob's terms, so i'll call the use cases "interactors" and the domain entities "entities". As far as I understand, the most specific business rules that are most ...
user avatar
3 votes
2 answers
222 views

Alternatives to outbox pattern, does outbox pattern break clean-architecture?

I've read and tried the Transactional Outbox pattern for communicating between services. It is clear to me what are the benefits of this pattern, as it has two main parts: By using a transaction, we ...
user avatar
  • 207
0 votes
0 answers
93 views

microservice custom error messages

We use microservices and spring boot in our saas (multi tenant) projects. We will proceed through the schema per tenant. We manage the error messages we show to the users through a database. We are ...
user avatar
1 vote
0 answers
69 views

Could output port consist of multiple methods? (Clean Architecture)

The use case output port is called by the Interactor returning the response model, and the output port could be called many times with different responses. Question: Could the output port has multiple ...
user avatar
1 vote
2 answers
1k views

To which Clean Architecture layer should repositories implementations belong?

It's very common to see this use of repository in projects using clean architecture: interface Hero { } interface HeroRepository { findById(id: number): Hero; } class FetchHeroUseCase { ...
user avatar
0 votes
2 answers
101 views

Can the presenter talk to to the controller?

in the clear architecture, what uncle bob suggested. I have a lot of questions about how to correctly distribute the responsibility. it seems that there is no relationship between controller and ...
user avatar
2 votes
2 answers
71 views

Replacing service implementation based on environment variables

I have previously asked a question on this forum linked here. In short, I wanted to not call 3rd party APIs when developing locally. Based on the wonderful answers received I have opted for the ...
user avatar
  • 161
0 votes
3 answers
384 views

Mapping to and from domain entities

I am in the process of implementing onion / clean architecture, and would like to understand better how and when to map to my domain entities. So if we take a specific example where we have a Post and ...
user avatar
  • 161
1 vote
1 answer
132 views

Who should validate the request data, controller or useCase?

I use the controller to extract data from a request and Use Cases/Interactors to validate the data. But can I use the controller to extract and validate the request data?
user avatar
0 votes
2 answers
172 views

Sharing logic / services across modules in "clean" architecture [closed]

I am trying to implement a layered architecture consisting of; Controller, Service, Repository, Entity. Each module has at least some of the above layers. I am often finding that modules need to share ...
user avatar
  • 161
-1 votes
1 answer
122 views

How to use external validation libraries for entities in a "clean" architecture?

I would like to make use of a external library to parse the core domain entities. Doing this in a naive way it would look like the following: import { z } from 'zod'; const Audience = z.object({ ...
user avatar
  • 161
0 votes
1 answer
231 views

Where should interfaces/model definitions live? -- Clean architecture

I'm working on a Node project (in typescript) that features a variation of clean architecture. I have a pretty clear understanding of the different layers of an application and how they depend on each ...
user avatar
  • 111
0 votes
0 answers
126 views

Where Refit interfaces fit in a Clean Architecture structure

I want to start using Refit, it is a great library, but I'm having some hard time to keep the project structure clean because the library is at the same time the abstraction(interface) and the ...
user avatar
  • 101
0 votes
1 answer
107 views

Implement Dependency Inversion in C with UML diagram

As per Robert C. Martin in Clean Architecture, he gives a simple UML diagram to illustrate Dependency Inversion. To put it simply, HL1 initially referred to ML1 without interface to invoke F() ...
user avatar
  • 185
1 vote
1 answer
180 views

Avoiding coupling through code sharing

I have been working on an application which consists of several cohesive services, Customer, Invoice, PurchaseOrder, Highlight, the application is deployed within a mono repo and each service is ...
user avatar
  • 113
0 votes
0 answers
26 views

"Bind" one domain to another while still following the rules of Clean Architecture?

I am creating a house planning app as a little test project so I get a better understanding for Clean Architecture. I am using more or less this template: https://github.com/jasontaylordev/...
user avatar
1 vote
1 answer
84 views

How to deal with master data in a microservice environment

Hey Software Engineers Currently we basically have a what I would call "modular monolith". A diagram would likely look something like this: What we want to do in the future is being able to ...
user avatar
  • 319
0 votes
0 answers
46 views

Can/Should Refit (API) Contracts be the same of MediatR (CQRS) Commands?

I'm creating a microservice using Clean Architecture principles. The following picture shows the project structure: On the Application layer, I am using MediatR (using CQRS), where I have the ...
user avatar
-3 votes
1 answer
83 views

Whats the purpose of use-case and data-sources?

I have a question about where should I get the info required for making an api call. Let's say I have this : Presenter --> Use Case --> DataSource --> Api Ok now to do my api call, I need a ...
user avatar
  • 103
1 vote
1 answer
602 views

Clean Architecture how does domain layer communicate with the Infrastructure layer?

I'm trying to get a grasp of the Clean Architecture. In the examples I found the typical solution structure consists of three projects: Core, Infrastructure, and Presentation/UI. The Core project must ...
user avatar
1 vote
3 answers
433 views

Clean architecture, Login UseCase with OAuth breaking Single responsability principle

I'm building a login system using OAuth to integrate with various social networks. The flow is very simple, first, the user is redirected to their social network to grant permission to read the ...
user avatar
6 votes
8 answers
740 views

Java instanceof and Clean architecture

It seems to me that there is a conflict between clean architecture and the recommendation not to use instanceof. Consider the following code: class ParentEntity { } class AEntity extends ParentEntity ...
user avatar
  • 199
0 votes
0 answers
32 views

best approach of passing arguments from usecases to repositories

I want to pass interface as a request in my use cases and repositories while following the clean architecture in flutter hence my method signature is as follows for usecases and respositories ...
user avatar
  • 121
1 vote
2 answers
245 views

How can I manage dependency injection in test code?

This question is a follow-up question to Clean Architecture use case testing. Suppose the production code injects Use Case Interactor into the Input Boundary - that happens somewhere in the main ...
user avatar
0 votes
1 answer
100 views

Should I define a separate interface for clarity rather than implementing Supplier<T>?

Let's say you have to meet some prerequisites before doing something. For that, I think implementing Supplier<Boolean> is a great candidate since it's widely used, and quick to understand. But, ...
user avatar
  • 101
2 votes
0 answers
258 views

Clean Architecture, what are objects that does not completely fit as entities?

I'm reading chapter 20, "Business Rules", of clean architecture book, in this chapter Uncle Bob defines entities as: An Entity is an object within our computer system that embodies a small ...
user avatar
0 votes
2 answers
119 views

May the left-side know the right-side when using CQRS with Hexagonal?

I'm trying to use the hexagonal architecture but I want the flexibility to make CUSTOM queries right to the database (or cache) to populate DTOs right from the left-side without passing through the ...
user avatar
  • 109
6 votes
1 answer
353 views

How does Dependency Inversion solve switch cases?

I want to understand how Dependency Inversion gets rid of switch cases. Consider a service that needs to communicate with several databases. class StockUpdater { private final DataStore datastore; ...
user avatar
  • 212
1 vote
3 answers
2k views

What is the responsibility of Infrastructure layer in a clean architecture?

I am trying to follow Clean Architecture by Uncle Bob. I have 3 layers: Core (Hosts business logic, and is the central layer) Application (Host application usecases, and is directly above the core) ...
user avatar
-1 votes
2 answers
606 views

Clean Architecture, good approaches to avoid hard-coding the creation of entities on the Use Case

I have an Use Case that has an UseCaseInput (which is a parameter object of the use case) and an UseCaseOutput which is the output object, the UseCaseInput has lots of parameters in which will be used ...
user avatar
0 votes
1 answer
55 views

API controllers modeling

I'm developing an API with ASP.NET, but I'm having some questions about the best way I should develop the controller layer for the products. I'm having these questions because each product will have ...
user avatar
1 vote
1 answer
66 views

Adapt very different adapters to an Interface

I'm building a service to send push notifications to the user. At first, I designed an Interface for the push notification adapters, something like this: interface PushNotificationAdapterInterface { ...
user avatar
1 vote
2 answers
141 views

Should the Use Case be responsible for transforming its primitive parameters into typed data for the Entity to use?

I'm building a Use Case for creating blog posts, this Use Case has its own "DTO", which is basically a parameter object with only primitive data, as follows: Use Case's DTO (Parameter Object)...
user avatar
2 votes
2 answers
290 views

Should an Use Case method receive a "pre-filled" entity or a DTO as a parameter?

I'm building a use-case for creating blog posts, at first I thought of using an entity as a use-case parameter, and this entity would be created by the layer that calls Use Case, in my case a ...
user avatar
2 votes
2 answers
604 views

If Entities, in the Clean Architecture, are enterprise wide rules how different applications consume them?

In this post, Uncle Bob writes: Entities encapsulate Enterprise wide business rules. An entity can be an object with methods, or it can be a set of data structures and functions. It doesn’t matter so ...
user avatar
0 votes
0 answers
131 views

Passing Domain models from Presentation layer to data layer to make a networking request

So, I have this repository(Interface) in my domain layer public protocol ProfileRepository { func becomeVerifiedDriver(licenseImageName: String, vehicle: Vehicle)-> Single<Void> } and ...
user avatar
  • 101
0 votes
1 answer
79 views

Clean Architecture - Support plugins that can add new entities? [closed]

I'm following Uncle Bob's clean architecture for my application. However, I wish my application to be extensible via plugins. More specifically, I want the plugins to be able to add new entities and ...
user avatar
1 vote
2 answers
162 views

Catch "foreign" exception in adapter and convert them in own business exception is a good practice?

I am currently thinking about some design choices regarding exception handling. My current architecture looks a little like this: You can see that I have a UI where a try-catch middleware is cathing ...
user avatar
4 votes
0 answers
411 views

Best practice to reuse use cases in a clean architecture

Imagine a "clean architecture" in which you have two use cases. One of them is CreateCustomerHandler, and the other SignUpCustomerByGoogleAuthHandler. So, the ...
user avatar
  • 149
0 votes
0 answers
40 views

Doing the same tasks from multiple places when using Clean Architecture and CQS?

I'm working on some tooling that will help speed up the process of setting up a new computer for new developers. I want the user to be able to execute many tasks either as one task or grouped together ...
user avatar
  • 119
4 votes
2 answers
236 views

How to model classes that can be extendable?

I have recently inherited a codebase which has a weird problem and I am trying to search for an extensible solution that can solve my issue. Consider I have a model class that is used as a model to ...
user avatar
3 votes
2 answers
120 views

Checking the user in almost all use cases

I have a web application that has Users that belong to Companies. A User can only belong to 1 Company at a time and they can manage their own company information. I'm using java spring and I'm ...
user avatar
0 votes
1 answer
234 views

How do I implement a domain entity behaviour that depends on some external infrastructure?

I am in the process of developing some software using CQRS, ES and DDD. A part of the system is writing services for controlling devices and collecting data from them. Consider a "Start" ...
user avatar
  • 11