# konsist

Dylan Sale

10/26/2023, 8:18 AM
Hi, I’m trying to use konsist to enforce a “modulith” architecture. I have separate “subprojects” (not java modules) in a gradle project and I want to ensure that they don’t import each other and only communicate via an event bus using “common” type definitions (defined in an api project that they all import). Each module has it’s own package name (com.example.module1, com.example.module2, etc). What is the best way to express that with an architecture test?
I figured it out, here’s my test for anyone else who is interested:
Copy code
    fun `architecture is enforced`() {
        val modules = Konsist.scopeFromServices()
            .map { it.moduleName }
            //There is a common subproject that they can import
            .filter { !it.contains("/common/") }

            .assertArchitecture {
                val layers = { module ->
                    val packageName = 
module.replaceFirst(Regex(".*/"), "")
                    Layer(packageName, "$packageName..")
                layers.forEach {
                    it.dependsOnNothing() //Nothing being the other layers defined here
This does require that all packages in each module match the module name, but I can enforce that with another test. (scopeFromServices() is an extension function that just imports the scope from the path)


10/30/2023, 2:26 PM
Nice. BTW We have plans to improve architectural checks soon. If you have any feedback then it's good moment to share it with us