API Overview

Konture provides a unified, highly expressive DSL for architectural assertions across six core scopes:

  • files {}: Source file imports, package placements, and file-level call/reference prohibitions.
  • classes {}: Class declarations, interfaces, supertypes, modifiers, visibility, annotations, and dependencies.
  • functions {}: Function declarations (top-level and member), return types, parameter signatures, and invocations.
  • modules {}: Gradle module graph paths, module-to-module directional dependencies, cycle freedom, and applied plugins.
  • slices {}: Logical horizontal or vertical package slices derived via capture group patterns (e.g., com.acme.(*)..).
  • properties {}: Top-level and class property declarations, type signatures, and access prohibitions.

πŸ—ΊοΈ Feature Parity & API Surface Matrix

The table below outlines all available builder entry points, scoping utilities, filtering conditions, and assertion rules across Konture’s DSL surface:

Feature Dimension files {} classes {} functions {} modules {} slices {} properties {}
Declarative Builder Entry Point (Konture.*()) βœ… files() βœ… classes() βœ… functions() βœ… modules() βœ… slices() βœ… properties()
SourceSet Selector Override βœ… files(sourceSets) βœ… classes(sourceSets) βœ… functions(sourceSets) βœ… modules(sourceSets) βœ… slices(sourceSets) βœ… properties(sourceSets)
Auto-Checking Block DSL βœ… files { ... } βœ… classes { ... } βœ… functions { ... } βœ… modules { ... } βœ… slices { ... } βœ… properties { ... }
Batch Architecture Context Integration βœ… architecture { files { ... } } βœ… architecture { classes { ... } } βœ… architecture { functions { ... } } βœ… architecture { modules { ... } } βœ… architecture { slices { ... } } βœ… architecture { properties { ... } }
Functional Inspection Scope βœ… fileScope βœ… classScope / scope βœ… functionScope βœ… moduleScope βœ… sliceScope(pattern) βœ… propertyScope
Module-Scoped Functional Entry βœ… fileScopeFromModule βœ… classScopeFromModule βœ… functionScopeFromModule βœ… moduleScopeFromModule βœ… sliceScopeFromModule βœ… propertyScopeFromModule
Package-Scoped Functional Entry βœ… fileScopeFromPackage βœ… classScopeFromPackage βœ… functionScopeFromPackage βž– (N/A) βœ… sliceScopeFromPackage βœ… propertyScopeFromPackage
Scope Set Algebra Operators (+, -) βœ… + / - βœ… + / - βœ… + / - βœ… + / - βœ… + / - βœ… + / -
Allow Empty Selection (allowEmpty()) βœ… βœ… βœ… βœ… βœ… βœ…
Debug Matched Printing (printMatched*()) βœ… printMatchedFiles() βœ… printMatchedClasses() βœ… printMatchedFunctions() βœ… printMatchedModules() βœ… printMatchedSlices() βœ… printMatchedProperties()
Debug All Discovered Printing (printAll*()) βœ… printAllFiles() βœ… printAllClasses() βœ… printAllFunctions() βœ… printAllModules() βœ… printAllSlices() βœ… printAllProperties()
Baseline & Violation Suppression βœ… suppress { ... } βœ… suppress { ... } βœ… suppress { ... } βœ… suppress { ... } βœ… suppress { ... } βœ… suppress { ... }
Logical Chaining Operators (and, or, not) βœ… βœ… βœ… βœ… βœ… βœ…
Name / Path Filtering (that()) βœ… βœ… βœ… βœ… (havePath, haveName) βœ… (matching, haveKey) βœ…
Module Filtering (resideInAModule) βœ… βœ… βœ… βœ… resideInAModule βœ… resideInAModule βœ…
Package Filtering (resideInAPackage) βœ… βœ… βœ… βœ… resideInAPackage βœ… resideInAPackage βœ…
Annotation Filtering / Assertions βœ… (containClassesWithAnnotation) βœ… (beAnnotatedWith) βœ… (beAnnotatedWith) βœ… (containClassesWithAnnotation) βœ… (containClassesWithAnnotation) βœ… (beAnnotatedWith)
Visibility / Modifier Controls βž– (N/A) βœ… βœ… βž– (N/A) βž– (N/A) βœ…
Call / Reference Prohibitions βœ… notCall, notReferenceClass βœ… notCall, notReferenceClass βœ… notCall, notReferenceClass βœ… notCall, notReferenceClass βœ… notCall, notReferenceClass βœ… notCall, notReferenceClass
Dependency Assertions βœ… onlyDependOnPackages, notDependOnPackages, onlyDependOnModules, notDependOnModules βœ… onlyDependOn*, notDependOn* βž– βœ… onlyDependOnModules, notDependOnModules βœ… onlyDependOnSlices, notDependOnSlice βž–
Cycle Detection Assertions βž– βœ… beFreeOfCycles() βž– βœ… beFreeOfCycles() βœ… beFreeOfCycles() βž–
Plugin / Asset Assertions βž– βž– βž– βœ… havePlugin, notHavePlugin βž– βž–
Type-Safe Overloads (KClass, reified T) βœ… βœ… βœ… βœ… (Calls/Refs/Annotations) βœ… (Calls/Refs/Annotations) βœ…
Composite Predicates (anyOf, allOf, noneOf) βœ… βœ… βœ… βœ… βœ… βœ…
Custom Predicates & Assertions (satisfy) βœ… βœ… βœ… βœ… βœ… βœ…

πŸ’‘ Quick Code Snippets by Scope

1. files {} Scope

Konture.files {
    that().resideInAPackage("com.acme.feature..")
    should().onlyDependOnPackages("com.acme.core..", "kotlin..")
    andShould().notUseWildcardImports()
}

2. classes {} Scope

Konture.classes {
    that().haveNameEndingWith("Repository")
    should().beInterfaces()
    andShould().resideInAPackage("com.acme.domain..")
}

3. functions {} Scope

Konture.functions {
    that().haveNameStartingWith("get")
    should().notReferenceClass<android.content.Context>()
}

4. modules {} Scope

Konture.modules {
    that().resideInAModule(":feature-*")
    should().notDependOnModules(":feature-*")
    andShould().beFreeOfCycles()
    andShould().notCall("java.lang.System.exit")
}

5. slices {} Scope

Konture.slices {
    matching("com.acme.(*)..")
    should().onlyDependOnSlices("core", "common")
    andShould().beFreeOfCycles()
}

6. properties {} Scope

Konture.properties {
    that().resideInPackageOf<MarkerClass>()
    should().haveTypeOf<StateFlow<*>>()
}

🚨 Structured Violation Model

When executing declarative rules with .check(), Konture returns a structured ViolationReport. The underlying core models are fully @Serializable using kotlinx.serialization, enabling custom test reporters, IDE plugins, or CI quality tools to consume structured diagnostic results:

Core Model Description
ViolationReport Contains ruleId, violations: List<Violation>, severity: Severity, and computed flags hasErrors / hasWarnings.
Violation Details an individual violation including ruleId, subject: Subject, target: Subject?, sourceLocation: SourceLocation?, dependencyPath: List<Subject>, message, and severity.
Subject Sealed hierarchy identifying the target element (ModuleSubject, ClassSubject, FunctionSubject, or CustomSubject).
SourceLocation Source location metadata containing build-root relative filePath, 1-based line, and optional column.
Severity Enum representing violation importance (INFO, WARNING, ERROR).

πŸ“š KDoc API Reference

For detailed KDoc function signatures and type specifications generated directly from source headers, see the Dokka API Docs.


This site uses Just the Docs, a documentation theme for Jekyll.