# cdfmlr/pyflowchart architecture

> Architecture diagram of the GitHub repository cdfmlr/pyflowchart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cdfmlr/pyflowchart
- Repository: https://github.com/cdfmlr/pyflowchart

## Overview

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: [`pyflowchart/flowchart.py`](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/flowchart.py) (Flowchart), [`pyflowchart/test.py`](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/test.py) (Tests), [`pyflowchart/node.py`](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/node.py) (Nodes), [`pyproject.toml`](https://github.com/cdfmlr/pyflowchart/blob/master/pyproject.toml) (Pyproject)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core engine"]
  node_flowchart_core["Flowchart<br/>serializer<br/>[flowchart.py]"]
  node_node_model["Nodes<br/>graph model<br/>[node.py]"]
  node_ast_translator["AST parser<br/>source translator<br/>[ast_node.py]"]
end

subgraph group_interface["Public interface"]
  node_pkg_api["pyflowchart<br/>public API<br/>[__init__.py]"]
  node_cli(("CLI<br/>entrypoint<br/>[__main__.py]"))
end

subgraph group_output["Outputs"]
  node_html_output["HTML output<br/>adapter<br/>[output_html.py]"]
end

subgraph group_automation["Automation"]
  node_test_suite["Tests<br/>[test.py]"]
  node_pyproject["Pyproject<br/>build config<br/>[pyproject.toml]"]
  node_setup_py["Setup<br/>build config<br/>[setup.py]"]
  node_readme["README<br/>docs<br/>[README.md]"]
  node_readme_zh["README zh<br/>docs<br/>[README_zh-CN.md]"]
  node_docs_examples["Docs examples<br/>[examples.md]"]
  node_ci_tests["CI tests<br/>workflow<br/>[tests.yml]"]
  node_ci_codeql["CodeQL<br/>workflow"]
  node_release_pub["Release publish<br/>workflow"]
  node_pypi_pub["PyPI publish<br/>workflow"]
end

node_pkg_api -->|"exports"| node_flowchart_core
node_pkg_api -->|"exports"| node_node_model
node_cli -->|"uses"| node_flowchart_core
node_node_model -->|"builds input"| node_flowchart_core
node_ast_translator -->|"creates"| node_node_model
node_ast_translator -->|"feeds"| node_flowchart_core
node_flowchart_core -->|"wraps"| node_html_output
node_flowchart_core -.->|"documented by"| node_readme
node_html_output -->|"consumes DSL"| node_flowchart_core
node_test_suite -.->|"verifies"| node_node_model
node_test_suite -.->|"verifies"| node_ast_translator
node_test_suite -.->|"verifies"| node_flowchart_core
node_pyproject -.->|"packages with"| node_setup_py
node_ci_tests -->|"runs"| node_test_suite
node_ci_codeql -.->|"analyzes"| node_pyproject
node_release_pub -.->|"publishes"| node_pyproject
node_pypi_pub -.->|"publishes"| node_pyproject
node_docs_examples -.->|"explains"| node_flowchart_core
node_readme_zh -.->|"translates"| node_readme

click node_pkg_api "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/__init__.py"
click node_cli "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/__main__.py"
click node_flowchart_core "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/flowchart.py"
click node_node_model "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/node.py"
click node_ast_translator "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/ast_node.py"
click node_html_output "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/output_html.py"
click node_test_suite "https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/test.py"
click node_pyproject "https://github.com/cdfmlr/pyflowchart/blob/master/pyproject.toml"
click node_setup_py "https://github.com/cdfmlr/pyflowchart/blob/master/setup.py"
click node_readme "https://github.com/cdfmlr/pyflowchart/blob/master/README.md"
click node_readme_zh "https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md"
click node_docs_examples "https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md"
click node_ci_tests "https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/tests.yml"
click node_ci_codeql "https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/codeql-analysis.yml"
click node_release_pub "https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/release-publish.yml"
click node_pypi_pub "https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/TestPyPi-publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_flowchart_core,node_node_model,node_ast_translator toneBlue
class node_pkg_api,node_cli toneAmber
class node_html_output toneMint
class node_test_suite,node_pyproject,node_setup_py,node_readme,node_readme_zh,node_docs_examples,node_ci_tests,node_ci_codeql,node_release_pub,node_pypi_pub toneRose
```

## Components

### Core engine

Flowchart model, AST translation, and serialization.

- [Flowchart](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/flowchart.py): serializer · Orchestrates node graphs into flowchart.js DSL. · `pyflowchart/flowchart.py`
- [Nodes](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/node.py): graph model · Flowchart node types and connection behavior. · `pyflowchart/node.py`
- [AST parser](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/ast_node.py): source translator · Maps Python AST control flow into flowchart nodes. · `pyflowchart/ast_node.py`

### Public interface

Package entry points and command-line usage.

- [pyflowchart](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/__init__.py): public API · Top-level package surface and re-exports. · `pyflowchart/__init__.py`
- [CLI](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/__main__.py): entrypoint · python -m pyflowchart command-line wrapper. · `pyflowchart/__main__.py`

### Outputs

DSL and HTML presentation adapters.

- [HTML output](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/output_html.py): adapter · Wraps DSL into a self-contained interactive HTML page. · `pyflowchart/output_html.py`

### Automation

Testing, CI, packaging, and release.

- [Tests](https://github.com/cdfmlr/pyflowchart/blob/master/pyflowchart/test.py): test · Project test coverage and behavioral checks. · `pyflowchart/test.py`
- [Pyproject](https://github.com/cdfmlr/pyflowchart/blob/master/pyproject.toml): build config · Modern packaging and project metadata. · `pyproject.toml`
- [Setup](https://github.com/cdfmlr/pyflowchart/blob/master/setup.py): build config · Legacy packaging entrypoint and install metadata. · `setup.py`
- [README](https://github.com/cdfmlr/pyflowchart/blob/master/README.md): docs · Primary usage and feature documentation. · `README.md`
- [README zh](https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md): docs · Chinese documentation translation. · `README_zh-CN.md`
- [Docs examples](https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md): docs · Example-driven usage notes and illustrations. · `docs/examples.md`
- [CI tests](https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/tests.yml): workflow · GitHub Actions test workflow. · `.github/workflows/tests.yml`
- [CodeQL](https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/codeql-analysis.yml): workflow · Static analysis workflow. · `.github/workflows/codeql-analysis.yml`
- [Release publish](https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/release-publish.yml): workflow · Release publication workflow. · `.github/workflows/release-publish.yml`
- [PyPI publish](https://github.com/cdfmlr/pyflowchart/blob/master/.github/workflows/TestPyPi-publish.yml): workflow · TestPyPI publishing workflow. · `.github/workflows/TestPyPi-publish.yml`

## Connections

- 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.
