# wannaflyhigh/latia112-1 architecture

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

- Interactive diagram: https://gitdiagram.com/wannaflyhigh/latia112-1
- Repository: https://github.com/wannaflyhigh/latia112-1

## Overview

##### Project type and purpose
- This repository is a student’s LATIA112-1 course workspace. The “final” directory contains the actual deliverable: a Node.js–based LINE chatbot that uses OCR and the OpenAI API to process messages and image uploads, looks up or generates responses (sometimes via CSV data), and returns results to users on LINE.

##### File structure (focus on the “final” folder)
- Top-level of “final”
- app.js         – Main Express/Koa (or similar) server entrypoint, sets up HTTP/webhook.
- linebot.js     – Module that handles incoming LINE events (text, image) and routes to services.
- ocr.js         – Wrappers around Tesseract OCR using .traineddata files (chi_tra.traineddata, eng.traineddata).
- openai.js      – Wrapper for OpenAI API requests (GPT-based prompts).
- readCsv.js     – Utility to parse CSV files and produce JSON or lookup results (e.g., parsed.json).
- parsed.json    – Cached or pre-computed data extracted from CSVs.
- data_collect/  – Python scripts and notebooks (sele.py, test.ipynb) for scraping or assembling CSV data (源数据处理).
- package.json   – Defines Node.js dependencies (line-bot-sdk, tesseract.js, openai node client, etc.) and scripts.
- linebot.js     – Webhook handler specific to LINE Messaging API.
- ocr-traineddata files – Language packs for OCR.

##### README for additional insights
- The top-level README simply catalogs homework and the final project.
- The “final/README.md” (if present) likely describes usage, environment variables (LINE channel token, OpenAI key), and start scripts.

##### Elements
- Clear labels: “LINE Messaging Platform,” “Node.js Server,” “OCR Module,” “OpenAI Module,” “CSV Data Store,” “Data Collection Scripts.”
– Core server modules (messaging, OCR, NLP, data access) in another

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User(["User"]):::user
    LINE(["LINE Messaging Platform"]):::external

    User -->|send message/image| LINE
    LINE -->|webhook event| App

    %% Core Server
    subgraph "Node.js Server" 
        direction TB
        App(["app.js"]):::server
        Linebot(["linebot.js"]):::server
        OCR(["ocr.js"]):::service
        OpenAI(["openai.js"]):::service
        ReadCsv(["readCsv.js"]):::service
        Package(["package.json"]):::config
        Gitignore([".gitignore"]):::config
        Readme(["README.md"]):::config
        Env(["Environment Variables"]):::config

        App -->|route event| Linebot
        Linebot -->|image event| OCR
        Linebot -->|text event| OpenAI
        Linebot -->|text lookup| ReadCsv
        OCR -->|extracted text| Linebot
        OpenAI -->|AI response| Linebot
        ReadCsv -->|lookup result| Linebot
        Linebot -->|reply API call| LINE
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        Parsed(["parsed.json"]):::datastore
        CSVdata(["均一高中生物.csv"]):::datastore
        Chi(["chi_tra.traineddata"]):::datastore
        Eng(["eng.traineddata"]):::datastore
    end

    ReadCsv -->|uses CSV| CSVdata
    ReadCsv -->|reads JSON| Parsed
    OCR -->|uses traineddata| Chi
    OCR -->|uses traineddata| Eng

    %% Offline Data Collection Pipeline
    subgraph "Data Collection Pipeline (Offline)"
        direction TB
        Sele(["sele.py"]):::pipeline
        TestNotebook(["test.ipynb"]):::pipeline
        CSVdata
    end
    Sele --> TestNotebook
    TestNotebook --> CSVdata

    %% External Services
    OpenAIAPI(["OpenAI API"]):::external
    LINESDK(["LINE Reply API"]):::external

    OpenAI -->|HTTP request| OpenAIAPI
    Linebot -->|SDK/API call| LINESDK

    %% Click Events
    click App "https://github.com/wannaflyhigh/latia112-1/blob/main/final/app.js"
    click Linebot "https://github.com/wannaflyhigh/latia112-1/blob/main/final/linebot.js"
    click OCR "https://github.com/wannaflyhigh/latia112-1/blob/main/final/ocr.js"
    click OpenAI "https://github.com/wannaflyhigh/latia112-1/blob/main/final/openai.js"
    click ReadCsv "https://github.com/wannaflyhigh/latia112-1/blob/main/final/readCsv.js"
    click Parsed "https://github.com/wannaflyhigh/latia112-1/blob/main/final/parsed.json"
    click CSVdata "https://github.com/wannaflyhigh/latia112-1/blob/main/final/data_collect/均一高中生物.csv"
    click Chi "https://github.com/wannaflyhigh/latia112-1/blob/main/final/chi_tra.traineddata"
    click Eng "https://github.com/wannaflyhigh/latia112-1/blob/main/final/eng.traineddata"
    click Sele "https://github.com/wannaflyhigh/latia112-1/blob/main/final/data_collect/sele.py"
    click TestNotebook "https://github.com/wannaflyhigh/latia112-1/blob/main/final/data_collect/test.ipynb"
    click Package "https://github.com/wannaflyhigh/latia112-1/blob/main/final/package.json"
    click Readme "https://github.com/wannaflyhigh/latia112-1/blob/main/final/README.md"
    click Gitignore "https://github.com/wannaflyhigh/latia112-1/blob/main/final/.gitignore"

    %% Styles
    classDef user fill:#FFD47F,stroke:#E89A00,color:#000
    classDef external fill:#F0F0F0,stroke:#333,color:#000
    classDef server fill:#D0E6A5,stroke:#7AAE23,color:#000
    classDef service fill:#A5D8F3,stroke:#2394AE,color:#000
    classDef datastore fill:#F7C8E0,stroke:#C84F79,color:#000,shape:cylinder
    classDef pipeline fill:#E4C1F9,stroke:#6B1E7E,color:#000
    classDef config fill:#CCCCCC,stroke:#555,color:#000
```
