# afool4u/migpt architecture

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

- Interactive diagram: https://gitdiagram.com/afool4u/migpt
- Repository: https://github.com/afool4u/migpt

## Overview

##### Main Components
- User Interface & Input Handler: Although not explicitly a separate front-end, the system expects user commands (either via voice commands/instructions provided to the device or through an API endpoint in a script). This “input” can be depicted as a user node.
- Core Engine (MIGPT.py): Acts as the primary coordinator. It receives user inputs, orchestrates the conversation via the streaming ChatGPT API, and issues control commands.
- Xiaomi Account Module (miaccount.py): This module handles account credentials management for Xiaomi services. It is used by the core engine when initiating device control commands.
- Model Invocation Subsystem: Even if not fully implemented in the repository (as noted in the README), include a component representing the two models (fine-tuned BERT and TF-IDF+SVM classifier) that decide whether to route a request to the “ChatGPT” conversational flow or towards direct device commands.

##### Relationships/Interactions
- ChatGPT API Integration (external service), emphasizing the streaming, real-time data flow.
- Xiaomi Account and Device Service modules, showing how credentials (miaccount.py) support authentication before commanding devices (minaservice.py).
- Optionally, mark a connection with the Model Invocation Subsystem if automatic decision-making is triggered.

##### Architectural Patterns and Design Principles
- Separation of concerns: one module specifically handles external API interactions; independent modules manage account credentials and device control.
- Use of streaming conversation (API streaming) and asynchronous programming patterns used to reduce response latency.

##### Relevant Technologies and Frameworks
- “OpenAI API” as the external dependency for conversational AI.
- That the project is written in Python and uses “requirements.txt” to manage dependencies.
- If applicable, include “asynchronous programming patterns” (i.e., async/await) as part of the design annotation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    U("User Input"):::user
    MIGPT("MIGPT Core Engine"):::core
    CGAPI("ChatGPT API"):::external
    Model("Model Invocation Subsystem"):::model
    Xiaomi("Xiaomi Account Module"):::account
    Device("Device Control Module"):::device
    V3("Alternative Functionality Module"):::alt

    %% High-Level Flow
    U -->|"UserCommand"| MIGPT

    %% Real-Time Conversation Flow
    MIGPT <-->|"Streaming"| CGAPI

    %% Decision Branch for Request Routing
    MIGPT -->|"Decision"| Model
    Model -->|"RouteToChatGPT"| CGAPI
    Model -->|"RouteToDevice"| Xiaomi

    %% Device Control Flow
    Xiaomi -->|"Authentication"| Device

    %% Alternative/Extended Functionality Flow
    MIGPT -->|"AltPath"| V3

    %% Click Events
    click MIGPT "https://github.com/afool4u/migpt/blob/main/MIGPT.py"
    click Xiaomi "https://github.com/afool4u/migpt/blob/main/miaccount.py"
    click Device "https://github.com/afool4u/migpt/blob/main/minaservice.py"
    click V3 "https://github.com/afool4u/migpt/blob/main/V3.py"

    %% Styles
    classDef user fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef core fill:#9fdfbf,stroke:#333,stroke-width:2px;
    classDef external fill:#cde0ff,stroke:#333,stroke-width:2px;
    classDef model fill:#ffc0cb,stroke:#333,stroke-width:2px;
    classDef account fill:#e0ffff,stroke:#333,stroke-width:2px;
    classDef device fill:#ffe4e1,stroke:#333,stroke-width:2px;
    classDef alt fill:#d1c4e9,stroke:#333,stroke-width:2px;
```
