Skip to main content

AI-powered code debt fixing tool with intelligent test generation

Project description

๐Ÿง  Codebase Intelligence System

A RAG-based code analysis tool that understands your codebase and provides intelligent suggestions for improvement.

๐ŸŽฏ What This Project Does

This tool uses Retrieval-Augmented Generation (RAG) to analyze codebases and provide intelligent insights:

  • ๐Ÿ” Code Parsing: Parses Python, JavaScript, TypeScript files with AST analysis
  • ๐Ÿง  Vector Database: Stores code embeddings for semantic search
  • ๐Ÿ“Š Code Insights: Analyzes functions, classes, complexity, and dependencies
  • ๐Ÿ”„ Duplicate Detection: Finds similar code patterns across files
  • ๐ŸŽฏ Refactoring Suggestions: Identifies cross-file refactoring opportunities
  • ๐Ÿงช Test Generation: Creates context-aware tests based on your codebase
  • ๐Ÿค– AI Integration: Provides intelligent code improvement suggestions

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone <repository-url>
cd fix-code-debt

# Install dependencies
pip install -r requirements.txt

Basic Usage

# Initialize intelligence system
python3 -m iterate.cli . --intelligence

# Get codebase insights
python3 -m iterate.cli . --codebase-insights

# Find duplicate code patterns
python3 -m iterate.cli . --find-duplicates

# Analyze cross-file refactoring opportunities
python3 -m iterate.cli . --cross-file-refactor

๐Ÿ“‹ Available Commands

Core Features

# Initialize the intelligence system
python3 -m iterate.cli <directory> --intelligence

# Get comprehensive codebase insights
python3 -m iterate.cli <directory> --codebase-insights

# Find duplicate code patterns
python3 -m iterate.cli <directory> --find-duplicates

# Suggest cross-file refactoring opportunities
python3 -m iterate.cli <directory> --cross-file-refactor

# Generate intelligent refactoring suggestions for a specific file
python3 -m iterate.cli <directory> --intelligent-refactor <file_path>

# Generate context-aware tests for a file
python3 -m iterate.cli <directory> --context-aware-tests <file_path>

# Update context when a file changes
python3 -m iterate.cli <directory> --update-context <file_path>

Traditional File Scanning

# Basic directory scan
python3 -m iterate.cli <directory>

# Non-recursive scan
python3 -m iterate.cli <directory> --no-recursive

# Limit scan depth
python3 -m iterate.cli <directory> --max-depth 3

# Monitor directory for changes
python3 -m iterate.cli <directory> --monitor

# Verbose output
python3 -m iterate.cli <directory> -v

๐Ÿ“Š What You'll See

Intelligence Initialization

๐Ÿง  Initializing Intelligent Codebase Features...
๐Ÿ” Initializing codebase intelligence system...
๐Ÿ“Š Loading embedding model...
๐Ÿ—„๏ธ  Setting up vector database...
โœ… Codebase Intelligence initialized successfully!

Codebase Insights

๐Ÿ“Š Getting codebase insights...
๐Ÿ“ Total chunks: 45
๐Ÿ“„ Unique files: 12
๐Ÿ”ง Functions: 23
๐Ÿ—๏ธ  Classes: 8
๐Ÿ“ฆ Imports: 14
๐Ÿ“Š Average complexity: 3.2
โš ๏ธ  High complexity functions: 3
๐Ÿ”„ Duplicates found: 2
๐ŸŽฏ Cross-file opportunities: 5

Duplicate Detection

๐Ÿ” Finding duplicate code patterns...
๐ŸŽฏ Found 2 duplicate patterns:
๐Ÿ“ Function: validate_input
   Occurrences: 3
   Files: utils.py, helpers.py, main.py
   Suggestion: Consider extracting 'validate_input' into a shared utility function

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    RAG System Architecture                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚   File Parser   โ”‚  โ”‚  AST Analyzer   โ”‚  โ”‚  Chunking   โ”‚ โ”‚
โ”‚  โ”‚                 โ”‚  โ”‚                 โ”‚  โ”‚             โ”‚ โ”‚
โ”‚  โ”‚ โ€ข Python AST    โ”‚  โ”‚ โ€ข Functions     โ”‚  โ”‚ โ€ข Functions โ”‚ โ”‚
โ”‚  โ”‚ โ€ข JS Regex      โ”‚  โ”‚ โ€ข Classes       โ”‚  โ”‚ โ€ข Classes   โ”‚ โ”‚
โ”‚  โ”‚ โ€ข Multi-lang    โ”‚  โ”‚ โ€ข Imports       โ”‚  โ”‚ โ€ข Modules   โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ€ข Complexity    โ”‚  โ”‚ โ€ข Imports   โ”‚ โ”‚
โ”‚                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚   Embeddings    โ”‚  โ”‚  Vector DB      โ”‚  โ”‚  Query      โ”‚ โ”‚
โ”‚  โ”‚                 โ”‚  โ”‚                 โ”‚  โ”‚             โ”‚ โ”‚
โ”‚  โ”‚ โ€ข Sentence      โ”‚  โ”‚ โ€ข ChromaDB      โ”‚  โ”‚ โ€ข Semantic  โ”‚ โ”‚
โ”‚  โ”‚   Transformers  โ”‚  โ”‚ โ€ข Persistent    โ”‚  โ”‚ โ€ข Similarityโ”‚ โ”‚
โ”‚  โ”‚ โ€ข all-MiniLM    โ”‚  โ”‚ โ€ข Collections   โ”‚  โ”‚ โ€ข Context   โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

