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.