{"id":43335805,"url":"https://github.com/moinsen-dev/code_analyzer","last_synced_at":"2026-02-02T00:36:05.477Z","repository":{"id":314608264,"uuid":"1056144986","full_name":"moinsen-dev/code_analyzer","owner":"moinsen-dev","description":"A Python-based command-line tool that provides comprehensive analysis of source code repositories","archived":false,"fork":false,"pushed_at":"2025-09-23T09:32:41.000Z","size":3619,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-09-23T11:30:57.671Z","etag":null,"topics":["ai","analyzer","code","python3"],"latest_commit_sha":null,"homepage":"https://moinsen-dev.github.io/code_analyzer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moinsen-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-13T13:36:40.000Z","updated_at":"2025-09-23T09:29:38.000Z","dependencies_parsed_at":"2025-09-23T11:19:53.163Z","dependency_job_id":null,"html_url":"https://github.com/moinsen-dev/code_analyzer","commit_stats":null,"previous_names":["moinsen-dev/code_analyzer"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/moinsen-dev/code_analyzer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Fcode_analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Fcode_analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Fcode_analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Fcode_analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moinsen-dev","download_url":"https://codeload.github.com/moinsen-dev/code_analyzer/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinsen-dev%2Fcode_analyzer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28997069,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T23:10:54.274Z","status":"ssl_error","status_checked_at":"2026-02-01T23:10:47.298Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","analyzer","code","python3"],"created_at":"2026-02-02T00:36:04.939Z","updated_at":"2026-02-02T00:36:05.471Z","avatar_url":"https://github.com/moinsen-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Refactoroscope\n\n[![Build Status](https://github.com/moinsen-dev/refactoroscope/actions/workflows/ci.yml/badge.svg)](https://github.com/moinsen-dev/refactoroscope/actions)\n[![Python Version](https://img.shields.io/badge/python-3.13-blue.svg)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/github/license/moinsen-dev/refactoroscope)](LICENSE)\n[![Code Coverage](https://img.shields.io/codecov/c/github/moinsen-dev/refactoroscope)](https://codecov.io/gh/moinsen-dev/refactoroscope)\n[![PyPI version](https://badge.fury.io/py/refactoroscope.svg)](https://badge.fury.io/py/refactoroscope)\n[![CI/CD Integration](https://img.shields.io/badge/CI%2FCD-GitHub%20Actions%20%26%20GitLab%20CI-blue)](docs/ci-cd-integration.md)\n\n![Refactoroscope Icon](code-analyzer-icon.png)\n\nA Python-based command-line tool that provides comprehensive analysis of source code repositories. Think of it as an **MRI scanner for your codebase** - it doesn't just show you what's there, but reveals the health and complexity of your code structure.\n\n![Refactoroscope Wallpaper](code-analyzer-wallpaper.png)\n\n## Features\n\n- Scans directories recursively for source code files\n- Respects `.gitignore` patterns at all directory levels\n- Counts lines of code per file\n- Displays file sizes in human-readable format\n- Sorts results by line count\n- Beautiful terminal output using Rich\n- Code complexity analysis (Cyclomatic, Cognitive, Halstead)\n- Duplicate code detection using AST-based analysis\n- **Unused code detection using AST-based analysis**\n- **Unused file detection using dependency graph analysis**\n- **AI-powered code quality suggestions**\n- **Advanced refactoring tools with AI-powered refactoring plan generation**\n- **Tech stack detection for 10+ programming languages (Python, JavaScript/TypeScript, Flutter, Go, Rust, Ruby, PHP, Java, Kotlin)**\n- **Integrated tool execution for each detected tech stack**\n- **Outdated package detection for all supported tech stacks**\n- Export results to JSON/CSV/HTML\n- Configuration file support (.refactoroscope.yml)\n- Multi-language support (60+ programming languages)\n- Performance optimizations with parallel processing\n- CI/CD integration support (GitHub Actions, GitLab CI)\n- Real-time file watching for live code analysis\n- Advanced AST-based duplicate code detection with clone type classification\n\n## Duplicate Code Detection\n\nThe Refactoroscope provides advanced AST-based duplicate code detection with the following features:\n\n- **Clone Type Classification**: Identifies different types of code clones:\n  - **Exact Clones** (Type-1): Identical code except for comments and whitespace\n  - **Renamed Clones** (Type-2): Syntactically identical with identifier renames\n  - **Modified Clones** (Type-3): Semantically similar with small modifications\n  - **Semantic Clones** (Type-4): Functionally equivalent but syntactically different\n\n- **Cross-File Detection**: Finds duplicate code patterns across different files in your project\n\n- **Similarity Scoring**: Provides quantitative similarity measures between code blocks (0.0 to 1.0)\n\n- **Performance Optimizations**: Uses caching and global indexing for efficient analysis of large codebases\n\nThe duplicate detection can be customized with the `duplicates` command:\n\n```bash\n# Analyze for exact duplicates only (complexity analysis is now included by default)\nuv run refactoroscope duplicates src/ --type exact\n\n# Find similar code with minimum similarity threshold\nuv run refactoroscope duplicates src/ --min-similarity 0.8\n\n# Focus on renamed clones\nuv run refactoroscope duplicates src/ --type renamed\n```\n\n### Installation\n\nRefactoroscope can be installed in several ways depending on your needs. **Note: AI providers (OpenAI, Anthropic, Google) are now required dependencies.**\n\n#### Method 1: Install from PyPI (Recommended for most users)\n\n```bash\npip install refactoroscope\n```\n\nThis installs Refactoroscope globally on your system and makes it available as a command-line tool. **AI providers are now included by default.**\n\n#### Method 2: Install with uv (Recommended for developers)\n\nFirst, install [uv](https://github.com/astral-sh/uv) if you haven't already:\n\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n\nThen install Refactoroscope globally:\n\n```bash\nuv tool install refactoroscope\n```\n\n#### Method 3: Install from source (Recommended for contributors)\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/moinsen-dev/refactoroscope.git\n   cd refactoroscope\n   ```\n\n2. Install dependencies:\n   ```bash\n   uv sync\n   ```\n\n3. Install in development mode:\n   ```bash\n   pip install -e .\n   ```\n\n## Usage\n\n### Basic Analysis\n\n```bash\n# Analyze current directory (complexity analysis is now enabled by default)\nuv run refactoroscope analyze .\n\n# Analyze specific directory\nuv run refactoroscope analyze /path/to/project\n\n# Disable complexity analysis (if needed)\nuv run refactoroscope analyze . --no-complexity\n\n# Enable AI-powered suggestions\nuv run refactoroscope analyze . --ai\n```\n\n### AI-Powered Analysis\n\nRefactoroscope provides AI-powered code quality suggestions integrated directly into the main analysis command. The AI analysis provides intelligent insights on code readability, performance, potential bugs, and security issues.\n\n```bash\n# Analyze with AI-powered suggestions\nuv run refactoroscope analyze . --ai\n\n# Enable AI suggestions during watching\nuv run refactoroscope watch . --ai\n\n# Check tech stacks and run appropriate tools for each subfolder\nuv run refactoroscope analyze . --check\n\n# Generate an AI-based refactoring plan for the codebase\nuv run refactoroscope refactor-plan .\n```\n\n#### AI Provider Configuration\n\nTo use AI-powered features, you need to configure at least one AI provider in your `.refactoroscope.yml` configuration file:\n\n```yaml\n# AI configuration\nai:\n  # Enable AI-powered code suggestions\n  enable_ai_suggestions: true\n  \n  # Maximum file size to analyze with AI (in bytes)\n  max_file_size: 50000\n  \n  # Whether to cache AI analysis results\n  cache_results: true\n  \n  # Cache time-to-live in seconds\n  cache_ttl: 3600\n  \n  # Preference order for AI providers\n  provider_preferences:\n    - \"openai\"\n    - \"anthropic\"\n    - \"google\"\n    - \"ollama\"\n    - \"qwen\"\n  \n  # Provider configurations\n  providers:\n    openai:\n      # API key (can also be set via OPENAI_API_KEY environment variable)\n      # api_key: \"your-openai-api-key\"\n      \n      # Model to use\n      model: \"gpt-3.5-turbo\"\n      \n      # Whether this provider is enabled\n      enabled: true\n    \n    anthropic:\n      # API key (can also be set via ANTHROPIC_API_KEY environment variable)\n      # api_key: \"your-anthropic-api-key\"\n      \n      # Model to use\n      model: \"claude-3-haiku-20240307\"\n      \n      # Whether this provider is enabled\n      enabled: true\n    \n    google:\n      # API key (can also be set via GOOGLE_API_KEY environment variable)\n      # api_key: \"your-google-api-key\"\n      \n      # Model to use\n      model: \"gemini-pro\"\n      \n      # Whether this provider is enabled\n      enabled: true\n    \n    ollama:\n      # Ollama doesn't require API keys\n      \n      # Model to use\n      model: \"llama2\"\n      \n      # Base URL for Ollama (default is localhost)\n      base_url: \"http://localhost:11434\"\n      \n      # Whether this provider is enabled\n      enabled: true\n    \n    qwen:\n      # Qwen doesn't require API keys for local installations\n      \n      # Model to use\n      model: \"qwen\"\n      \n      # Base URL for Qwen (default is localhost)\n      base_url: \"http://localhost:11434\"\n      \n      # Whether this provider is enabled\n      enabled: true\n```\n\n### Tech Stack Analysis and Tool Execution\n\nRefactoroscope can automatically detect technology stacks in your project and run the appropriate tools for each stack:\n\n```bash\n# Analyze current directory and run appropriate tools for detected tech stacks\nuv run refactoroscope analyze . --check\n\n# This will:\n# 1. Detect technology stacks (Python, JavaScript, Flutter, Go, Rust, etc.)\n# 2. Run appropriate linters, formatters, and type checkers for each stack\n# 3. Check for outdated packages\n# 4. Display results in terminal\n\n# Example output for a Python project:\n# Folder: src/\n# Detected Tech Stacks: python\n# Tool Results:\n#   • lint_ruff: ✓ Passed\n#   • format_black: ✗ Failed (would reformat src/main.py)\n#   • type_mypy: ✓ Passed\n# Outdated Packages:\n#   • requests: 2.31.0 -\u003e 2.32.3\n```\n\n### AI-Powered Refactoring Plan Generation\n\nGenerate comprehensive, AI-based refactoring plans for your codebase:\n\n```bash\n# Generate an AI-based refactoring plan for your project\nuv run refactoroscope refactor-plan .\n\n# Generate refactoring plan with specific AI provider\nuv run refactoroscope refactor-plan . --provider openai\n\n# Save refactoring plan to specific file\nuv run refactoroscope refactor-plan . --output my_refactoring_plan.md\n\n# This will:\n# 1. Analyze your codebase\n# 2. Detect complexity hotspots, duplicate code, code smells\n# 3. Generate a phased refactoring plan with implementation timeline\n# 4. Provide risk assessment and success metrics\n```\n\n#### Supported AI Providers\n\n1. **OpenAI**: Supports GPT models (GPT-3.5, GPT-4, etc.)\n2. **Anthropic**: Supports Claude models\n3. **Google**: Supports Gemini models\n4. **Ollama**: Supports locally-run models (no API key required)\n\nFor cloud-based providers, you can set API keys via environment variables:\n- `OPENAI_API_KEY` for OpenAI\n- `ANTHROPIC_API_KEY` for Anthropic\n- `GOOGLE_API_KEY` for Google\n\n### Real-time Watching\n\n```bash\n# Watch current directory for changes (complexity analysis is now enabled by default)\nuv run refactoroscope watch .\n\n# Enable AI-powered suggestions during watching\nuv run refactoroscope watch . --ai\n\n# Disable complexity analysis (if needed)\nuv run refactoroscope watch . --no-complexity\n```\n\n### Output Formats\n\n```bash\n# Display in terminal (default)\nuv run refactoroscope analyze . --output terminal\n\n# Export to JSON\nuv run refactoroscope analyze . --export json --export-dir ./reports\n\n# Export to multiple formats\nuv run refactoroscope analyze . --export json,html --export-dir ./reports\n```\n\n### Advanced Usage\n\n```bash\n# Compare two analysis reports\nuv run refactoroscope compare reports/report1.json reports/report2.json\n\n# Initialize configuration file\nuv run refactoroscope init\n\n# Analyze for duplicate code with advanced options\nuv run refactoroscope duplicates src/ --type exact --min-similarity 0.9\n\n# Analyze for unused code\nuv run refactoroscope unused src/\n\n# Analyze for unused files\nuv run refactoroscope unused-files src/\n\n# Analyze for unused files with confidence threshold\nuv run refactoroscope unused-files src/ --confidence 0.7\n```\n\n### Unused Code Detection\n\nRefactoroscope can identify potentially unused code in your Python projects using AST-based static analysis. This feature helps you identify dead code that can be safely removed to reduce technical debt.\n\nThe unused code detection identifies:\n- Unused functions and methods\n- Unused classes\n- Unused variables\n- Unused imports\n\n```bash\n# Analyze for unused code\nuv run refactoroscope unused src/\n\n# Get JSON output for unused code\nuv run refactoroscope unused src/ --output json\n```\n\nThe analysis provides confidence scores for each finding to help you distinguish between likely unused code and potential false positives.\n\n### Unused File Detection\n\nRefactoroscope can also identify completely unused files in your Python projects using dependency graph analysis. This feature helps you identify entire files that are never imported by any other file in your project.\n\n```bash\n# Analyze for unused files\nuv run refactoroscope unused-files src/\n\n# Analyze for unused files with confidence threshold\nuv run refactoroscope unused-files src/ --confidence 0.7\n\n# Get JSON output for unused files\nuv run refactoroscope unused-files src/ --output json\n```\n\nThe unused file detection uses the following approach:\n1. Builds a dependency graph of all Python files in your project\n2. Identifies entry points (files with `__main__` guards, common entry point names)\n3. Performs reachability analysis to find files that are not reachable from entry points\n4. Provides confidence scores to help distinguish between truly unused files and potential false positives\n\n## Supported Languages\n\nThe Refactoroscope supports 60+ programming languages:\n\n- **Primary**: Python, JavaScript/TypeScript, Java, C#, C++/C, Go, Rust\n- **Mobile**: Dart/Flutter, Swift, Kotlin\n- **Web**: HTML, CSS/SCSS, Vue, React, Svelte\n- **Scripting**: PHP, Ruby\n- **Configuration**: YAML, JSON, TOML, XML\n- **Data**: SQL, GraphQL\n- **Documentation**: Markdown, reStructuredText\n\n## Configuration\n\nCreate a `.refactoroscope.yml` file in your project root:\n\n```yaml\nversion: 1.0\n\n# Language-specific settings\nlanguages:\n  python:\n    max_line_length: 88\n    complexity_threshold: 10\n  typescript:\n    max_line_length: 100\n    complexity_threshold: 15\n\n# Analysis rules\nanalysis:\n  ignore_patterns:\n    - \"*.generated.*\"\n    - \"*_pb2.py\"\n    - \"*.min.js\"\n    - \"node_modules/\"\n    - \".git/\"\n\n  complexity:\n    include_docstrings: false\n    count_assertions: true\n\n  thresholds:\n    file_too_long: 500\n    function_too_complex: 20\n    class_too_large: 1000\n\n# Output preferences\noutput:\n  format: \"terminal\"  # terminal, json, html, csv\n  theme: \"monokai\"\n  show_recommendations: true\n  export_path: \"./reports\"\n\n# AI configuration\nai:\n  # Enable AI-powered code suggestions\n  enable_ai_suggestions: false\n  \n  # Maximum file size to analyze with AI (in bytes)\n  max_file_size: 50000\n  \n  # Whether to cache AI analysis results\n  cache_results: true\n  \n  # Cache time-to-live in seconds\n  cache_ttl: 3600\n  \n  # Preference order for AI providers\n  provider_preferences:\n    - \"openai\"\n    - \"anthropic\"\n    - \"google\"\n    - \"ollama\"\n  \n  # Provider configurations\n  providers:\n    openai:\n      # API key (can also be set via OPENAI_API_KEY environment variable)\n      # api_key: \"your-openai-api-key\"\n      \n      # Model to use\n      model: \"gpt-3.5-turbo\"\n      \n      # Whether this provider is enabled\n      enabled: false\n    \n    anthropic:\n      # API key (can also be set via ANTHROPIC_API_KEY environment variable)\n      # api_key: \"your-anthropic-api-key\"\n      \n      # Model to use\n      model: \"claude-3-haiku-20240307\"\n      \n      # Whether this provider is enabled\n      enabled: false\n    \n    google:\n      # API key (can also be set via GOOGLE_API_KEY environment variable)\n      # api_key: \"your-google-api-key\"\n      \n      # Model to use\n      model: \"gemini-pro\"\n      \n      # Whether this provider is enabled\n      enabled: false\n    \n    ollama:\n      # Ollama doesn't require API keys\n      \n      # Model to use\n      model: \"llama2\"\n      \n      # Base URL for Ollama (default is localhost)\n      base_url: \"http://localhost:11434\"\n      \n      # Whether this provider is enabled\n      enabled: false\n```\n\n## CI/CD Integration\n\nRefactoroscope provides built-in support for popular CI/CD platforms:\n\n### GitHub Actions\n\nTo integrate Refactoroscope into your GitHub Actions workflow, create a workflow file in `.github/workflows/`:\n\n```yaml\nname: Code Analysis\non: [push, pull_request]\n\njobs:\n  analyze:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - name: Run Code Analysis\n        uses: moinsen-dev/refactoroscope@v0.2.0\n        with:\n          args: analyze . --complexity --export json,html\n```\n\nAlternatively, you can install and run it directly:\n\n```yaml\n- name: Install uv\n  uses: astral-sh/setup-uv@v3\n\n- name: Install Refactoroscope\n  run: |\n    uv pip install refactoroscope\n\n- name: Run analysis\n  run: |\n    refactoroscope analyze . --complexity --export json,html --export-dir ./reports\n```\n\n### GitLab CI\n\nFor GitLab CI, add this to your `.gitlab-ci.yml`:\n\n```yaml\nanalyze:\n  stage: test\n  script:\n    - pip install refactoroscope\n    - refactoroscope analyze . --complexity --export json,html --export-dir ./reports\n  artifacts:\n    paths:\n      - reports/\n```\n\nSee [CI/CD Integration Guide](docs/ci-cd-integration.md) for more detailed instructions.\n\n## Documentation\n\nFor detailed documentation, visit our [GitHub Pages site](https://moinsen-dev.github.io/refactoroscope/).\n\n- [Real-time Watching](docs/watch.md)\n- [AI-Powered Analysis](docs/ai.md)\n- [Duplicate Code Detection](docs/duplicates.md)\n- [Unused Code Detection](docs/unused_code.md)\n- [Unused File Detection](docs/unused_file_detection.md)\n\nSee [CHANGELOG.md](CHANGELOG.md) for release history.\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](docs/contributing.md) for more information.\n\n## Release Process\n\nNew versions are automatically published to PyPI when a new tag is created following the pattern `v*.*.*`. To release a new version:\n\n1. Update the version in `pyproject.toml` and `setup.py`\n2. Create a new tag: `git tag -a v1.0.0 -m \"Release version 1.0.0\"`\n3. Push the tag: `git push origin v1.0.0`\n4. The GitHub Actions workflow will automatically build and publish to PyPI","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinsen-dev%2Fcode_analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoinsen-dev%2Fcode_analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinsen-dev%2Fcode_analyzer/lists"}