fix-code-debt/
โ”œโ”€โ”€ iterate/
โ”‚   โ”œโ”€โ”€ cli.py                          # Main CLI interface
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ codebase_intelligence.py    # RAG system core
โ”‚   โ”‚   โ”œโ”€โ”€ intelligent_ai_generator.py # AI integration
โ”‚   โ”‚   โ”œโ”€โ”€ ai_code_generator.py        # AI code generation
โ”‚   โ”‚   โ”œโ”€โ”€ dependency_mapper.py        # Dependency analysis
โ”‚   โ”‚   โ”œโ”€โ”€ test_generator.py           # Test generation
โ”‚   โ”‚   โ””โ”€โ”€ ... (other core modules)
โ”‚   โ”œโ”€โ”€ utils/                          # Utility functions
โ”‚   โ””โ”€โ”€ integrations/                   # External integrations
โ”œโ”€โ”€ tests/                              # Test files
โ””โ”€โ”€ README.md                           # This file

๐ŸŽฏ Use Cases

For Developers

  • Code Review: Quickly identify complex functions and potential issues
  • Refactoring: Find duplicate code and cross-file refactoring opportunities
  • Testing: Generate context-aware tests for your functions
  • Documentation: Understand codebase structure and dependencies

For Teams

  • Code Quality: Monitor complexity and maintainability metrics
  • Knowledge Sharing: Understand how different parts of the codebase relate
  • Onboarding: Help new developers understand the codebase structure

For Projects

  • Technical Debt: Identify areas that need refactoring
  • Architecture: Analyze dependencies and coupling between modules
  • Maintenance: Track code changes and their impact across files

๐Ÿ”ง Dependencies

  • sentence-transformers: For code embeddings
  • chromadb: For vector database storage
  • numpy: For numerical operations
  • ast: For Python code parsing
  • re: For regex-based parsing
  • python-dotenv: For environment variable management
  • openai: For AI-powered code generation

๐Ÿ”‘ Environment Setup

Required Environment Variables

The tool requires certain environment variables to be set for full functionality:

# OpenAI API key (required for AI features)
OPENAI_API_KEY=your_openai_api_key_here

# Optional environment variables
CHROMA_DB_PATH=./.iterate_cache/chromadb
LOG_LEVEL=INFO

Setting Up Environment Variables

Option 1: Use the helper script (recommended)

python3 create_env.py

Option 2: Create .env file manually Create a .env file in your project root:

echo "OPENAI_API_KEY=your_actual_api_key" > .env

Option 3: Set system environment variables

export OPENAI_API_KEY=your_actual_api_key

The tool automatically loads environment variables from .env files using python-dotenv.

Note: The .env file is automatically ignored by git for security.

๐Ÿš€ Future Features

  • Real-time Updates: File watchers for live code analysis
  • Enhanced AI: Context-aware code generation and refactoring
  • Multi-language Support: More programming languages
  • IDE Integration: Plugin for popular IDEs
  • Team Analytics: Code quality metrics and trends

๐Ÿ“ Examples

Analyze a Python Project

python3 -m iterate.cli /path/to/python/project --intelligence --codebase-insights

Find Duplicates in JavaScript Project

python3 -m iterate.cli /path/to/js/project --find-duplicates

Generate Tests for Specific File

python3 -m iterate.cli . --context-aware-tests src/main.py

Monitor Changes

python3 -m iterate.cli . --monitor --duration 300

๐Ÿค Contributing

This project is designed to be a smart code analysis tool that helps developers understand and improve their codebases. Contributions are welcome!

๐Ÿ“„ License

[Add your license information here]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iterate_code_debt-0.1.0.tar.gz (55.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iterate_code_debt-0.1.0-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file iterate_code_debt-0.1.0.tar.gz.

File metadata

  • Download URL: iterate_code_debt-0.1.0.tar.gz
  • Upload date:
  • Size: 55.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for iterate_code_debt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 271659242ba409f4cdfdf1c9cf9d4071ac4095f1afa4597338423d245b445698
MD5 db48421ab17799673d75d0dada870784
BLAKE2b-256 865114abc154d4b128b4e57663a875b664b2c17f27c9569854d13dacd7505671

See more details on using hashes here.

File details

Details for the file iterate_code_debt-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for iterate_code_debt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45570b4a3b3f5dab71cd2e27a08c8ffe5cf0e595a643b74e2349064a6d6adf75
MD5 b622210f0b4ea08afc21c90122e69f96
BLAKE2b-256 146c8bb3f6a2b8230bd6f642d2ae1ce03b6d0226f1abf7c44579c4a75eea6bc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page