# ssrhy/langchaintest architecture

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

- Interactive diagram: https://gitdiagram.com/ssrhy/langchaintest
- Repository: https://github.com/ssrhy/langchaintest

## Overview

##### Project Overview
- This is a full-stack web application named “3D Scene Generator.”
- Its main purpose is to take natural language scene descriptions and generate interactive 3D scenes using an AI-powered, multi-agent system.
- The backend is built in Python using FastAPI and LangChain (with GPT-4) for AI tasks, while the frontend uses HTML/CSS/JavaScript with Three.js for 3D rendering.

##### Main Components
a. Frontend
- Web UI: Represented by static files (index.html, main.js, styles.css)
- Dynamic 3D Renderer: Uses Three.js for rendering the scene and a sandbox component to safely execute generated code.
b. Backend
- FastAPI Server: The core server script is in main.py.
- AI Agents: Represent the multi-agent system that includes planning, code generation, and code review. Configuration and template files in the .cursor/rules directory support these agents.
- Supporting Tools: tools.py and any helper scripts.
c. Communication Channels
- REST Endpoints: For generating 3D scene code (e.g., POST request to /generate).
- WebSockets (as mentioned in the README for real-time updates).
d. Environment and Configuration
- .env for environment variables (such as OpenAI API key)
- requirements.txt for Python dependency management

##### Relationships and Interactions
- User Interaction: A user enters a natural language prompt via the frontend web interface.
- Data Flow:
1. The frontend sends the prompt to the FastAPI backend using a REST API call.
2. The backend passes the prompt to one or more AI agents (configured via the .cursor rules) that use LangChain to generate Three.js code.
3. The backend processes the generated code, performing any safety checks.
4. The safe code is returned to the frontend.
5. The frontend executes the code within a secure sandbox to render the 3D scene.

##### Architectural Patterns and Technologies
- Full-stack separation: Clearly distinguish the frontend (visual rendering and user interaction) from the backend (AI and REST API logic).
- Security Layer: Illustrate the safe code execution/sandbox environment where generated code is run, emphasizing the security aspect.
- Technologies to note:
- Python, FastAPI, LangChain, GPT-4 (backend/AI)
- JavaScript, Three.js (frontend/3D rendering)
- WebSockets (real-time updates)
- REST APIs (communication)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global User Node
    U["User (Browser)"] 

    %% Frontend Subgraph
    subgraph "Frontend"
        FWUI["Frontend Web UI"]
        TSR["Dynamic 3D Renderer (Three.js)"]
        SS["Security Sandbox"]
    end

    %% Backend Subgraph
    subgraph "Backend"
        FASTAPI["FastAPI Server"]
        %% AI Agents Subgraph inside Backend
        subgraph "AI Agents"
            Agent["Agent"]
            DAgent["Design Agent"]
        end
        ST["Supporting Tools"]
        EV["Environment Variables"]
        PD["Python Dependencies"]
    end

    %% Data Flow
    U -->|"enter_prompt"| FWUI
    FWUI -->|"POST/generate"| FASTAPI
    FASTAPI -->|"process"| Agent
    FASTAPI -->|"process"| DAgent
    Agent -->|"return_code"| FASTAPI
    DAgent -->|"return_code"| FASTAPI
    FASTAPI -->|"safety_check"| SS
    SS -->|"render_scene"| TSR
    FASTAPI -->|"WS_Update"| FWUI
    EV --> FASTAPI
    PD --> FASTAPI
    ST --> FASTAPI

    %% Click Events
    click FWUI "https://github.com/ssrhy/langchaintest/blob/main/static/index.html"
    click FWUI "https://github.com/ssrhy/langchaintest/blob/main/static/main.js"
    click FWUI "https://github.com/ssrhy/langchaintest/blob/main/static/styles.css"
    click TSR "https://github.com/ssrhy/langchaintest/blob/main/static/main.js"
    click FASTAPI "https://github.com/ssrhy/langchaintest/blob/main/main.py"
    click Agent "https://github.com/ssrhy/langchaintest/blob/main/.cursor/rules/agent.mdc"
    click DAgent "https://github.com/ssrhy/langchaintest/blob/main/.cursor/rules/design.mdc"
    click ST "https://github.com/ssrhy/langchaintest/blob/main/tools.py"
    click EV "https://github.com/ssrhy/langchaintest/blob/main/.env"
    click PD "https://github.com/ssrhy/langchaintest/blob/main/requirements.txt"

    %% Styles
    class U default;
    class FWUI,TSR,SS frontend;
    class FASTAPI,EV,PD,ST backend;
    class Agent,DAgent agent;
    
    classDef frontend fill:#CDEBFF,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFE4C4,stroke:#333,stroke-width:2px;
    classDef agent fill:#CEF9CE,stroke:#333,stroke-width:2px;
    classDef misc fill:#FFDAB9,stroke:#333,stroke-width:2px;
```
