# brucechou1983/chainlit_langgraph architecture

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

- Interactive diagram: https://gitdiagram.com/brucechou1983/chainlit_langgraph
- Repository: https://github.com/brucechou1983/chainlit_langgraph

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface
    subgraph "User Interface"
        direction TB
        User["User (Browser)"]:::external
        ChainlitUI["Chainlit UI"]:::internal
    end

    %% Chainlit Server
    subgraph "Chainlit Server"
        direction TB
        Server["Chainlit Server (app.py)"]:::internal
        CLConfig[".chainlit/config.toml"]:::internal
        CLTrans[".chainlit/translations/"]:::internal
    end

    %% Workflow Engine
    subgraph "Workflow Engine"
        direction TB
        ModuleDiscovery["ModuleDiscovery"]:::internal
        StateSerializer["StateSerializer"]:::internal
        BaseWorkflow["BaseWorkflow"]:::internal
        WorkflowFactory["WorkflowFactory"]:::internal
        SimpleChat["SimpleChat Workflow"]:::internal
        MultimodalChat["MultimodalChat Workflow"]:::internal
        ResumeOptimizer["ResumeOptimizer Workflow"]:::internal
        LeanCanvas["LeanCanvasChat Workflow"]:::internal
    end

    %% LLM Layer
    subgraph "LLM Layer"
        direction TB
        LLMFactory["LLM Factory"]:::internal
        Capabilities["Capabilities Mapping"]:::internal
        subgraph "Providers"
            direction TB
            OpenAI["OpenAI Provider"]:::external
            Anthropic["Anthropic Provider"]:::external
            Ollama["Ollama Provider"]:::external
            Google["Google Provider"]:::external
            Groq["Groq Provider"]:::external
            XAI["XAI Provider"]:::external
        end
    end

    %% Tools & Prompts
    subgraph "Tools & Prompts"
        direction TB
        Prompts["ThinkingClaude Prompt"]:::internal
        SearchTool["Search Tool"]:::internal
        TimeTool["Time Tool"]:::internal
    end

    %% Persistence
    subgraph "Persistence"
        direction TB
        Postgres["PostgreSQL"]:::datastore
        MinIO["MinIO Object Storage"]:::datastore
        AlembicDir["alembic/"]:::internal
        AlembicIni["alembic.ini"]:::internal
        StorageClient["StorageClient"]:::internal
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLMAPIs["LLM Provider APIs"]:::external
        SearchAPI["Tavily Search API (optional)"]:::external
        OAuth["OAuth (Google) (optional)"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure & Deployment"
        direction TB
        DockerfileNode["Dockerfile"]:::internal
        Compose["docker-compose.yml"]:::internal
        WaitForIt["wait-for-it.sh"]:::internal
        EnvExample[".env.example"]:::internal
    end

    %% Connections
    User -->|interacts via| ChainlitUI
    ChainlitUI -->|sends events| Server
    Server -->|loads config| CLConfig
    Server -->|loads translations| CLTrans
    Server -->|dispatches events| ModuleDiscovery
    ModuleDiscovery -->|discovers workflows| WorkflowFactory
    WorkflowFactory -->|instantiates BaseWorkflow| BaseWorkflow
    BaseWorkflow -->|defines StateGraph| SimpleChat
    BaseWorkflow --> MultimodalChat
    BaseWorkflow --> ResumeOptimizer
    BaseWorkflow --> LeanCanvas
    SimpleChat -->|serialize state| StateSerializer
    MultimodalChat --> StateSerializer
    ResumeOptimizer --> StateSerializer
    LeanCanvas --> StateSerializer
    StateSerializer -->|persists state| Postgres
    StateSerializer -->|stores artifacts| MinIO

    BaseWorkflow -->|calls prompts| Prompts
    BaseWorkflow -->|calls tools| SearchTool
    BaseWorkflow --> TimeTool

    BaseWorkflow -->|requests LLM| LLMFactory
    LLMFactory --> Capabilities
    Capabilities --> OpenAI
    Capabilities --> Anthropic
    Capabilities --> Ollama
    Capabilities --> Google
    Capabilities --> Groq
    Capabilities --> XAI
    OpenAI -->|calls| LLMAPIs
    Anthropic -->|calls| LLMAPIs
    Ollama -->|calls| LLMAPIs
    Google -->|calls| LLMAPIs
    Groq -->|calls| LLMAPIs
    XAI -->|calls| LLMAPIs

    SearchTool -->|calls| SearchAPI
    OAuth -.->|optional auth| Server
    SearchAPI -.->|optional| BaseWorkflow

    Infrastructure & Deployment -->|orchestrates| Server
    Infrastructure & Deployment --> Postgres
    Infrastructure & Deployment --> MinIO

    %% Click Events
    click Server "https://github.com/brucechou1983/chainlit_langgraph/blob/main/app.py"
    click CLConfig "https://github.com/brucechou1983/chainlit_langgraph/blob/main/.chainlit/config.toml"
    click CLTrans "https://github.com/brucechou1983/chainlit_langgraph/tree/main/.chainlit/translations/"
    click ModuleDiscovery "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/module_discovery.py"
    click StateSerializer "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/state_serializer.py"
    click BaseWorkflow "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/base.py"
    click WorkflowFactory "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/workflow_factory.py"
    click SimpleChat "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/simple_chat.py"
    click MultimodalChat "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/multimodal_chat.py"
    click ResumeOptimizer "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/resume_optimizer.py"
    click LeanCanvas "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/workflows/lean_canvas_chat.py"
    click LLMFactory "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/factory.py"
    click Capabilities "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/capabilities.py"
    click OpenAI "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/openai.py"
    click Anthropic "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/anthropic.py"
    click Ollama "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/ollama.py"
    click Google "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/google.py"
    click Groq "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/groq.py"
    click XAI "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/llm/providers/xai.py"
    click Prompts "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/prompts/thinking_claude.py"
    click SearchTool "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/tools/search.py"
    click TimeTool "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/tools/time.py"
    click AlembicDir "https://github.com/brucechou1983/chainlit_langgraph/tree/main/alembic/"
    click AlembicIni "https://github.com/brucechou1983/chainlit_langgraph/blob/main/alembic.ini"
    click StorageClient "https://github.com/brucechou1983/chainlit_langgraph/blob/main/chat_workflow/storage_client.py"
    click DockerfileNode "https://github.com/brucechou1983/chainlit_langgraph/tree/main/Dockerfile"
    click Compose "https://github.com/brucechou1983/chainlit_langgraph/blob/main/docker-compose.yml"
    click WaitForIt "https://github.com/brucechou1983/chainlit_langgraph/blob/main/wait-for-it.sh"
    click EnvExample "https://github.com/brucechou1983/chainlit_langgraph/blob/main/.env.example"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef datastore fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef optional stroke-dasharray: 5 5,fill:#FFEFD5,stroke:#333,stroke-width:1px
```
