# Architecture Snippets

Snippets used to guard application architecture.

## 1. 2 Layer Architecture Has Correct Dependencies

```kotlin
@Test
fun `2 layer architecture has correct dependencies`() {
    Konsist
        .scopeFromProject()
        .assertArchitecture {
            val presentation = Layer("Presentation", "com.myapp.presentation..")
            val business = Layer("Business", "com.myapp.business..")
            val persistence = Layer("Persistence", "com.myapp.persistence..")
            val database = Layer("Database", "com.myapp.database..")

            presentation.dependsOn(business)
            business.dependsOn(presentation)
            business.dependsOn(persistence)
            persistence.dependsOn(business)
            business.dependsOn(database)
            database.dependsOn(business)
        }
}
```

## 2. Every File In Module Reside In Module Specific Package

```kotlin
@Test
fun `every file in module reside in module specific package`() {
    Konsist
        .scopeFromProject()
        .files
        .assertTrue { it.packagee?.name?.startsWith(it.moduleName) }
}
```

## 3. Files Reside In Package That Is Derived From Module Name

```kotlin
@Test
fun `files reside in package that is derived from module name`() {
    Konsist.scopeFromProduction()
        .files
        .assertTrue {
            /*
            module -> package name:
            feature_meal_planner -> mealplanner
            feature_caloric_calculator -> caloriccalculator
            */
            val featurePackageName = it
                .moduleName
                .removePrefix("feature_")
                .replace("_", "")

            it.hasPackage("com.myapp.$featurePackageName..")
        }
}
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.konsist.lemonappdev.com/inspiration/snippets/architecture-snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
