A RAG-based code analysis tool that understands your codebase and provides intelligent suggestions for improvement.
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
# Clone the repository
git clone <repository-url>
cd fix-code-debt
# Install dependencies
pip install -r requirements.txt# 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# 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># 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π§ Initializing Intelligent Codebase Features...
π Initializing codebase intelligence system...
π Loading embedding model...
ποΈ Setting up vector database...
β
Codebase Intelligence initialized successfully!
π 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
π 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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
- 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
- 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
- Technical Debt: Identify areas that need refactoring
- Architecture: Analyze dependencies and coupling between modules
- Maintenance: Track code changes and their impact across files
- 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
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=INFOOption 1: Use the helper script (recommended)
python3 create_env.pyOption 2: Create .env file manually
Create a .env file in your project root:
echo "OPENAI_API_KEY=your_actual_api_key" > .envOption 3: Set system environment variables
export OPENAI_API_KEY=your_actual_api_keyThe tool automatically loads environment variables from .env files using python-dotenv.
Note: The
.envfile is automatically ignored by git for security.
- 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
python3 -m iterate.cli /path/to/python/project --intelligence --codebase-insightspython3 -m iterate.cli /path/to/js/project --find-duplicatespython3 -m iterate.cli . --context-aware-tests src/main.pypython3 -m iterate.cli . --monitor --duration 300This project is designed to be a smart code analysis tool that helps developers understand and improve their codebases. Contributions are welcome!
[Add your license information here]