Skip to content

Acollie/Kaizen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ”οΈ Kaizen - Code Quality Analysis Tool

Build Status codecov Go Report Card License: MIT Go Version Latest Release

Continuous improvement starts with visibility. Kaizen analyzes code quality, complexity, and churn to identify technical debt and hotspots in your codebase. It generates health grades, actionable concerns, and interactive visualizations.

Kaizen Demo


✨ Features

  • 🎯 A-F Health Grades with 0-100 scores across complexity, maintainability, churn, function size, and code structure
  • πŸ“ˆ Cyclomatic & Cognitive Complexity, Halstead Metrics, Maintainability Index, and hotspot detection
  • 🌍 Multi-Language β€” Go (native AST), Python, Kotlin & Swift (tree-sitter)
  • 🎨 Interactive Visualizations β€” HTML treemaps, Sankey diagrams, call graphs, terminal charts
  • πŸ›‘οΈ CI Quality Gate β€” blast-radius detection with exit codes for pipelines
  • πŸ€– GitHub PR Action β€” automatic PR comments with score deltas, hotspot tracking, and call graph diffs
  • πŸ“Š Historical Tracking β€” SQLite snapshots with trend analysis and diff reporting
  • πŸ‘₯ Code Ownership β€” CODEOWNERS-based team metrics and reports

πŸ“Š Self-Analysis β€” Kaizen on Kaizen

Kaizen practices what it preaches. Here are the results from analyzing its own codebase:

Grade B β€” 88/100 βœ…

Metric Value Status
πŸ“ Files Analyzed 53
βš™οΈ Total Functions 394
🧠 Avg Cyclomatic Complexity 4.5 βœ… Excellent
🧩 Avg Cognitive Complexity 4.9 βœ… Excellent
πŸ“ Avg Function Length 27 lines βœ… Excellent
πŸ”§ Avg Maintainability Index 86.8 βœ… Good
πŸ”₯ Hotspots 0 βœ… Perfect

Component Scores:

Component Score Rating
🧠 Complexity 77/100 Good
πŸ”§ Maintainability 87/100 Good
πŸ“ Function Size 92/100 Excellent
πŸ—οΈ Code Structure 100/100 Excellent

πŸ₯ Code Health Grades

Grade Score Meaning
🟒 A 90–100 Excellent β€” well-maintained, low risk
🟒 B 75–89 Good β€” minor improvements suggested
🟑 C 60–74 Fair β€” consider refactoring
πŸ”΄ D 40–59 Poor β€” significant technical debt
🚨 F 0–39 Critical β€” urgent refactoring needed

πŸ” Automatic Issue Detection

Issue Threshold Why It Matters
πŸ”΄ High Complexity CC > 10 Error-prone, hard to test
🟑 Low Maintainability MI < 20 Hard to understand and modify
πŸ”΄ Long Functions > 50 lines Harder to test and review
πŸ”΄ Deep Nesting > 4 levels Confusing control flow
🟑 High Churn > 10 commits Unstable, frequently changing
🟠 Hotspots High CC + High churn Top priority for refactoring

πŸ€– GitHub Action β€” PR Analysis

Add Kaizen to any repository to get automatic code quality comments on every pull request.

⚑ Quick Setup

Create .github/workflows/kaizen.yml in your repository:

name: Kaizen PR Analysis

on:
  pull_request:
    branches: [main]

jobs:
  kaizen:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: read
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: acollie/kaizen@v0.1.0-beta
        with:
          path: "."
          base-branch: main

Every PR will receive a comment showing score changes, complexity metrics, and hotspot status. The comment is updated in-place on each push β€” never duplicated.

πŸ‘‰ See full Action docs for all inputs, outputs, and examples.


πŸš€ Quick Start

πŸ“¦ Installation

git clone https://github.com/acollie/kaizen.git
cd kaizen
./install.sh

kaizen --version

πŸ”¬ First Analysis

cd /path/to/your/project
kaizen analyze --path=.
kaizen visualize --format=html
kaizen report owners

πŸ’» Common Commands

# 🎨 Interactive heatmap
kaizen visualize --metric=complexity --format=html --open

