# wtlow003/investment-advisor-gpt architecture

> Architecture diagram of the GitHub repository wtlow003/investment-advisor-gpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wtlow003/investment-advisor-gpt
- Repository: https://github.com/wtlow003/investment-advisor-gpt

## Overview

##### Main Components

a) Client Layer:
- Chainlit UI (Port 8080)
- REST API endpoints (Port 8000)

b) Application Layer:
- FastAPI Server (src/api.py)
- Agent Controller (src/model/agents/controller.py)
- Conversation Management System

c) Core Components:
- LLM Integration (OpenAI)
- Knowledge Base (ChromaDB)
- External Services (Serper API for web search)

d) Storage Layer:
- Vector Database (ChromaDB)
- Conversation History Storage

##### Component Relationships

- User interactions through either UI or API
- Request processing through the application layer
- Agent's decision-making process
- Knowledge retrieval flow
- External API interactions

##### Specific Design Elements

- Blue rectangles for user-facing components (UI, API)
- Green rectangles for core processing components
- Yellow diamonds for external services
- Orange rectangles for agent components

##### Key Flows to Highlight

a) Main Conversation Flow:
**User Input → API/UI → Agent Controller → LLM → Response Generation → User**

b) Knowledge Retrieval Flow:
**Agent → Knowledge Base Query → ChromaDB → Retrieved Context → Response Generation**

c) Tool Usage Flow:
**Agent → Tool Selection (ProductSearch/WebSearch) → External APIs → Response Integration**

##### Important Subsystems to Detail

a) Agent System:
- Conversation Stage Analyzer
- Context Management
- Tool Selection Logic
- Response Generation

b) Knowledge Base:
- Document Storage
- Vector Embeddings
- Retrieval System

##### Technical Details

- Docker container boundaries
- API endpoints
- Database connections
- Configuration management
- Memory management system

##### Architectural Patterns to Emphasize

- Microservices architecture (Docker containers)
- Event-driven conversation flow
- Tool-augmented agent pattern
- Vector-based knowledge retrieval

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI[Chainlit UI\nPort 8080]
        API[REST API\nPort 8000]
    end

    subgraph AppLayer
        Server["FastAPI Server"]
        AgentCtrl["Agent Controller"]
        ConvMgmt["Conversation Management"]
        Parser["Agent Parser"]
        Tools["External Tools Integration"]
        Prompts["System Prompts"]
        Templates["Tool & Chain Templates"]
    end

    subgraph External
        LLM["OpenAI LLM"]
        WebSearch["Serper API"]
    end

    subgraph Storage
        VectorDB[(ChromaDB\nVector Store)]
        ConvHistory[(Conversation\nHistory)]
    end

    UI --> Server
    API --> Server
    Server --> AgentCtrl
    AgentCtrl --> Parser
    AgentCtrl --> ConvMgmt
    AgentCtrl --> Tools
    Tools --> WebSearch
    AgentCtrl --> LLM
    ConvMgmt --> VectorDB
    ConvMgmt --> ConvHistory
    Parser --> Prompts
    Tools --> Templates

    %% Click Events
    click UI "https://github.com/wtlow003/investment-advisor-gpt/blob/main/.chainlit/config.toml"
    click Server "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/api.py"
    click AgentCtrl "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/model/agents/controller.py"
    click Parser "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/model/agents/parser.py"
    click ConvMgmt "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/model/chains.py"
    click Tools "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/model/tools.py"
    click Templates "https://github.com/wtlow003/investment-advisor-gpt/tree/main/src/model/templates"
    click Prompts "https://github.com/wtlow003/investment-advisor-gpt/blob/main/src/model/prompts.py"
    click VectorDB "https://github.com/wtlow003/investment-advisor-gpt/blob/main/db/chroma.sqlite3"
    click ConvHistory "https://github.com/wtlow003/investment-advisor-gpt/blob/main/.chainlit/.langchain.db"

    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef app fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white

    class UI,API client
    class Server,AgentCtrl,ConvMgmt,Parser,Tools,Prompts,Templates app
    class LLM,WebSearch external
    class VectorDB,ConvHistory storage
```
