# zaibys/cloudprinter architecture

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

- Interactive diagram: https://gitdiagram.com/zaibys/cloudprinter
- Repository: https://github.com/zaibys/cloudprinter

## Overview

##### Project Type and Purpose
- This is a full-stack web application implementing an Order Management System (OMS) augmented by an AI-driven multi-agent orchestration layer (AG2, formerly AutoGen).
- Purpose: Provide a real-time chat interface where human operators and specialized AI agents collaborate to process orders, query product catalogs, and interact with external services (CloudPrinter, OpenAI, LangSmith).

##### File Structure
- Top-level files:
- .env.template / python-version / pyproject.toml – environment and dependency config
- README.md – project overview and architecture summary
- uv.lock – lockfile for the UV package manager
- src/ directory (core application):
- app.py – Flask server setup, HTTP routes, Socket.IO real-time endpoint
- functions.py – wrappers for CloudPrinter API calls (list products, order quote, etc.)
- prompts.py – definitions of agent prompts and conversational logic
- logger.py – centralized logging config
- templates/index.html – web UI (chat interface)
- static/ – image assets (user.png, agent.png) for UI avatars

##### README for Additional Insights
- Technology stack: Python 3.12+, Flask, Socket.IO, AG2 multi-agent framework, OpenAI API, CloudPrinter API, LangSmith tracing
- Agents: ConversableAgent instances with custom speaker selection logic (human, assistant_agent, executor_agent)
- Real-time update workaround: customized `_print_received_message` integrated via Socket.IO

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        Browser["Client Browser / Web UI"]:::frontend
        StaticAssets["Static Assets (UI Avatars)"]:::frontend
        SocketClient["Socket.IO Client"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        FlaskServer["Flask Server\n(HTTP routes & Socket.IO)"]:::internal
        AgentOrch["AG2 Agent Orchestrator"]:::internal
        PromptEngine["Prompt Engine\n(prompts.py)"]:::internal
        Functions["CloudPrinter API Wrapper\n(functions.py)"]:::internal
        Logger["Centralized Logger"]:::config
        ConfigStore["Configuration Store\n(.env.template)"]:::config
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
        CloudPrinter["CloudPrinter API"]:::external
        LangSmith["LangSmith Tracing"]:::external
    end

    %% Interactions
    Browser -->|"HTTP GET index.html"| FlaskServer
    Browser -->|Socket.IO event| SocketClient
    SocketClient -.->|WebSocket| FlaskServer
    FlaskServer -->|calls| AgentOrch
    AgentOrch -->|uses| PromptEngine
    AgentOrch -->|calls| Functions
    PromptEngine -->|LLM requests| OpenAI
    Functions -->|API calls| CloudPrinter
    FlaskServer -->|reports traces| LangSmith
    FlaskServer -->|logs events| Logger
    AgentOrch -->|logs agent events| Logger
    ConfigStore -->|env vars| FlaskServer
    ConfigStore -->|env vars| PromptEngine
    ConfigStore -->|env vars| Functions

    %% Click Events
    click Browser "https://github.com/zaibys/cloudprinter/blob/dev/src/templates/index.html"
    click StaticAssets "https://github.com/zaibys/cloudprinter/tree/dev/src/static/"
    click FlaskServer "https://github.com/zaibys/cloudprinter/blob/dev/src/app.py"
    click AgentOrch "https://github.com/zaibys/cloudprinter/blob/dev/src/app.py"
    click PromptEngine "https://github.com/zaibys/cloudprinter/blob/dev/src/prompts.py"
    click Functions "https://github.com/zaibys/cloudprinter/blob/dev/src/functions.py"
    click LangSmith "https://github.com/zaibys/cloudprinter/blob/dev/src/app.py"
    click Logger "https://github.com/zaibys/cloudprinter/blob/dev/src/logger.py"
    click ConfigStore "https://github.com/zaibys/cloudprinter/blob/dev/.env.template"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef internal fill:#B3FFB3,stroke:#2e7d32,color:#2e7d32;
    classDef external fill:#CCFFCC,stroke:#388e3c,color:#388e3c;
    classDef config fill:#FFF2CC,stroke:#fbc02d,color:#f57f17;
```