# πŸ›‘οΈ CI quality gate
kaizen check --base=main --path=.

# πŸ”— Function call graph
kaizen callgraph --path=. --format=html

# πŸ”— Call graph filtered to changed functions only
kaizen callgraph --path=. --base=main --format=svg

# πŸ“ˆ Compare with previous analysis
kaizen diff --path=.

# πŸ“Š Track trends over time
kaizen trend overall_score --days=30

# πŸ‘₯ Team ownership report
kaizen report owners --format=html

# πŸ”„ Code ownership Sankey diagram
kaizen sankey --input=kaizen-results.json

# πŸ“‹ Analysis history
kaizen history list

πŸ”§ Command Reference

Command Description
kaizen analyze πŸ”¬ Analyze a codebase and generate metrics (JSON output)
kaizen visualize 🎨 Generate interactive heatmaps (HTML, SVG, or terminal)
kaizen check πŸ›‘οΈ CI quality gate β€” warn on high blast-radius function changes
kaizen callgraph πŸ”— Generate function call graph (HTML, SVG, or JSON)
kaizen pr-comment πŸ€– Generate a GitHub PR comment from base vs head analysis
kaizen sankey πŸ”„ Generate Sankey diagram of code ownership flow
kaizen diff πŸ“ˆ Compare current analysis with previous snapshot
kaizen trend πŸ“Š Visualize metric trends over time (ASCII, HTML, or JSON)
kaizen report owners πŸ‘₯ Generate code ownership report
kaizen history list πŸ“‹ List all stored analysis snapshots
kaizen history show πŸ” Display detailed snapshot information
kaizen history prune πŸ—‘οΈ Remove old snapshots

πŸ€– GitHub Action β€” Full Reference

πŸ“₯ Inputs

Input Description Default
path Directory to analyze .
base-branch Branch to compare against main
skip-churn Skip git churn analysis for faster runs true
github-token GitHub token for posting PR comments ${{ github.token }}
fail-on-regression Fail the action if the score drops false
languages Comma-separated list of languages to include all
include-callgraph Include SVG call graph of changed functions (Go only) false

πŸ“€ Outputs

Output Description
score-delta Numeric score change between base and head
grade Current grade letter (A-F)
has-concerns Whether blast-radius concerns were found

πŸ”§ Full Example

name: Kaizen PR Analysis

on:
  pull_request:
    branches: [main, develop]

jobs:
  kaizen:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: read
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: acollie/kaizen@v0.1.0-beta
        id: kaizen
        with:
          path: "."
          base-branch: main
          skip-churn: "true"
          fail-on-regression: "true"
          languages: "go,kotlin"
          include-callgraph: "true"

      - name: Check results
        run: |
          echo "Score delta: ${{ steps.kaizen.outputs.score-delta }}"
          echo "Grade: ${{ steps.kaizen.outputs.grade }}"
          echo "Has concerns: ${{ steps.kaizen.outputs.has-concerns }}"

πŸ’¬ What the PR Comment Shows

  • 🎯 Grade and Score β€” overall health grade (A-F) with numeric score out of 100
  • πŸ“ˆ Score Delta β€” how much the score changed compared to the base branch
  • πŸ“Š Metrics Table β€” overall score, avg complexity, maintainability, hotspot count, function count with deltas
  • πŸ”₯ Hotspot Changes β€” new hotspots introduced, hotspots fixed, and persistent hotspots
  • πŸ’₯ Blast-Radius Warnings β€” functions with high fan-in (many callers) that were modified
  • πŸ”— Call Graph (optional) β€” SVG artifact showing changed functions and their callers/callees

πŸ“Œ Pinning a Version

      # Pin to a specific release (recommended)
      - uses: acollie/kaizen@v0.1.0-beta

      # Or track the latest on main (may include breaking changes)
      - uses: acollie/kaizen@main

πŸ”‘ Using with a Custom Token

The default ${{ github.token }} works for most cases. If you need to trigger other workflows from the comment, use a Personal Access Token or GitHub App token:

      - uses: acollie/kaizen@v0.1.0-beta
        with:
          github-token: ${{ secrets.KAIZEN_TOKEN }}

🎯 Roadmap

