How cdfmlr/pyflowchart works
1. Repository purpose
- This is a small Python package whose core job is to turn either:
- manually constructed flowchart objects, or
- Python source code
into the textual flowchart.js DSL.
- The generated DSL can be printed to stdout or wrapped into a standalone HTML page for interactive viewing.
2. Main public boundary
- The pyflowchart package is the public API surface.
- pyflowchart/__init__.py likely re-exports the main classes/functions so users can do from pyflowchart import *.
- The package supports both library usage and command-line usage.
3. Core domain model: flowchart nodes
- node.py defines the flowchart element types and their relationships.
- From the README, the supported node kinds map directly to flowchart.js concepts:
- Start
- Operation
- Condition
- Input/Output
- Subroutine
- End
- These nodes expose connection methods like generic connect() and condition-specific branches like connect_yes() / connect_no().
- This is the graph-building layer: it represents a flowchart independent of Python source code.
4. Graph serialization layer
- flowchart.py is the main orchestration layer for turning a connected node graph into flowchart.js text.
- It appears to own the Flowchart class used in both manual-node mode and source-code mode.
- Its output is the DSL string printed to stdout, embedded into HTML, or pasted into flowchart.js-compatible renderers.
- This is the key boundary between internal model and external rendering syntax.
5. Python source-to-flowchart translation
- ast_node.py is the AST analysis layer.
- It likely walks Python’s built-in ast structures and maps language constructs to flowchart nodes.
- The README indicates support for:
- functions and methods selected by dotted path
- if / else
- loops
- match/case
- try/except/else/finally
- This layer is where source code semantics are converted into a control-flow graph.
6. End-to-end data flow
- The primary pipeline for code translation is:
1. Read Python source text
2. Parse it into an AST
3. Select a target field/function/method, if requested
4. Convert AST control-flow into connected node objects
5. Serialize those nodes into flowchart.js DSL
6. Emit DSL to stdout or wrap it in HTML
- That pipeline is the central architecture to diagram.
7. CLI entry point
- __main__.py provides the python -m pyflowchart entry point.
- The CLI mirrors the library API:
- choose a file
- optionally choose a function/method path
- optionally parse only the body (inner)
- optionally simplify one-line blocks
- optionally align consecutive conditions
- optionally write HTML output
- The CLI is just a thin wrapper around the core Flowchart.from_code(...) path.
8. HTML output subsystem
- output_html.py is a separate presentation layer.
- It takes a flowchart DSL string and writes a self-contained HTML page that renders the diagram interactively.
- This is not part of the graph model or AST parser; it is an output adapter for browser-based visualization.
9. Package and build boundaries
- pyproject.toml and setup.py indicate a standard Python packaging setup.
- The project targets Python 3.7+ and is tested up through Python 3.14 per the README.
- This is a pure Python library with no compiled components and no backend service.
10. Testing and quality automation
- pyflowchart/test.py contains the project’s test code.
- GitHub Actions workflows cover:
- test execution
- CodeQL analysis
- PyPI/TestPyPI publishing
- release publishing
- These workflows do not affect runtime architecture, but they show the package is shipped as a distributable library with CI-driven validation and release automation.
11. External dependencies and integration points
- The main external “runtime dependency” conceptually is flowchart.js, because the package emits its DSL.
- Python’s built-in ast module is the parser backbone for source translation.
- HTML output relies on browser-side rendering of the generated DSL, not on a server.
12. How to draw the architecture
- A good diagram would show two ingress paths:
- manual node construction into the node graph
- Python source file into AST parsing
- Both paths converge into the same Flowchart serialization layer.
- From there, output splits into:
- stdout / DSL text
- HTML file generation
- Supporting boxes around that core would be:
- CLI wrapper
- HTML output adapter
- CI/release automation around the package
Main entry points: flowchart.py Flowchart · test.py Tests · node.py Nodes · pyproject.toml Pyproject
Components 16
Core engine
Flowchart model, AST translation, and serialization.
- Flowchart · Orchestrates node graphs into flowchart.js DSL.
pyflowchart/flowchart.py - Nodes · Flowchart node types and connection behavior.
pyflowchart/node.py - AST parser · Maps Python AST control flow into flowchart nodes.
pyflowchart/ast_node.py
Public interface
Package entry points and command-line usage.
- pyflowchart · Top-level package surface and re-exports.
pyflowchart/__init__.py - CLI · python -m pyflowchart command-line wrapper.
pyflowchart/__main__.py
Outputs
DSL and HTML presentation adapters.
- HTML output · Wraps DSL into a self-contained interactive HTML page.
pyflowchart/output_html.py
Automation
Testing, CI, packaging, and release.
- Tests · Project test coverage and behavioral checks.
pyflowchart/test.py - Pyproject · Modern packaging and project metadata.
pyproject.toml - Setup · Legacy packaging entrypoint and install metadata.
setup.py - README · Primary usage and feature documentation.
README.md - README zh · Chinese documentation translation.
README_zh-CN.md - Docs examples · Example-driven usage notes and illustrations.
docs/examples.md - CI tests · GitHub Actions test workflow.
.github/workflows/tests.yml - CodeQL · Static analysis workflow.
.github/workflows/codeql-analysis.yml - Release publish · Release publication workflow.
.github/workflows/release-publish.yml - PyPI publish · TestPyPI publishing workflow.
.github/workflows/TestPyPi-publish.yml
Connections 19
- pyflowchart → Flowchart: exports · Public API exposes the main flowchart builder.
- pyflowchart → Nodes: exports · Package surface exposes node classes for manual graphs.
- CLI → Flowchart: uses · CLI delegates to Flowchart construction and serialization.
- Nodes → Flowchart: builds input · Connected nodes form the graph serialized by Flowchart.
- AST parser → Nodes: creates · AST traversal produces node graphs and branches.
- AST parser → Flowchart: feeds · Translated control flow is passed into Flowchart output.
- Flowchart → HTML output: wraps · DSL output can be embedded into standalone HTML.
- Flowchart → README: documented by · README describes the serialization and usage flow.
- HTML output → Flowchart: consumes DSL · HTML adapter takes generated flowchart.js text.
- Tests → Nodes: verifies · Tests cover graph construction and node behavior.
- Tests → AST parser: verifies · Tests exercise source-to-flowchart translation.
- Tests → Flowchart: verifies · Tests cover serialization and top-level behavior.
- Pyproject → Setup: packages with · Project uses standard Python packaging metadata.
- CI tests → Tests: runs · CI executes the test suite.
- CodeQL → Pyproject: analyzes · CodeQL workflow scans the repository.
- Release publish → Pyproject: publishes · Release workflow ships the package artifact.
- PyPI publish → Pyproject: publishes · TestPyPI workflow validates distribution publishing.
- Docs examples → Flowchart: explains · Examples show how to use the core serializer.
- README zh → README: translates · Localized documentation mirrors the main README.