# adt109119/chatpdf-linebot architecture

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

- Interactive diagram: https://gitdiagram.com/adt109119/chatpdf-linebot
- Repository: https://github.com/adt109119/chatpdf-linebot

## Overview

##### Project Components
- Frontend: Located under the “View” directory and built using Vue.js. It handles user interactions such as uploading files and interacting with the PDF Q&A functionality.
- Backend/API Server: Built with Python using FastAPI. The primary entry point is “main.py”. This layer handles the web API endpoints, processes requests from the front end, and connects with external services.
- Controllers: Found in the “Controller” directory, divided by channels:
- “liff” for handling LIFF web interactions.
- “line” for integrating with the Line Messaging API.
- Business Logic / Services: Under the “Service” directory. This layer encapsulates functionality such as interacting with LLMs, embedding text, and file upload management.
- Data Models: In the “Model” directory, where data structures for chat history, uploaded files, knowledge bases, settings, etc., are defined.
- Middleware & Configurations: Files like “Middleware.py”, environment variable definitions (.env.example), and Docker-related files show cross-cutting concerns and deployment configurations.
- Databases / File Storage: Directories such as “db” and “config” indicate where files (e.g., uploaded PDFs, vector database content) and configurations are stored.

##### Relationships and Interactions
- The Vue.js front end communicates with the FastAPI backend through REST API calls.
- The backend acts as the mediator – it routes requests via the controllers, applies middleware processing, and calls service functions to, for example, upload files, generate text embeddings, and drive the natural language QA.
- Controllers specifically handle different integrations; the “liff” controllers manage interactions from the LIFF web page, while “line” controllers manage webhook callbacks and messaging from Line.
- The Services layer encapsulates core functionalities (e.g., “llm” for language model requests, “embedding” for generating embeddings, “upload_file” for file management).
- Models serve as the structure for persisting user data, chat histories, uploaded files, and configurations.
- External integrations include the Line Bot SDK (for messaging) and third-party APIs provided by OpenAI or Groq for language model interactions.

##### Architectural Patterns and Technologies
- Separation of Concerns/MVC-like pattern: The clear division among Controllers (handling user requests or API callbacks), Models (data representation), and Services (core business logic).
- Docker and CI/CD: The presence of Dockerfile, .dockerignore, and GitHub workflows indicate a containerized deployment strategy.
- Environment-based Configuration: Use of .env files and dynamic environment variable loading ensures adaptable deployments.

##### Final Advice to the Principal Software Engineer
- That the integration points with external platforms (Line Messaging API, MIFF endpoints, and language model API providers) are clearly visible and properly annotated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        FE["Frontend (Vue.js LIFF Page)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["API Server (FastAPI)"]:::backend
        subgraph "Controllers"
            C_LIFF["LIFF Controllers"]:::controller
            C_Line["Line Controllers"]:::controller
        end
        SVC["Services (Business Logic)"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        DM["Data Models"]:::model
        CF["Config Files"]:::storage
        DB["Database Storage"]:::storage
    end

    %% External Services
    subgraph "External Services"
        EAI["External AI Providers (LangChain,LLM_APIs)"]:::external
        LP["Line Platform (Line Bot SDK)"]:::external
    end

    %% Deployment / Containerization
    DEP["Containerization (Docker)"]:::deployment

    %% User Node
    USER["User"]:::frontend

    %% Connections
    USER -->|"triggers"| FE
    FE -->|"API_call"| API
    API -->|"routes"| C_LIFF
    API -->|"routes"| C_Line
    C_LIFF -->|"invokes"| SVC
    C_Line -->|"invokes"| SVC
    SVC -->|"processes"| DM
    DM -->|"persist_to"| CF
    DM -->|"persist_to"| DB
    SVC -->|"calls"| EAI
    C_Line -->|"sends_reply"| LP
    DEP --- FE
    DEP --- API

    %% Click Events
    click FE "https://github.com/adt109119/chatpdf-linebot/tree/main/View/"
    click API "https://github.com/adt109119/chatpdf-linebot/blob/main/main.py"
    click C_LIFF "https://github.com/adt109119/chatpdf-linebot/tree/main/Controller/liff/"
    click C_Line "https://github.com/adt109119/chatpdf-linebot/tree/main/Controller/line/"
    click SVC "https://github.com/adt109119/chatpdf-linebot/tree/main/Service/"
    click DM "https://github.com/adt109119/chatpdf-linebot/tree/main/Model/"
    click CF "https://github.com/adt109119/chatpdf-linebot/tree/main/config/"
    click DB "https://github.com/adt109119/chatpdf-linebot/tree/main/db/"

    %% Styles
    classDef frontend fill:#aqua,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef controller fill:#ffc,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef model fill:#fcf,stroke:#333,stroke-width:2px;
    classDef storage fill:#fbb,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ddd,stroke:#333,stroke-width:2px;
```