πŸš€ Planned Features

  • πŸ“Š Web dashboard for team health monitoring
  • πŸ€– GitHub integration (automatic PR comments via reusable Action)
  • 🐍 Complete Python analyzer with tree-sitter AST parsing
  • πŸ“ˆ Advanced trend prediction
  • πŸ¦€ Rust analyzer
  • πŸ“± TypeScript/JavaScript analyzer
  • β˜• Java analyzer

πŸ”§ Quality Improvements

  • ⚑ Performance optimization for massive codebases (100M+ LOC)
  • πŸ’¬ Better error messages and recovery
  • 🧡 Parallel analysis for multi-core systems
  • πŸ”„ Incremental analysis (only changed files)

πŸ—οΈ How It Works

🧱 Architecture

Kaizen uses a modular, language-agnostic architecture:

  • πŸ”Œ Interface-based language analyzers β€” easy to add new languages
  • 🌳 Tree-sitter AST parsing β€” accurate syntax understanding (Python, Kotlin, Swift)
  • 🐹 Go's ast package β€” native support for Go analysis
  • πŸ’Ύ SQLite time-series database β€” efficient historical tracking
  • ⌨️ Cobra CLI framework β€” professional command structure

πŸ“– See Architecture Guide for technical details.

🌍 Supported Languages

Language Status Parser Coverage
🐹 Go βœ… Full go/ast 95%+
🐍 Python βœ… Full tree-sitter 90%+
🟣 Kotlin βœ… Full tree-sitter 90%+
🍎 Swift βœ… Full tree-sitter 90%+

πŸ“ What It Analyzes

Per-File: lines of code, import count, duplication percentage

Per-Function: length, parameter count, cyclomatic complexity, cognitive complexity, nesting depth, Halstead metrics, maintainability index, fan-in/fan-out

🎨 Visualizations

πŸ—ΊοΈ Interactive Heatmap β€” drill-down treemap with color-coded metrics. Color intensity = severity, box size = code volume, click to explore, hover for details.

πŸ”— Call Graph β€” D3.js force-directed graph showing function call relationships. Node size = fan-in, color = complexity. Filter by --base to show only changed functions.

πŸ”„ Sankey Diagram β€” code ownership flow showing team-to-function dependencies. Flow width = call frequency.

πŸ“Ÿ Terminal Charts β€” quick ASCII trend lines without opening a browser.

⚑ Performance

Project Size Estimated Time
10K LOC ~0.1-0.5s
100K LOC ~1-3s
1M LOC ~15-25s
10M+ LOC ~3-5m

πŸ’‘ Use --skip-churn to disable git operations (adds 20-40% overhead). Run on SSD for 2-3x faster I/O. Exclude large directories with .kaizenignore.


🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for code style, testing requirements, and pull request process.

🌍 Adding a New Language

  1. Create pkg/languages/<lang>/ directory
  2. Implement the LanguageAnalyzer interface
  3. Register in pkg/languages/registry.go
  4. Add tests
  5. Submit PR

πŸ“– See Adding Languages for the detailed guide.

πŸ› Reporting Issues


βœ… Quality Assurance

All code changes are tested across Go versions 1.21, 1.22, and 1.23 on Linux:

  • πŸ§ͺ Unit Tests: 50+ test files covering analyzers, metrics, and language parsers
  • πŸ”— Integration Tests: end-to-end analysis and visualization pipeline validation
  • πŸ“Š Coverage Target: 50%+ on main branch with automated codecov checks
  • πŸ”„ CI Pipeline: automated testing, linting (golangci-lint), and build verification on every PR

Tests codecov


πŸ“‹ Requirements

  • 🐹 Go 1.21+
  • πŸ”€ Git (optional β€” use --skip-churn without it)
  • 🌳 Tree-sitter libraries for Kotlin/Swift (auto-installed)

πŸ“– Documentation


πŸ“œ License

MIT License β€” see LICENSE for details.

πŸ™ Acknowledgments

Built with go-tree-sitter, Cobra, D3.js, and GORM.

About

πŸ”οΈ Kaizen is a multi-language code analytics platform combining cyclomatic complexity, maintainability indexing, and git-driven churn detection with interactive visualization

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors