Given the following design from clean architecture in which layer would you put overall application state?

In each state a subset of use cases are allowed to be invoked. For example if application is in "Updating" state invoking AddNewParameterUseCase is not allowed.enter image description here

  • The first question to ask (or reconsider) is do you want/need Redux-style overall application state to begin with. If not, then your state will be distributed throughout different objects/components. If yes, then the global store would be an infrastructural thing, and as such you should treat it as it's own component. Couple of ways to go about it. E.g. treat it as an in-memory data store, so allow access to it as you'd do it with any other database (so, interface adapter implemented by the store in the outermost layer). Alternatively, you could consider it an application-specific service. Oct 23, 2022 at 19:19
  • P.S. Please note that in CA, the Entities are not data entities, but proper OO objects with behavior that encodes various business rules. The actual data associated with those rules can be stored with those entities, but can also be provided to them externally, or can actually reside in your Redux-style store, or some such scheme - this is for you to decide, and design. Oct 23, 2022 at 19:23
  • Ah, sorry, read your comment under candied_orange's answer - you're asking about something different. You are talking about application being in one of several states. In principle, you don't "put overall state" like you said; instead, you capture those rules within one or more use cases. E.g., you could add a use case that tracks the current state internally, and can return (to the controller) or push (to the presenter) a list of other use case instances. The list would contain only those use cases that are allowed. Then you just need to figure out how to take that list and turn it into UI. Oct 23, 2022 at 19:34
  • Thank you Filip, I was thinking the same and I think this is the way to go
    – hamid
    Oct 25, 2022 at 6:49

1 Answer 1


Well, if by "Application State" you mean:

Application State (also known as Program State) represents the totality of everything necessary to keep your application running. When we refer to application state we are normally referring to the state of the program as it exists in the contents of its memory.

What is State and Why Does it Matter? - thedaylightstudio.com

Then for the most part you'll find your Application State is not on your diagram. It's over here where the Entities live:

enter image description here

That being said, every layer holds some state. Even if it's mostly just configuration info.

However, some applications go out of their way to eliminate "Application State". They're called stateless.= They push all responsibility for knowing things onto the DB. That way the application doesn't change from request to request. Makes it easy to know if it's in a good state since it only has one.

  • Thank you for the answer, here by overall application state I mean letting the application uses a machine correctly and effectively. For example consider a simple vending machine, the machine can handle only one purchase at a time so when the machine is in the process of dispensing it can not accept a new purchase or inserting cash. In our system apart from user interaction there might be some requests from external system so I would like to track the state of application in order to accept or reject those requests.
    – hamid
    Oct 23, 2022 at 14:38
  • 1
    I think you may be conflating application state and some basic examples of state machines. These are not the same thing. Oct 23, 2022 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.