How dkapur17/streamlit-flow works
Project type and purpose
• Streamlit Flow is a hybrid full-stack component library: a Python package that wraps a React/React Flow front-end as a Streamlit custom component.
File structure
• Top-level:
• setup.py, MANIFEST.in, LICENSE, build_and_upload.sh, post_build_cleanup.sh → packaging and release scripts
• example.py → a sample Streamlit app demonstrating usage
• assets/ → demo videos and images
• Package root “streamlit_flow/”:
• __init__.py → component entry point, exports streamlit_flow()
• elements.py → Python classes modeling nodes & edges
• state.py → StreamlitFlowState class (state management)
• layouts.py → Python layout base classes
• frontend/ → React application for the UI
– package.json, .env → React build configuration
– public/index.html → host HTML
– src/StreamlitFlowComponent.jsx, StreamlitFlowApp.jsx, index.jsx → React component glue for Streamlit
– components/, layouts/ (ElkLayout.js), style.css → sub-components & styling
README for additional insights
• Description of the component’s features: node/edge creation, context menus, multiple layouts, markdown support, bidirectional state sync
• Usage patterns: how Python code constructs a StreamlitFlowState and passes it to streamlit_flow()
• Build & run instructions showing two processes: npm start for the front-end, streamlit run for the example
• Streamlit App (example.py or any user script)
• Streamlit Server / Python runtime (hosts the component)
• streamlit_flow Python module (elements.py, state.py, layouts.py)
• Streamlit Components API (RPC channel between Python and JS)
• React/React Flow front-end (frontend/src…)
• External dependencies: npm/Node.js, pip packages
b. Relationships and data flows:
1. User writes a Python script and runs streamlit run example.py.
2. Streamlit Server imports streamlit_flow and invokes the custom component function.
3. The Python side serializes the initial state (nodes, edges) and sends it via the Streamlit Components API to the React front-end.
5. On each interaction, the front-end posts updated state back through the Components API.
6. Python side (StreamlitFlowState) receives updates, stores them in st.session_state, and may trigger a rerun.
7. If Python code mutates the state programmatically (e.g., calls a layout algorithm in layouts.py), it sends the new state back to the front-end on the next render.
c. Architectural patterns and principles:
• Clear separation of concerns: Python backend vs. React UI
• Bidirectional state synchronization via a component API bridge
• Pluggable layout strategy (Strategy pattern) implemented in both Python and JS
• Component packaging: Python wheel containing prebuilt React assets
d. Key technologies and libraries:
• Python 3.x, Streamlit, pip, setuptools
• React, React Flow, JSX, webpack (via create-react-app)
• npm, Node.js for front-end build
• Streamlit Components API for RPC between Python and JavaScript