Skip to main content

Installation

Install Refactron using pip:
pip install refactron
Refactron requires Python 3.8 or higher

Complete Workflow

Follow this workflow to get the most out of Refactron:
1

Login

Authenticate with Refactron to unlock AI features:
refactron login
2

Initialize Configuration

Set up Refactron in your project:
refactron init
Choose a template (base, django, fastapi, or flask) to get started quickly.
3

Connect Repository (Optional)

Connect your GitHub repository for enhanced features:
refactron repo connect
4

Analyze Your Code

Run comprehensive code analysis:
refactron analyze . --detailed
5

Get AI Suggestions

Generate AI-powered refactoring suggestions:
refactron suggest myfile.py
6

Apply Refactoring

Preview and apply refactoring changes:
# Preview changes first
refactron refactor myfile.py --preview

# Apply when ready
refactron refactor myfile.py --apply
7

Generate Report

Create a comprehensive technical debt report:
refactron report . --format html -o report.html
8

Rollback if Needed

Rollback changes if something goes wrong:
refactron rollback

Quick Commands

Analyze Code

# Analyze a file
refactron analyze mycode.py

# Analyze a directory
refactron analyze myproject/

# Get detailed analysis
refactron analyze . --detailed

Refactor Code

# Preview refactoring suggestions
refactron refactor myfile.py --preview

# Apply automated fixes
refactron autofix myfile.py --apply

# Apply specific refactoring
refactron refactor myfile.py --apply

AI-Powered Features

# Get AI suggestions
refactron suggest myfile.py --query "How can I improve this?"

# Generate documentation
refactron document myfile.py

# Use RAG for context-aware suggestions
refactron rag query "How to optimize database queries?"

Python API

Use Refactron programmatically in your Python code:
from refactron import Refactron

# Initialize Refactron
refactron = Refactron()

# Analyze code
analysis = refactron.analyze("path/to/code.py")
print(analysis.report())

# Preview refactoring
result = refactron.refactor("path/to/code.py", preview=True)
result.show_diff()

# Apply refactoring
result = refactron.refactor("path/to/code.py", preview=False)

Example Output

When you run an analysis, you’ll see:
 Analyzing myproject/
  Files analyzed: 25
  Issues found: 12
  
  CRITICAL (2):
  - SQL injection vulnerability (line 45)
  - Hardcoded secret detected (line 78)
  
  ERROR (4):
  - High cyclomatic complexity (line 120)
  - Deep nesting detected (line 156)
  
  WARNING (6):
  - Magic number usage (line 23)
  - Missing type hints (line 67)

Next Steps