# melih-unsal/demogpt architecture

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

- Interactive diagram: https://gitdiagram.com/melih-unsal/demogpt
- Repository: https://github.com/melih-unsal/demogpt

## Overview

##### Project Type and Purpose
- DemoGPT is an LLM-based agent library that automates the generation of LangChain pipelines and interactive Streamlit applications. Its primary workflow includes planning, task creation, code generation (in snippets), and assembling the final Streamlit app.
- The README details the LLM interactions, planning stages, and integration with external agents (e.g., planned Gorilla and other API tools), giving us clues about a modular, pipeline-driven architecture.

##### Analyzing the File Structure
- There are two main top-level packages:
- “demogpt”: Contains core components such as the application entry point (app.py), chains, prompts, self-refinement modules, and utilities. It directs the pipeline workflow—from initial planning and task creation to assembling and testing the generated code.
- “demogpt_agenthub”: Provides an ecosystem for agents, APIs, LLM wrappers, tools, and specialized prompts relating to agents. This module supports tool integration and external service calls.
- The “chains” directory under demogpt, with various sub-modules for prompts (e.g., planning, feedback, task listing, self-refinement), emphasizes an architecture based on pipelines (or chain-of-tasks) and modular prompt generation.
- Additional directories like “tests”, “docs”, and “assets” confirm good separation of concerns (source code, testing, documentation, and static assets).

##### Key System Components
- User Interfaces:
- CLI (via demogpt/cli.py) and a Web interface through Streamlit (demogpt/app.py).
- Core Pipeline Management:
- Overall orchestration is handled by the “demogpt” package, which sequences the following stages:
- Planning: Generating a high-level plan from user instructions.
- Task Creation: Breaking down the plan into individual tasks.
- Code Snippet Generation: Converting tasks into code fragments.
- Final Assembly: Combining snippets into a complete finished Streamlit application.
- Chains & Prompts:
- The “chains” folder contains numerous prompt templates and refinement strategies to direct model responses. These include both initial draft generation and self-refinement stages, which are essential for iterative improvement.
- Agent and Tool Integration:
- The agenthub module encapsulates agents, tool calling mechanisms, and LLM wrappers—all aimed at extending DemoGPT’s capabilities with external integrations.
- Planned Enhancements:
- The README and TODO list indicate upcoming database integration (for caching or example retrieval) and API call enhancements through Gorilla and Rapid API modules.

##### Architectural Patterns and Design Principles
- Modular Pipeline – Each stage (plan, task, snippet, final assembly) is encapsulated in its own module, demonstrating separation of concerns.
- Microservice-like Separation – The dual structure (demogpt vs. demogpt_agenthub) allows independent evolution of the core pipeline and external agent tools.
- Extensibility – The use of prompt chains and a modular design enables adding new models or external APIs with minimal coupling.
- Iterative and Self-Refining – A built-in self-refinement strategy (e.g., via demogpt/chains/prompts/self_refinement) underlines an elegant loop for quality improvement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        CLI["CLI Interface"]:::ui
        Streamlit["Streamlit App"]:::ui
    end

    %% Core Pipeline Engine
    subgraph "Core Pipeline Engine"
        Input["User Input"]:::core
        Planning["Planning Module"]:::core
        Task["Task Creation Module"]:::core
        CodeGen["Code Snippet Generation"]:::core
        Assembly["Final Assembly"]:::core
    end

    %% Chains & Prompts Modules
    subgraph "Chains & Prompts"
        CP1["Planning Prompts"]:::chains
        CP2["Task List Prompts"]:::chains
        CP3["Self-Refinement Engine"]:::chains
    end

    %% AgentHub Integration Layer
    subgraph "AgentHub Integration"
        AHub["AgentHub"]:::agent
        Agent["Agents"]:::agent
        LLM["LLM Wrappers"]:::agent
        PromptHub["Agent Prompts"]:::agent
        Tools["Tools Integration"]:::agent
        ExternalAPIs["External API & RAG"]:::agent
    end

    %% External Dependencies
    subgraph "External Dependencies"
        LLM_Ext["OpenAI_GPT-3.5-turbo_and_LangChain"]:::external
    end

    %% Connections from UI to Core Pipeline
    CLI -->|"starts"| Input
    Streamlit -->|"starts"| Input

    %% Core Pipeline Flow Sequence
    Input -->|"triggers"| Planning
    Planning -->|"invokes"| CP1
    CP1 -->|"refines plan"| Planning
    Planning -->|"delegates to"| Task
    Task -->|"uses"| CP2
    Task -->|"executes"| CodeGen
    CodeGen -->|"assembles"| Assembly

    %% Channels to AgentHub Integration
    Planning -->|"integrates"| AHub
    Task -->|"integrates"| AHub
    CodeGen -->|"integrates"| AHub

    %% AgentHub Internal Flow
    AHub --> Agent
    AHub --> LLM
    AHub --> PromptHub
    AHub --> Tools
    AHub --> ExternalAPIs

    %% External LLM and LangChain calls
    Planning -->|"LLM_call"| LLM_Ext
    Task -->|"LLM_call"| LLM_Ext
    CodeGen -->|"LLM_call"| LLM_Ext

    %% Click Events
    click CLI "https://github.com/melih-unsal/demogpt/blob/main/demogpt/cli.py"
    click Streamlit "https://github.com/melih-unsal/demogpt/blob/main/demogpt/app.py"
    click Planning "https://github.com/melih-unsal/demogpt/blob/main/demogpt/chains/prompts/plan.py"
    click Task "https://github.com/melih-unsal/demogpt/tree/main/demogpt/chains/prompts/task_list"
    click CodeGen "https://github.com/melih-unsal/demogpt/blob/main/demogpt/chains/chains.py"
    click CP3 "https://github.com/melih-unsal/demogpt/tree/main/demogpt/chains/prompts/self_refinement"
    click Agent "https://github.com/melih-unsal/demogpt/tree/main/demogpt_agenthub/agents"
    click LLM "https://github.com/melih-unsal/demogpt/tree/main/demogpt_agenthub/llms"
    click PromptHub "https://github.com/melih-unsal/demogpt/tree/main/demogpt_agenthub/prompts"
    click Tools "https://github.com/melih-unsal/demogpt/tree/main/demogpt_agenthub/tools"
    click ExternalAPIs "https://github.com/melih-unsal/demogpt/tree/main/demogpt_agenthub/apis"

    %% Style Classes
    classDef ui fill:#ffe0f0,stroke:#d9007e,stroke-width:2px;
    classDef core fill:#e0f7ff,stroke:#0066cc,stroke-width:2px;
    classDef chains fill:#e0ffe0,stroke:#008000,stroke-width:2px;
    classDef agent fill:#fff0d9,stroke:#cc6600,stroke-width:2px;
    classDef external fill:#e0ffff,stroke:#008080,stroke-width:2px;
```
