11# code2flow
22
3- ** Python Code Flow Analysis Tool** — Static analysis for control flow graphs (CFG), data flow graphs (DFG), and call graph extraction with 4 purpose-built output formats .
3+ ** Python Code Flow Analysis Tool** - Static analysis for control flow graphs (CFG), data flow graphs (DFG), and call graph extraction with optimized TOON format .
44
55![ img.png] ( img.png )
66
7- ## 🚀 New in v0.3.0: Format Taxonomy
7+ ## 🚀 New: TOON Format v2
88
9- ** 4 files, 4 purposes ** — each format answers a different question :
9+ ** TOON v2 ** is the default output format - scannable, severity-sorted, prompt-ready :
1010
11- | Format | File | Purpose | Answers |
12- | --------| ------| ---------| ---------|
13- | ** Map** | ` project.map ` | Structure | "What exists and how it's connected?" |
14- | ** Toon** | ` analysis.toon ` | Health diagnostics | "What's broken and how to fix it?" |
15- | ** Flow** | ` flow.toon ` | Data flow | "How do data flow through the system?" |
16- | ** Context** | ` context.md ` | LLM narrative | "Understand the system to rebuild it" |
11+ - ** 🎯 Health-first design** - issues sorted by severity (🔴/🟡)
12+ - ** 📊 Coupling matrix** - fan-in/fan-out analysis
13+ - ** 🔍 Duplicate detection** - find identical classes
14+ - ** 📈 Layered architecture** - package-level metrics
15+ - ** ⚡ Inline markers** - ` !! ` (CC≥15), ` ! ` (CC≥10), ` ×DUP `
16+ - ** 🚫 Smart filtering** - excludes venv, site-packages
17+ - ** 📋 Actionable REFACTOR** - concrete steps, not just problems
1718
1819``` bash
19- # Default: health diagnostics only
20+ # Default: TOON format only
2021code2flow /path/to/project
2122
22- # Generate all 4 core formats
23- code2flow /path/to/project -f toon,map,flow,context
24-
25- # Generate everything (all 8 formats)
23+ # Generate all formats
2624code2flow /path/to/project -f all
2725
28- # Just the structural map
29- code2flow /path/to/project -f map
30- ```
31-
32- ### When to Use Which Format
33-
34- ```
35- "What's in the project?" → project.map
36- "What's broken?" → analysis.toon (HEALTH)
37- "How to fix it?" → analysis.toon (REFACTOR)
38- "How do data flow through the system?"→ flow.toon (PIPELINES)
39- "Where to split a type?" → flow.toon (DATA_TYPES)
40- "Is the pipeline pure?" → flow.toon (CONTRACTS)
41- "How to rebuild in another language?" → context.md
42- "What depends on this module?" → analysis.toon (COUPLING)
43- "What type does a function return?" → project.map (signatures)
26+ # TOON + YAML (for comparison)
27+ code2flow /path/to/project -f toon,yaml
4428```
4529
46- ## 🎯 TOON v2 — Health Diagnostics
47-
48- ** TOON v2** (` analysis.toon ` ) is the default output — scannable, severity-sorted, prompt-ready:
49-
50- - ** 🎯 Health-first design** — issues sorted by severity (🔴/🟡)
51- - ** 📊 Coupling matrix** — fan-in/fan-out analysis
52- - ** 🔍 Duplicate detection** — find identical classes
53- - ** 📈 Layered architecture** — package-level metrics
54- - ** ⚡ Inline markers** — ` !! ` (CC≥15), ` ! ` (CC≥10), ` ×DUP `
55- - ** 🚫 Smart filtering** — excludes venv, site-packages
56- - ** 📋 Actionable REFACTOR** — concrete steps, not just problems
57-
5830## Performance Optimization
5931
6032For large projects (>1000 functions), use ** Fast Mode** :
@@ -171,26 +143,17 @@ code2flow /path/to/project -o my_analysis
171143
172144## Output Files
173145
174- ### Core Formats (4 purpose-built files)
175-
176- | File | Format | Purpose | Size |
177- | ------| --------| ---------| ------|
178- | ` analysis.toon ` | ** Toon** | Health diagnostics (HEALTH, REFACTOR, COUPLING) | ~ 25KB |
179- | ` project.map ` | ** Map** | Structural map (modules, imports, signatures) | ~ 23KB |
180- | ` flow.toon ` | ** Flow** | Data-flow analysis (PIPELINES, CONTRACTS, DATA_TYPES) | ~ 10KB |
181- | ` context.md ` | ** Context** | LLM narrative (architecture, patterns, API) | ~ 30KB |
182-
183- ### Additional Formats
184-
185146| File | Description | Size |
186147| ------| -------------| ------|
148+ | ` analysis.toon ` | ** 🎯 Optimized TOON format** (default) | ~ 200KB |
187149| ` analysis.yaml ` | Complete structured analysis data | ~ 2.5MB |
188150| ` analysis.json ` | JSON format for programmatic use | ~ 2.6MB |
189151| ` flow.mmd ` | Full Mermaid flowchart (all nodes) | ~ 9KB |
190- | ` compact_flow.mmd ` | Compact flowchart — deduplicated nodes | ~ 9KB |
152+ | ` compact_flow.mmd ` | Compact flowchart - deduplicated nodes | ~ 9KB |
191153| ` calls.mmd ` | Function call graph | ~ 9KB |
192154| ` cfg.png ` | Control flow visualization | ~ 7MB |
193155| ` call_graph.png ` | Call graph visualization | ~ 3.7MB |
156+ | ` llm_prompt.md ` | LLM-ready analysis summary | ~ 35KB |
194157
195158## 🎯 TOON v2 Format Structure
196159
@@ -210,10 +173,10 @@ REFACTOR[4]:
210173
211174COUPLING:
212175 ┌─────────────┬──────────────────────────────────────┐
213- │ Package │ fan-in fan-out status │
176+ │ Package │ fan-in fan-out status │
214177 ├─────────────┼──────────────────────────────────────┤
215178 │ core │ 12 45 !! split needed │
216- │ exporters │ 5 28 hub │
179+ │ exporters │ 5 28 hub │
217180 └─────────────┴──────────────────────────────────────┘
218181
219182LAYERS:
@@ -360,12 +323,9 @@ The analyzer is designed to be extensible. Key areas for enhancement:
360323
361324| Command | Output | Use Case |
362325| ---------| --------| ----------|
363- | ` code2flow ./project ` | ` analysis.toon ` | Quick health diagnostics (default) |
364- | ` code2flow ./project -f all ` | All 8 formats | Complete analysis |
365- | ` code2flow ./project -f toon,map,flow,context ` | 4 core formats | Full taxonomy |
366- | ` code2flow ./project -f map ` | ` project.map ` | Structural map |
367- | ` code2flow ./project -f flow ` | ` flow.toon ` | Data-flow analysis |
368- | ` code2flow ./project -f context ` | ` context.md ` | LLM narrative |
326+ | ` code2flow ./project ` | ` analysis.toon ` | Quick analysis (default) |
327+ | ` code2flow ./project -f all ` | All formats | Complete analysis |
328+ | ` code2flow ./project -f toon,yaml ` | TOON + YAML | Comparison |
369329| ` code2flow ./project -m hybrid -v ` | TOON + verbose | Detailed analysis |
370330| ` python validate_toon.py analysis.toon ` | Validation | Quality check |
371331
@@ -475,19 +435,19 @@ code2flow ./project -f toon,yaml
475435# Both formats available for comparison
476436```
477437
478- ## 📋 TOON v2 Format Specification
438+ ## 📋 TOON Format Specification
479439
480440### File Structure
481441```
482442analysis.toon
483- ├── Header lines # Project summary + key metrics
484- ├── HEALTH # Highest-severity issues (🔴/🟡)
485- ├── REFACTOR # Actionable refactoring steps
486- ├── COUPLING # Package-level fan-in/fan-out summary
487- ├── LAYERS # Package hierarchy + inline markers
488- ├── FUNCTIONS # CC-filtered function list (focus on CC≥10)
489- ├── HOTSPOTS # Top fan-out functions
490- └── CLASSES # Class-level complexity summary
443+ ├── meta # Metadata (project, mode, timestamp)
444+ ├── stats # Analysis statistics
445+ ├── functions # Function analysis with complexity
446+ ├── classes # Class information from function grouping
447+ ├── modules # Module-level statistics
448+ ├── patterns # Detected design patterns
449+ ├── call_graph # Top 50 most important functions
450+ └── insights # Recommendations and summaries
491451```
492452
493453### Complexity Scoring
0 commit comments