title: Checking the architecture of your Clojure code with unit tests
body: <p>I have been inspired buy this book: <a href="https://www.thoughtworks.com/books/building-evolutionary-architectures" rel="nofollow noreferrer">Building Evolutionary Architectures</a> and <a href="https://www.amazon.co.uk/Clean-Architecture-Craftsmans-Software-Structure/dp/0134494164" rel="nofollow noreferrer">clean architecture</a>.</p>
  
  <p>One of the concept is to be able to test your architecture in the code. 
  In particular I would like to be able to check dependencies between namespaces, layers and assert that a namespace doesn't call a namespace for another layer.</p>
  
  <p>All my namespaces are inside the circles:</p>
  
  <p><a href="https://i.stack.imgur.com/QrZsx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QrZsx.png" alt="my architecture"></a></p>
  
  <p>The idea is that a namespace inside 'controllers' <strong>can not</strong> import a namespace inside 'entities' but only import namespaces below him (use-cases). And I would like to detect this in my unit tests.</p>
  
  <p>So this should fail in my unit tests:</p>
  
  <pre><code>(ns com.controller.core
    (:require [com.entities.core :as entities]
              [com.use-cases.core :as use-cases]))
  
  (defn do-something [args]
        (let [use-cases-results (use-cases/do-something args)]
             (entities/do-some-other-thing use-cases-results)))
  </code></pre>
  
  <p>In java you can write those sort of unit tests using <a href="https://www.archunit.org/" rel="nofollow noreferrer">archunit</a>.</p>
  
  <pre><code>private final JavaClasses classes = new ClassFileImporter().importPackagesOf(Controller/core.class);
  
  noClasses().that().resideInAPackage("..controller..").should().accessClassesThat().resideInAPackage("..use-cases..").check(classes);
  </code></pre>
  
  <p>Are you using something similar for clojure or do you have some suggestions how to tackle this problem? </p>