# hoangvusnape/automation-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/hoangvusnape/automation-chatbot
- Repository: https://github.com/hoangvusnape/automation-chatbot

## Overview

##### Main Components
- Frontend Application – Representing the “chatbot-frontend” folder. This includes React components (e.g., ChatBox, ChatMessage, ChatPage, and various service components such as the chat API integration in chatService.js).
- API Layer: Located under “app/api/v1/chat/routes.py” which handles HTTP requests/responses.
- Core AI Module: Under “app/core/ai” (ai_service.py, tools.py) which likely processes the chatbot's AI logic.
- Database Layer (Data Persistence Services): Under “app/database” which includes models, chat_history_service, order_service, product_service, wallet_service, and the seed script for populating the database.
- Main Application Entrypoint: This is “main.py” which ties the API routes and other services together.
- Infrastructure / Deployment Support:
- Docker Compose File (“docker-compose.yml”) helps orchestrate the backend (and possibly a database container).
- Environment Config Files (“.env.example”) for both backend and frontend, which define run-time configuration.

##### Relationships and Interactions
- The Backend API layer forwards requests to the Core AI module for processing, and interacts with the Database Layer to store/retrieve data (chat history, orders, products, wallet information).
- The Backend’s “main.py” acts as the primary entry, initializing the routing, middleware, and integrating different modules.
- Docker Compose coordinates the backend (and possibly associated service containers) during deployment.

##### Architectural Patterns & Design Principles
- A clear separation of concerns is used to split the project into the Frontend and Backend layers.
- The backend is further structured in a modular fashion. The API layer, business logic (within the Core AI module), and the database interface are organized into separate directories, hinting at a layered or hexagonal-like architecture.
- The use of environment variable files and Docker Compose indicates a focus on reproducible environments and containerized deployment.

##### Relevant Technologies, Frameworks, and Libraries
- Frontend: React (as indicated by JSX files and package.json).
- Backend: Python (with Uvicorn to run a server, and likely FastAPI given the structure and use of “routes”).
- Docker & Docker Compose for containerization and orchestration.
- Database: While the specific database isn’t mentioned, the various service files suggest a relational or document-based backend.
- Anaconda for Python environment management on the backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React)"
        FE_Client["Client (React UI)"]:::frontend
        FE_ChatBox["ChatBox (Component)"]:::frontend
        FE_ChatMessage["ChatMessage (Component)"]:::frontend
        FE_ChatPage["ChatPage (Page)"]:::frontend
        FE_ChatAPI["Chat API Integration"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (FastAPI/Python)"
        BE_Main["Main Application Entrypoint"]:::backend
        subgraph "API Layer"
            BE_API["Chat API Routes"]:::backend
        end
        subgraph "Core AI Module"
            BE_AIService["AI Service"]:::backend
            BE_AIUtils["AI Utilities"]:::backend
        end
        subgraph "Database Layer"
            BE_ChatHistory["Chat History Service"]:::database
            BE_Order["Order Service"]:::database
            BE_Product["Product Service"]:::database
            BE_Wallet["Wallet Service"]:::database
            BE_Seed["Data Seeding Script"]:::database
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        INF_Docker["Docker Compose"]:::infrastructure
        INF_BackendEnv["Backend .env Example"]:::infrastructure
        INF_FrontendEnv["Frontend .env Example"]:::infrastructure
    end

    %% Connections between Frontend and Backend
    FE_Client -->|"uses"| FE_ChatAPI
    FE_ChatAPI -->|"HTTP_Request"| BE_API

    %% Backend internal connections
    BE_Main -->|"initializes"| BE_API
    BE_API -->|"forwards"| BE_AIService
    BE_AIService -->|"calls"| BE_AIUtils
    BE_AIService -->|"stores_to"| BE_ChatHistory
    BE_AIService -->|"stores_to"| BE_Order
    BE_AIService -->|"stores_to"| BE_Product
    BE_AIService -->|"stores_to"| BE_Wallet

    %% Infrastructure connections
    INF_Docker -->|"orchestrates"| BE_Main
    INF_BackendEnv -->|"configures"| BE_Main
    INF_FrontendEnv -->|"configures"| FE_Client

    %% Click Events for Frontend
    click FE_Client "https://github.com/hoangvusnape/automation-chatbot/tree/main/chatbot-frontend"
    click FE_ChatBox "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-frontend/src/components/chat/ChatBox.jsx"
    click FE_ChatMessage "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-frontend/src/components/chat/ChatMessage.jsx"
    click FE_ChatPage "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-frontend/src/pages/ChatPage.jsx"
    click FE_ChatAPI "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-frontend/src/services/chatService.js"

    %% Click Events for Backend
    click BE_API "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/api/v1/chat/routes.py"
    click BE_AIService "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/core/ai/ai_service.py"
    click BE_AIUtils "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/core/ai/tools.py"
    click BE_ChatHistory "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/database/chat_history_service.py"
    click BE_Order "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/database/order_service.py"
    click BE_Product "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/database/product_service.py"
    click BE_Wallet "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/database/wallet_service.py"
    click BE_Seed "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/app/database/seed.py"
    click BE_Main "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-backend/main.py"

    %% Click Events for Infrastructure
    click INF_Docker "https://github.com/hoangvusnape/automation-chatbot/blob/main/docker-compose.yml"
    click INF_BackendEnv "https://github.com/hoangvusnape/automation-chatbot/blob/main/.env.example"
    click INF_FrontendEnv "https://github.com/hoangvusnape/automation-chatbot/blob/main/chatbot-frontend/.env.example"

    %% Styles
    classDef frontend fill:#cce,stroke:#333,stroke-width:2px;
    classDef backend fill:#fcc,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ff9,stroke:#333,stroke-width:2px;
```
