# kosi-libs/kodein architecture

> Architecture diagram of the GitHub repository kosi-libs/kodein, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kosi-libs/kodein
- Repository: https://github.com/kosi-libs/kodein

## Overview

##### Main Components
- Core DI Module: This is found in the “kodein-di” directory. Its commonMain sources (and platform-specific sources for JVM, JS, Native) implement the heart of dependency injection – the container, binding APIs, instance retrieval, scope management, etc.
- Framework Integration Modules: The “framework” directory contains several subdirectories (android, compose, ktor, tornadofx) which provide specialized integrations for each environment. They extend the core DI functionality and offer idiomatic APIs for each platform. Additional directories like “kodein-di-conf” and “kodein-di-jxinject-jvm” add further configuration or alternative injection paradigms.
- Test & Utility Components: There is a “test-utils” module that provides helper functions, annotations, and sample types to ease testing of DI bindings and resolution.

##### Relationships and Interactions
- The Core DI Module is at the center and serves as the foundation – all other modules depend on it.
- The Compiler modules (resolver API, processor, test) interact with the core layer. They scan for DI annotations or DSL constructs and generate (or validate) dependency binding code that will be used by the core DI container at runtime.
- Framework-specific modules wrap or extend the core DI container; for example, modules under “framework/android” or “framework/ktor” receive their capabilities by integrating with the core and exposing additional convenience functions/methods tailored to that platform.
- Test and utility modules are used both for actual testing scenarios and serving as examples for correct usage.

##### Architectural Patterns and Design Principles
- Modular Architecture: The separation into core, compiler, and framework modules indicates a well-organized, modular design that allows users to pull in only the pieces they need.
- DSL-Driven Configuration: As indicated in the README’s example, the DI container is configured via a declarative DSL (a domain-specific language) that defines bindings and scopes.
- Multiplatform Design: The source-set split (commonMain, jvmMain, jsBasedMain, nativeMain) and corresponding tests ensure that the core DI behavior is available on all targeted platforms.
- Compiler Assistance: The use of compiler modules reduces runtime overhead by shifting parts of dependency resolution to compile time (or KSP processing).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Compiler Integration"
        CIApi["Resolver API"]:::compiler
        CIProc["Resolver Processor"]:::compiler
        CITest["Resolver Test"]:::compiler
    end

    DI_Core["DI Core (kodein-di)\nBindings Manager\nResolution Engine\nScope & Lifecycle Management"]:::core

    subgraph "Framework Integrations"
        FW_Android["Android"]:::framework
        FW_Compose["Compose"]:::framework
        FW_Ktor["Ktor"]:::framework
        FW_TornadoFX["TornadoFX"]:::framework
    end

    ConfigMod["Configuration Module (kodein-di-conf)"]:::config
    AltInj["Alternative Injection (JxInject)"]:::config
    TestUtil["Test & Utility Components"]:::test

    CIApi -->|"GeneratesFor"| DI_Core
    CIProc -->|"GeneratesFor"| DI_Core
    CITest -->|"GeneratesFor"| DI_Core

    DI_Core -->|"Extends"| FW_Android
    DI_Core -->|"Extends"| FW_Compose
    DI_Core -->|"Extends"| FW_Ktor
    DI_Core -->|"Extends"| FW_TornadoFX

    ConfigMod -->|"ProvidesConfig"| DI_Core
    AltInj -->|"AlternativeInjection"| DI_Core
    TestUtil -->|"ValidatesDI"| DI_Core

    click DI_Core "https://github.com/kosi-libs/kodein/tree/main/kodein-di/src/commonMain/kotlin/org/kodein/di"
    click CIApi "https://github.com/kosi-libs/kodein/tree/main/compiler/kodein-resolver-api"
    click CIProc "https://github.com/kosi-libs/kodein/tree/main/compiler/kodein-resolver-processor"
    click CITest "https://github.com/kosi-libs/kodein/tree/main/compiler/kodein-resolver-test"
    click FW_Android "https://github.com/kosi-libs/kodein/tree/main/framework/android"
    click FW_Compose "https://github.com/kosi-libs/kodein/tree/main/framework/compose"
    click FW_Ktor "https://github.com/kosi-libs/kodein/tree/main/framework/ktor"
    click FW_TornadoFX "https://github.com/kosi-libs/kodein/tree/main/framework/tornadofx"
    click ConfigMod "https://github.com/kosi-libs/kodein/tree/main/kodein-di-conf"
    click AltInj "https://github.com/kosi-libs/kodein/tree/main/kodein-di-jxinject-jvm"
    click TestUtil "https://github.com/kosi-libs/kodein/tree/main/test-utils"

    classDef core fill:#F9E79F,stroke:#D68910,stroke-width:2px;
    classDef compiler fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef framework fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef config fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef test fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
```
