How brucechou1983/chainlit_langgraph works
Project type and purpose
• This is a full-stack conversational AI application combining:
• Chainlit (frontend + server framework for chat UI)
• LangGraph (workflow/state-graph engine)
• PostgreSQL (relational database)
• MinIO (object storage for file uploads/artifacts)
• Multiple external LLM providers (OpenAI, Anthropic, Ollama, etc.)
• Purpose: Rapidly build and deploy production-ready AI chat agents with customizable workflows.
File structure
• Top-level files:
• Dockerfile / docker-compose.yml: containerized deployment
• app.py: main Chainlit server entrypoint
• alembic/: database migration scripts
• .chainlit/: Chainlit configuration and translations
• public/: static assets (logo, screenshots)
• chat_workflow/: core Python package
– auth.py, storage_client.py, state_serializer.py, module_discovery.py
– llm/: provider factory, capability mapping, individual provider adapters
– prompts/: prompt templates per model
– workflows/: concrete workflow implementations + factory
– tools/: helper modules (search, time)
– tests/: unit tests for LLM and workflow logic
• Environment: .env.example for API keys, DB & MinIO volumes, optional OAuth / search key.
README for additional insights
• Describes architecture at a high level: Chainlit + LangGraph integration
• Lists supported LLMs, prebuilt workflows (simple chat, multimodal, resume optimizer, lean canvas)
• Walkthrough for custom workflow creation via subclassing BaseWorkflow and BaseState.
Main components
a. Chainlit Server
• app.py initializes Chainlit HTTP server
• Chains: user ↔ WebSocket/HTTP ↔ Chainlit UI
b. Workflow Engine
• chat_workflow/module_discovery + workflow_factory
• chat_workflow/workflows (StateGraph nodes & edges)
• chat_workflow/state_serializer (persist workflow state)
c. LLM Layer
• chat_workflow/llm/factory routes calls to provider adapters
• chat_workflow/llm/providers/* (OpenAI, Anthropic, Ollama, Google, Groq, XAI)
d. Tools & Prompts
• chat_workflow/tools (search, time)
• chat_workflow/prompts (model-specific prompt templates)
e. Persistence
• PostgreSQL (via SQLAlchemy + Alembic migrations)
• MinIO object storage (for uploads, resume PDFs, images)
f. External Services
• LLM provider APIs
• Optional OAuth (Google), optional Tavily search API
g. Infrastructure
• Docker Compose orchestrates: Chainlit container, Postgres container, MinIO container
Relationships & interactions
1. User ↔ Chainlit UI (browser)
2. Chainlit Server (app.py) receives events → dispatches to Workflow Engine
3. Workflow Engine invokes StateGraph nodes → may call LLM Layer or Tools
4. LLM Layer factory selects provider → external API call → LLM response
5. Tools layer (search/time) makes HTTP calls to search API or returns system time
6. StateSerializer persists intermediate state to Postgres (and/or MinIO for artifacts)
7. Final response flows back → Chainlit UI → user
Architectural patterns & design principles
• Modular separation: workflows, prompts, llm providers, tools, storage
• Factory pattern: llm factory & workflow factory
• State graph pattern: workflows defined as LangGraph StateGraph nodes/edges
• Dependency injection via BaseWorkflow / BaseState inheritance
• Containerization for reproducible environments
Relevant technologies, frameworks & libraries
• Python 3.10+, FastAPI under the hood (Chainlit)
• Chainlit 1.3.1, LangGraph 0.2.45
• SQLAlchemy + Alembic for DB migrations
• MinIO client SDK
• Docker, Docker Compose
• External LLM SDKs or HTTP clients
Summary of steps for the principal software engineer
3. With technology names and callouts for key patterns (Factory, StateGraph)
5. Labels are clear and directionality of data flow is unambiguous