> For the complete documentation index, see [llms.txt](https://docs.konsist.lemonappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.konsist.lemonappdev.com/verifying-codebase/verify-interfaces.md).

# Verify Interfaces

Konsist enables development teams to enforce structural rules for interfaces, ensuring code consistency across projects.

To verify interfaces start by querying all interfaces present in the project:

```kotlin
Konsist
.scopeFromProject()
.interfaces()
...
```

{% hint style="info" %}
The above code selects all interfaces present in the project codebase. While this demonstrates Konsist's API capabilities, in practical scenarios you'll typically want to verify a specific subset of interfaces - such as those with a particular name suffix or interfaces within a given package. See [Create The Scope](/writing-tests/koscope.md) and [Declaration Filtering](/writing-tests/declaration-query-and-filter.md).
{% endhint %}

Konsist allows you to verify multiple aspects of interfaces. For the complete list of available APIs, explore `KoInterfaceDeclaration` in your IDE (code completion and KDoc).

Let's look at a few examples.

## Verify Name

Interface names can be validated to ensure they follow project naming conventions and patterns.

Check if interface name ends with `Repository`:

```kotlin
...
.assertTrue {
   it.hasNameEndingWith("Repository")
}
```

## Verify Modifiers

Interface modifiers can be validated to ensure proper encapsulation and access control.

Check if interface has `internal` modifier:

```kotlin
...
.assertTrue {
   it.hasInternalModifier
}
```

## Verify Annotations

Interface-level and member annotations can be verified for presence, correct usage, and required attribute values.

Check if interface is annotated with `Service` annotation:

```kotlin
...
.assertTrue {
   it.hasAnnotationOf(Service::class)
}
```

## Verify Package

Package declarations can be validated to ensure interfaces are located in the correct package structure according to architectural guidelines.

Check if interface has `model` package or sub-packages (`..` means include sub-packages):

```kotlin
...
.assertTrue {
   it.resideInPackage("com.lemonappdev.model..")
}
```

## Verify Methods

Methods can be validated for their signatures, modifiers, annotations, naming patterns, return types, and parameter structures.

Check if methods (functions defined inside interface) have name starting with `Local`:

```kotlin
...
.functions()
.assertTrue {
    it.hasNameStartingWith("Local")
}
```

See [Verify Functions](/verifying-codebase/verify-functions.md).

## Verify Properties

Properties can be checked for proper access modifiers, type declarations, and initialization patterns.

Check if all properties (defined inside interface) have `val` modifier:

```kotlin
...
.properties()
.assertTrue {
   it.isVal
}
```

See [Verify Properties](/verifying-codebase/verify-properties.md).

## Verify Generic Type Parameters

Generic type parameters and constraints can be checked for correct usage and bounds declarations.

Check if interface has no type parameters:

<pre class="language-kotlin"><code class="lang-kotlin">...
.assertFalse {
<strong>    it.hasTypeParameters()
</strong>}
</code></pre>

## Verify Generic Type Arguments

Generic type arguments can be checked for correct usage.

Check if parent has no type arguments:

```kotlin
...
.parents()
.assertFalse {
    it.hasTypeArguments()
}
```

## Verify Parents

Inheritance hierarchies, interface implementations, and superclass relationships can be validated.

Check if interface extends `CrudRepository`:

```kotlin
...
.assertTrue {
   it.hasParentOf(CrudRepository::class)
}
```

## Verify Companion Objects

Companion object declarations, their contents, and usage patterns can be verified for compliance.

Check if interface has `companion object`:

```kotlin
...
.assertTrue {
   it.hasCompanionObject()
}
```

## Verify Members Order

The sequential arrangement of interface members can be enforced according to defined organizational rules.

Check if interface properties are defined before functions:

```kotlin
...
.assertTrue {
    val lastKoPropertyDeclarationIndex = it
        .declarations(includeNested = false, includeLocal = false)
        .indexOfLastInstance<KoPropertyDeclaration>()
    
    val firstKoFunctionDeclarationIndex = it
        .declarations(includeNested = false, includeLocal = false)
        .indexOfFirstInstance<KoFunctionDeclaration>()
    
    if (lastKoPropertyDeclarationIndex != -1 && firstKoFunctionDeclarationIndex != -1) {
        lastKoPropertyDeclarationIndex < firstKoFunctionDeclarationIndex
    } else {
        true
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.konsist.lemonappdev.com/verifying-codebase/verify-interfaces.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
