explaingit

scottrogowski/code2flow

4,572PythonAudience · developerComplexity · 2/5LicenseSetup · moderate

TLDR

A command-line tool that reads Python, JavaScript, Ruby, or PHP source files and generates a visual diagram showing which functions call which other functions.

Mindmap

mindmap
  root((repo))
    What It Does
      Generate call graphs
      Trace function calls
      Find orphaned code
    Supported Languages
      Python
      JavaScript
      Ruby and PHP
    Output
      DOT file format
      Image via Graphviz
    Usage
      CLI tool
      Python library
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate a call graph for an unfamiliar codebase to quickly understand how functions connect.

USE CASE 2

Find orphaned functions that nothing calls in a large Python or JavaScript project.

USE CASE 3

Visualize the structure of complex code before refactoring to see what depends on what.

USE CASE 4

Document how your application flows from its entry point through to its output as a diagram.

Tech stack

PythonGraphviz

Getting it running

Difficulty · moderate Time to first run · 30min

Requires Graphviz to be installed separately on your system in addition to the pip package.

MIT license, use, modify, and distribute freely for any purpose including commercial projects.

In plain English

Code2flow is a command-line tool that reads your source code files and produces a diagram showing which functions call which other functions. These diagrams are called call graphs, and they give you a visual map of how code flows from one piece to another. The tool supports Python, JavaScript, Ruby, and PHP. To use it, you install it via pip and point it at one or more source files. It outputs a DOT file, which is a standard format for graph diagrams, and renders it as an image using Graphviz, a separate free tool you also need to install. You can narrow the output to focus on a specific function and control how many levels of callers and callees to include. The tool can also be used as a Python library rather than from the command line. The tool works by parsing the source code into an internal structure, finding all function definitions, and then tracing where each function is called. Because Python, JavaScript, Ruby, and PHP are dynamic languages where values and types are only known at runtime, perfect accuracy is not possible. Code2flow documents its known limitations clearly: functions that share a name in different contexts may be skipped, anonymous functions and lambdas are skipped, and functions passed around as variables may not be traced correctly. The result is described as a pretty good estimate of project structure rather than an exact map. The tool is useful for developers trying to understand an unfamiliar codebase, identify functions that nothing calls (orphaned code), or untangle code that has grown complex over time. It can generate diagrams for a single file or an entire directory of source files. Code2flow is released under the MIT license and has 100% test coverage according to its own test suite.

Copy-paste prompts

Prompt 1
Run code2flow on this Python file and show me a diagram of all the function call relationships.
Prompt 2
How do I use code2flow to generate a call graph that focuses only on calls from a specific function?
Prompt 3
Install code2flow and Graphviz, then generate a PNG call graph for all .py files in my src/ folder.
Prompt 4
Use code2flow as a Python library to programmatically generate a call graph and save it as an SVG.
Prompt 5
What are the known limitations of code2flow when analyzing dynamic Python code with lambdas or closures?
Open on GitHub → Explain another repo

← scottrogowski on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.