How ai-yash/st-chat works
Project type & purpose (what you’re diagramming)
This repo is a Streamlit custom component packaged as a Python library (streamlit-chat) that provides a chat UI (message bubbles, alignment, markdown/HTML/table rendering) for Streamlit apps. It’s not a full “system” with a backend/database; it’s a reusable UI component with:
• Python API surface (what the Streamlit developer imports: from streamlit_chat import message)
• A frontend implementation (TypeScript/React-style Streamlit component frontend under streamlit_chat/frontend)
• The Streamlit component bridge/runtime (Streamlit’s components mechanism that synchronizes Python ↔ iframe’d frontend via messages/props)
Python packaging / distribution
• setup.py, MANIFEST.in, requirements*.txt, LICENSE
• streamlit_chat/__init__.py (exposes the public API; likely defines message() and registers the component + points to frontend build assets)
• test_component.py (local testing harness for the component)
Frontend component (built + source)
• streamlit_chat/frontend/src/* (actual UI logic)
• Chat.tsx, stChat.tsx (main UI component(s))
• message.tsx (message bubble rendering)
• avatar.tsx (avatars)
• CSS: stChat.css, index.css
• main.tsx (frontend entry)
• streamlit_chat/frontend/package.json, vite.config.ts, tsconfig*.json (build toolchain)
• streamlit_chat/frontend/build/* (compiled static assets that get shipped with the Python package)
Docs / examples / CI
• examples/chatbot.py (consumer usage pattern; shows Streamlit app loop + session_state)
• docs/*, mkdocs.yml, .github/workflows/* (documentation site + CI publishing)
What the README implies architecturally
• The user calls message("…", is_user=True, allow_html=True, is_table=...) from a Streamlit script.
• The component renders chat messages, supports HTML-in-markdown when explicitly allowed, and can render a “table mode”.
• The component is purely UI; any “bot logic” is in the consuming app (e.g., examples/chatbot.py), not in this repo.
User Browser
• Contains Streamlit UI + the component iframe
Streamlit App (Python)
• The developer’s app code (e.g., examples/chatbot.py)
• Uses st.session_state and calls streamlit_chat.message()
streamlit_chat Python Package
• Public API: message()
• Component registration (Streamlit Components API)
• Serves/points to frontend build assets
streamlit_chat Frontend (TSX)
• Chat UI components: stChat.tsx, message.tsx, avatar.tsx
• Styling: stChat.css
Streamlit Component Bridge
• The bidirectional message/props channel between Python and frontend (Streamlit’s component protocol over websocket)
• *Streamlit App → streamlit_chat (Python)*: function call message(text, is_user, allow_html, is_table, key, ...)
• *streamlit_chat (Python) → Streamlit Component Bridge*: sends props (message text, flags, styling choices, keys)
• *Component Bridge → Frontend iframe*: delivers props to the TS frontend
• *Frontend → Browser DOM*: renders chat bubbles, markdown/table/html
Important annotation to include:
• The frontend runs in an iframe (standard Streamlit custom component model).
• allow_html is a security toggle (trusted content only).
• The chat “history” isn’t maintained by the component; it’s typically maintained in st.session_state in the consumer app.
This repo includes both TS source and compiled assets; for accuracy, show the pipeline.
• Developer workstation / CI
• Frontend build system: vite (from vite.config.ts, package.json)
• Output: streamlit_chat/frontend/build/*
• Python packaging: setup.py + MANIFEST.in
• Artifact: PyPI package streamlit-chat
• Consumer environment: pip install streamlit-chat
• frontend/src → (Vite build) → frontend/build
• frontend/build + streamlit_chat/*.py → (python sdist/wheel) → PyPI
• PyPI → pip install → user’s Streamlit app imports
• main.tsx → mounts root component
• stChat.tsx / Chat.tsx → container layout
• message.tsx → bubble renderer (user vs bot)
• avatar.tsx → avatar rendering
• CSS modules/files → styling
• Wrapper + embedded frontend: Python façade (message()) wraps a web UI delivered as static assets.
• Unidirectional props flow (likely): Python computes state (session_state), frontend renders.
• Consumer-owned state: Chat transcript is managed by the Streamlit app, not the library.
• Separation of concerns:
• Python: API ergonomics + Streamlit component registration
• Frontend: presentation + rendering modes (markdown/html/table)
Labels (be explicit)
• “streamlit_chat/__init__.py (Python API: message())”
• “Frontend: frontend/src/stChat.tsx, message.tsx”
• “Built assets: frontend/build/*”
• “props: {text, is_user, allow_html, is_table, key}”
• “renders DOM/CSS”
• “component protocol (Streamlit)”
• Browser (Streamlit UI + iframe)
• Streamlit server (Python app)
• streamlit_chat Python wrapper
• Component bridge
• streamlit_chat frontend renderer
• Data flow: message props → rendered chat bubbles
• TS source → vite build → static assets
• static assets + python package → PyPI → pip install → used by Streamlit apps
That pair will be the most accurate representation of this repo’s actual architecture and how it is used in practice.