Skip to content

Menu

Announcing NKP 0.1: Static Analysis for Kotlin Projects

November 01, 2025

I’m excited to share the first MVP release of NKP (aNalysis of Kotlin Programs), a command-line tool for analyzing Kotlin codebases and uncovering architectural insights.

What is NKP?

NKP examines Kotlin source code to surface structure, dependencies, and stability metrics. It helps answer questions like:

  • How are my packages coupled?
  • Which areas of my code are unstable?
  • What does my class hierarchy look like?

Key Capabilities

NKP focuses on architectural understanding:

  • Package coupling metrics (Afferent Ca, Efferent Ce, Instability I)
  • Class and file analysis (hierarchies, inheritance, imports, declarations)
  • Mermaid diagram generation
    • Class hierarchies
    • Package import flow
    • Coupling relationships
  • Search functionality for classes across the codebase

When to Use NKP

Use NKP for:

  • Architectural assessment
  • Refactoring planning and impact analysis
  • Architecture documentation and onboarding
  • Code reviews with architectural context
  • Migration and modernization efforts

Limitations (for now)

This MVP emphasizes architecture, not general code quality metrics. Think JDepend for Kotlin, not Sonar or Detekt.

Example: Ray Tracer Analysis

Running NKP on my ray-tracer project showed:

  • 203 classes across 37 packages
  • Average package instability of 0.69 (69%)
  • Clear separation between stable core packages (math, colors, hits) and application layers
  • High coupling in orchestration packages that need refactoring attention

The package coupling metrics helped identify that:

  • Core domain packages (math, colors) are very stable (I < 0.1)
  • Application layer packages have high instability (I > 0.7)
  • The world package couples 14 different subsystems, indicating a need for better separation

This kind of insight is invaluable when planning architectural improvements.

Why Build NKP?

As someone who works with teams on architectural improvements and refactoring, I found myself needing better tools to understand Kotlin codebases. While there are excellent tools for Java (like JDepend), Kotlin’s package structure and syntax required a specialized approach.

NKP fills this gap by providing:

  • Kotlin-specific analysis using the official Kotlin grammar tools
  • Actionable metrics based on well-established software engineering principles (Robert C. Martin’s package coupling metrics)
  • Visual output in the widely-supported Mermaid format
  • CLI-first design for easy integration into scripts and CI/CD pipelines

Get Involved

NKP is open source and available on GitHub. If you work with Kotlin projects and need better insights into your architecture, give NKP a try. It’s particularly useful for:

  • Understanding large codebases
  • Planning refactoring efforts
  • Documenting architecture
  • Identifying coupling issues before they become technical debt

I’d love to hear your feedback and learn about your experiences using NKP on your projects!

Read next

Java in the Technology Radar
Sep 03, 2025 software-engineering

Java in the Technology Radar (JavaSpektrum)

I’ve written a new article for JavaSpektrum: “Java im Technology Radar – Totgesagte leben länger”. The piece looks back at Java’s journey through the eyes of the Thoughtworks Technology Radar...

#java #article #jvm #thoughtworks
Read more
Structured Concurrency in Java 24
Mar 31, 2025 software-engineering

Structured Concurrency in Java 24 (JavaSpektrum)

I’ve written an article for JavaSpektrum 2/2025 about Structured Concurrency in Java 24. The article covers JEP 499, Java’s fourth preview of Structured Concurrency, which aims to make concurrent programming...

#java #concurrency #article #jvm #parallelism
Read more