# jhihjian/guyu architecture

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

- Interactive diagram: https://gitdiagram.com/jhihjian/guyu
- Repository: https://github.com/jhihjian/guyu

## Overview

##### Project Type and Purpose
- This is a Python-based personal assistant application aimed at aggregating personal daily data, including food intake, exercise, and other lifestyle details.
- It integrates various functionalities such as a UI interface, database connectivity (sqlite), voice recognition (及语音唤醒), QQ message listening, and connections to large-model APIs for natural language processing.
- There’s also the FoodCa functionality: a streamlined, voice-interpreting tool that records food intake and fetches nutritional information via an AI-based back end.

##### File Structure for Architectural Clues
- The top-level “pydev” directory contains the core source code.
- “pydev/src/QianFanApi.py” likely encapsulates API interactions (possibly with the large model or nutrition API).
- “pydev/src/util” includes helper modules such as DESHelper.py and PWManager.py, suggesting responsibilities for encryption and password/credential management.
- The “pydev/requirements.txt” file points to external dependencies.
- The “resource” directory holds files like “pw.txt” and “qianfan_key_id_data” which are probably used for authentication and secure storage of API keys or other sensitive configuration.
- Although there isn’t an explicit “UI” directory, the README mentions a UI. This indicates that the UI might be integrated within the main code or built using packaged resources.

##### Key Components
a. User Interface (UI) Layer:
- Represents the desktop UI for the exe version of “谷雨”. This would handle voice commands and daily logs.
- This as a distinct module even if internals are embedded.
b. API Integration Module:
- QianFanApi.py should be shown as the module that handles communication with external large models and APIs to perform tasks like nutritional analysis and natural language processing.
c. Utility Modules:
- DESHelper and PWManager as submodules under a “Security / Credential Manager” component for encryption and managing keys/resources.
d. Resource / Configuration Component:
- The “resource” folder (with pw.txt and qianfan_key_id_data) serves as a configuration backing store.
e. Database Component:
- As per the README mention, an embedded sqlite database should be depicted to show persistent data storage used for daily logs, food recording, or event logs.
f. Specialized Modules:
g. FoodCa Functionality:
- Since FoodCa is positioned as a streamlined record tool for nutritional info, indicate a dedicated “Food Analysis” or “Calorie Recorder” component. Show its relationship to the API integration layer (for nutrition models) as well as its connection to charting/dashboard outputs for historical data.

##### Relationships and Interactions
- From the User Interface to the API module (representing user commands triggering requests to the large model).
- From the API module to external services (nutritional databases, language model endpoints), which may be represented as a cloud or external system.
- From utility/security components to both configuration/resource storage and API integration (to handle secure key usage).
- Between UI and Database, illustrating data persistence such as voice logs and daily records.
- The FoodCa recording module should have inputs from the UI (voice or text input describing food) and outputs connecting to the API (for analysis) and then back to UI/database display.

##### Architectural Patterns and Design Principles
- A modular design with clear separation of concerns:
- UI separated from the core business logic and API interactions.
- Security utilities decoupled from the core API integration, facilitating secure key management.
- Use of an embedded database for localized storage.
- Layers (Presentation, Business Logic/API, Data Storage, and Security/Configuration).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Desktop UI"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        QianFanApi["QianFanApi (API Integration)"]:::backend
        FoodAnalysis["Food Analysis/Calorie Recorder"]:::backend
    end

    %% Data Storage Layer
    subgraph "Data Storage"
        DB["SQLite Database"]:::database
    end

    %% Utility Layer
    subgraph "Utility Layer"
        %% Security/Credential Manager Subgroup
        subgraph "Security/Credential Manager"
            DESHelper["DESHelper"]:::utility
            PWManager["PWManager"]:::utility
        end
        Resource["Resource/Configuration"]:::utility
        %% Specialized Modules Subgroup
        subgraph "Specialized Modules"
            VoiceRec["Voice Recognition"]:::utility
            QQListener["QQ Listener"]:::utility
            EventParser["Event Parser"]:::utility
        end
    end

    %% External Services
    External["External Nutritional & NLP Services"]:::external

    %% Connections between layers
    UI -->|"userCommands"| QianFanApi
    UI -->|"foodInput"| FoodAnalysis
    QianFanApi -->|"analysisRequest"| FoodAnalysis
    FoodAnalysis -->|"analysisResult"| UI

    %% QianFanApi interactions
    QianFanApi -->|"apiCalls"| External
    QianFanApi -->|"storeData"| DB
    UI -->|"logData"| DB

    %% QianFanApi security/config interactions
    QianFanApi -->|"keyRequest"| DESHelper
    QianFanApi -->|"keyRequest"| PWManager
    Resource -->|"loadConfig"| DESHelper
    Resource -->|"loadConfig"| PWManager

    %% Specialized Modules feeding into UI
    VoiceRec -->|"voiceCommand"| UI
    QQListener -->|"chatMsg"| UI
    EventParser -->|"eventData"| UI

    %% Click Events
    click QianFanApi "https://github.com/jhihjian/guyu/blob/main/pydev/src/QianFanApi.py"
    click DESHelper "https://github.com/jhihjian/guyu/blob/main/pydev/src/util/DESHelper.py"
    click PWManager "https://github.com/jhihjian/guyu/blob/main/pydev/src/util/PWManager.py"
    click Resource "https://github.com/jhihjian/guyu/tree/main/resource"

    %% Styles
    classDef frontend fill:#A2D5F2,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFDDC1,stroke:#000,stroke-width:2px;
    classDef database fill:#C1E1C1,stroke:#000,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef utility fill:#F7C6C7,stroke:#000,stroke-width:2px;
    classDef external fill:#FDE2C6,stroke:#000,stroke-width:2px;
```
