r/Clojure • • 3d ago

Implementing Clean Architecture in Clojure

https://en.andros.dev/blog/bebb6f27/implementing-clean-architecture-in-clojure/
28 Upvotes

3 comments sorted by

1

u/yogthos 2d ago

I find that clean architecture is only a part of the bigger picture because keeping IO strictly at the edges is not practical in many scenarios. Often, you simply don't know what data you're going to need later, and fetching everything up front is inefficient.

So, the way I've started thinking about this is that you can structure the application as effectively a graph of small components that each take resources and the state, do some task and return a new state that then gets dispatched to the next node in the graph. This way each node can be structured using Clean Architecture with effects at the edges, and then data can be loaded as needed when the state transitions to a new node in the graph. I wrote about this approach in some more detail here.

2

u/tanrax 2d ago

Thanks for the reply! And for the original post, it's cited in the article.

I agree on the problem, that's exactly why I didn't go with Functional Core, Imperative Shell. In the article the use cases receive the repository as an argument and can fetch data mid-flow, so IO isn't strictly at the edges; the core just doesn't depend on concrete infrastructure.

In my opinion, I see your graph approach as the next level up. Each node could be one of these use cases, with the conductor making the flow explicit and traceable. Maybe, for a small app it'd be overkill.

I'll check out Mycelium.

2

u/yogthos 2d ago

Ah, missed the citation. :) And yeah, I agree the graph approach is overkill for a smaller app where it's easy enough to trace the control flow.