{"id":51339610,"url":"https://github.com/semcod/code2logic","last_synced_at":"2026-07-02T06:04:31.906Z","repository":{"id":332046595,"uuid":"1127162527","full_name":"semcod/code2logic","owner":"semcod","description":"High-performance Python code flow analysis with NLP query processing - CFG, DFG, call graphs, and intelligent code queries","archived":false,"fork":false,"pushed_at":"2026-06-29T08:59:32.000Z","size":3085,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-29T09:24:32.526Z","etag":null,"topics":["ast","call-graph","code-analysis","code-understanding","control-flow","data-flow","llm","nlp","python","reverse-engineering","semcod","static-analysis"],"latest_commit_sha":null,"homepage":"https://semcod.github.io/code2logic/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semcod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"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":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-03T10:07:28.000Z","updated_at":"2026-06-29T08:59:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/semcod/code2logic","commit_stats":null,"previous_names":["wronai/code2logic"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/semcod/code2logic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2logic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2logic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2logic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2logic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semcod","download_url":"https://codeload.github.com/semcod/code2logic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2logic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35034998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ast","call-graph","code-analysis","code-understanding","control-flow","data-flow","llm","nlp","python","reverse-engineering","semcod","static-analysis"],"created_at":"2026-07-02T06:04:31.279Z","updated_at":"2026-07-02T06:04:31.897Z","avatar_url":"https://github.com/semcod.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# code2flow\n\n## AI Cost Tracking\n\n![AI Cost](https://img.shields.io/badge/AI%20Cost-$33.83-orange) ![AI Model](https://img.shields.io/badge/AI%20Model-openrouter%2Fqwen%2Fqwen3-coder-next-lightgrey)\n\nThis project uses AI-generated code. Total cost: **$33.8299** with **122** AI commits.\n\nGenerated on 2026-06-29 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/models/openrouter/qwen/qwen3-coder-next)\n\n---\n\n\n\n**Python Code Flow Analysis Tool** - Static analysis for control flow graphs (CFG), data flow graphs (DFG), and call graph extraction.\n\n## Performance Optimization\n\nFor large projects (\u003e1000 functions), use **Fast Mode**:\n\n```bash\n# Ultra-fast analysis (5-10x faster)\ncode2flow /path/to/project --fast\n\n# Custom performance settings\ncode2flow /path/to/project \\\n    --parallel-workers 8 \\\n    --max-depth 3 \\\n    --skip-data-flow \\\n    --cache-dir ./.cache\n```\n\n### Performance Tips\n\n| Technique | Speedup | Use Case |\n|-----------|---------|----------|\n| `--fast` mode | 5-10x | Initial exploration |\n| Parallel workers | 2-4x | Multi-core machines |\n| Caching | 3-5x | Repeated analysis |\n| Depth limiting | 2-3x | Large codebases |\n| Skip private methods | 1.5-2x | Public API analysis |\n\n### Benchmarks\n\n| Project Size | Functions | Time (fast) | Time (full) |\n|--------------|-----------|-------------|-------------|\n| Small (\u003c100) | ~50 | 0.5s | 2s |\n| Medium (1K) | ~500 | 3s | 15s |\n| Large (10K) | ~2000 | 15s | 120s |\n\n## Features\n\n- **Control Flow Graph (CFG)**: Extract execution paths from Python AST\n- **Data Flow Graph (DFG)**: Track variable definitions and dependencies  \n- **Call Graph Analysis**: Map function calls and dependencies\n- **Pattern Detection**: Identify design patterns (state machines, factories, recursion)\n- **Compact Output**: Deduplicated flow diagrams with pattern recognition\n- **Multiple Output Formats**: YAML, JSON, Mermaid diagrams, PNG visualizations\n- **LLM-Ready Output**: Generate prompts for reverse engineering\n\n## Installation\n\n```bash\n# Install from source\npip install -e .\n\n# Or with development dependencies\npip install -e \".[dev]\"\n```\n\n## Quick Start\n\n```bash\n# Analyze a Python project\ncode2flow /path/to/project\n\n# With verbose output\ncode2flow /path/to/project -v\n\n# Specify output directory and formats\ncode2flow /path/to/project -o ./analysis --format yaml,json,mermaid,png\n\n# Use different analysis modes\ncode2flow /path/to/project -m static    # Fast static analysis only\ncode2flow /path/to/project -m hybrid     # Combined analysis (default)\n```\n\n## Usage\n\n### Basic Analysis\n```bash\ncode2flow /path/to/project\n```\n\n### Analysis Modes\n```bash\n# Static analysis only (fastest)\ncode2flow /path/to/project -m static\n\n# Dynamic analysis with tracing\ncode2flow /path/to/project -m dynamic\n\n# Hybrid analysis (recommended)\ncode2flow /path/to/project -m hybrid\n\n# Behavioral pattern focus\ncode2flow /path/to/project -m behavioral\n\n# Reverse engineering ready\ncode2flow /path/to/project -m reverse\n```\n\n### Custom Output\n```bash\ncode2flow /path/to/project -o my_analysis\n```\n\n## Output Files\n\n| File | Description |\n|------|-------------|\n| `analysis.yaml` | Complete structured analysis data |\n| `analysis.json` | JSON format for programmatic use |\n| `flow.mmd` | Full Mermaid flowchart (all nodes) |\n| `compact_flow.mmd` | **Compact flowchart** - deduplicated nodes, grouped by function |\n| `calls.mmd` | Function call graph |\n| `cfg.png` | Control flow visualization |\n| `call_graph.png` | Call graph visualization |\n| `llm_prompt.md` | LLM-ready analysis summary |\n\n### Compact Flow Format\n\nThe `compact_flow.mmd` file provides optimized output:\n\n- **Deduplication**: Identical node patterns are merged (e.g., `x = 1`, `x = 2` → `x = N`)\n- **Function Subgraphs**: Nodes grouped by function in subgraphs\n- **Pattern Preservation**: Control flow structure maintained while reducing file size\n- **Import Reuse**: Common patterns linked rather than duplicated\n\nExample compact output:\n```mermaid\nflowchart TD\n    %% Function subgraphs\n    subgraph F12345[\"process_data\"]\n        N1[\"x = N\"]  \n        N2{\"if x \u003e 0\"}\n        N3[/\"return x\"/]\n    end\n    \n    %% Edges reference deduplicated nodes\n    N1 --\u003e N2\n    N2 --\u003e|\"true\"| N3\n```\n\n## Understanding the Output\n\n### LLM Prompt Structure\nThe generated prompt includes:\n- System overview with metrics\n- Call graph structure\n- Behavioral patterns with confidence scores\n- Data flow insights\n- State machine definitions\n- Reverse engineering guidelines\n\n### Behavioral Patterns\nEach pattern includes:\n- **Name**: Descriptive identifier\n- **Type**: sequential, conditional, iterative, recursive, state_machine\n- **Entry/Exit points**: Key functions\n- **Decision points**: Conditional logic locations\n- **Data transformations**: Variable dependencies\n- **Confidence**: Pattern detection certainty\n\n### Reverse Engineering Guidelines\nThe analysis provides specific guidance for:\n1. Preserving call graph structure\n2. Implementing identified patterns\n3. Maintaining data dependencies\n4. Recreating state machines\n5. Preserving decision logic\n\n## Advanced Features\n\n### State Machine Detection\nAutomatically identifies:\n- State variables\n- Transition methods\n- Source and destination states\n- State machine hierarchy\n\n### Data Flow Tracking\nMaps:\n- Variable dependencies\n- Data transformations\n- Information flow paths\n- Side effects\n\n### Dynamic Tracing\nWhen using dynamic mode:\n- Function entry/exit timing\n- Call stack reconstruction\n- Exception tracking\n- Performance profiling\n\n## Integration with LLMs\n\nThe generated `system_analysis_prompt.md` is designed to be:\n- **Comprehensive**: Contains all necessary system information\n- **Structured**: Organized for easy parsing\n- **Actionable**: Includes specific implementation guidance\n- **Language-agnostic**: Describes behavior, not implementation\n\nExample usage with an LLM:\n```\n\"Based on the system analysis provided, implement this system in Go,\npreserving all behavioral patterns and data flow characteristics.\"\n```\n\n## Limitations\n\n- Dynamic analysis requires test files\n- Complex inheritance hierarchies may need manual review\n- External library calls are treated as black boxes\n- Runtime reflection and metaprogramming not fully captured\n\n## Contributing\n\nThe analyzer is designed to be extensible. Key areas for enhancement:\n- Additional pattern types\n- Language-specific optimizations\n- Improved visualization\n- Real-time analysis mode\n\n## License\n\nLicensed under Apache-2.0.\n## Author\n\nTom Sapletta\n## Status\n\n_Last updated by [taskill](https://github.com/oqlos/taskill) at 2026-04-25 13:36 UTC_\n\n| Metric | Value |\n|---|---|\n| HEAD | `bdf9336` |\n| Coverage | — |\n| Failing tests | — |\n| Commits in last cycle | 50 |\n\n\u003e Large refactor and feature sweep: added a deep code analysis engine and supporting modules, improved configuration management and CLI, integrated AppDefaults for auto-loading a default LLM profile, and delegated env file I/O to getv.EnvStore. Docs, examples, and tests were updated alongside several chore/quality improvements and a release commit.\n\n\u003c!-- taskill:status:end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fcode2logic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemcod%2Fcode2logic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fcode2logic/lists"}