# nekoparapa/ainiee architecture

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

- Interactive diagram: https://gitdiagram.com/nekoparapa/ainiee
- Repository: https://github.com/nekoparapa/ainiee

## Overview

##### Project Overview & Main Components
- Project type – AiNiee is a full-stack desktop (or GUI) tool primarily focused on AI-based translation for games, novels, subtitles, documents, etc. The README emphasizes multi-format support, integration with multiple LLM platforms, and a plug-in system.
- Main architectural components include:
- Core Engine and Base Modules: Represented by AiNiee.py and the “Base” folder (Base.py, EventManager.py, PluginManager.py). This layer coordinates events, plugin loading, and overall workflow.
- File I/O and Conversion Layer: Under “ModuleFolders” are subfolders for FileReader, FileOutputer, FileConverter, FileAccessor—as well as Cache management. These components handle various file formats (JSON, DOCX, EPUB, TXT, etc.), performing reading, conversion, and saving operations.
- API & Translation Services: Modules like “LLMRequester”, “Translator”, and “PromptBuilder” encapsulate the communication with external AI platforms as shown in the README and the LLMRequester submodules (OpenaiRequester, GoogleRequester, etc.). Also include RequestLimiter, ResponseChecker, and ResponseExtractor modules.
- Widget & UI Components: The “DRWidget”, “UserInterface”, and “Widget” directories provide UI controls and configuration panels to set up translation projects, select APIs, change prompt settings, and manage UI interactions. They include settings pages, status monitoring, plugin management, and file operations.
- Plugin Extensions: The “PluginScripts” folder contains various plugins (e.g., BilingualPlugin, LanguageFilter, TextNormalizer, etc.) that add extra functionalities. These plugins extend or modify the core translation workflow.
- Supporting Resources: “Resource” holds localization files, prompt text files, regex definitions, and updater executables.

##### Relationships and Data Flow
- Next, detail the file flow:
- The FileReader modules (ModuleFolders/FileReader) read original documents.
- The FileConverter (ModuleFolders/FileConverter) can process files between formats as needed.
- Then come the FileOutputers which write translated text to the designated output.
- The translation workflow should branch to include the “Translator” component which, in turn, connects with LLMRequester and PromptBuilder modules to structure requests and communicate with external AI platforms.
- Layer in the plugins: Display a plug-in layer that intercepts or modifies content through PluginManager from the “PluginScripts” folder, adding functionalities such as language filtering, text normalization, or specialized translation checks.
- Also, illustrate the ancillary modules, such as RequestLimiter, ResponseExtractor, and ResponseChecker, that ensure proper throughput and quality control.

##### Architectural Patterns & Design Principles
- Modularity and separation of concerns:
- UI is distinct from core translation logic.
- All file operations are abstracted into dedicated modules.
- External API interfacing is encapsulated in specialized modules.
- Plugin-based extensibility allows one to add or update functionality without changing the core code.
- Labels should clearly state each component (for example: “User Interface – Project Settings Page”, “Core Engine – Event Manager”, “FileReader – DocxReader”, “Plugin – TextNormalizer”, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI1["User Interface - Project Settings"]:::ui
        UI2["DRWidget"]:::ui
        UI3["Widget"]:::ui
    end

    %% Core Engine Layer
    subgraph "Core Engine Layer"
        CE1["AiNiee.py"]:::core
        CE2["Base/Base.py"]:::core
        CE3["Base/EventManager.py"]:::core
        CE4["Base/PluginManager.py"]:::core
    end

    %% File Handling Layer
    subgraph "File Handling Layer"
        FH1["ModuleFolders/FileReader"]:::file
        FH2["ModuleFolders/FileConverter"]:::file
        FH3["ModuleFolders/FileOutputer"]:::file
        FH4["ModuleFolders/Cache"]:::file
    end

    %% AI & Processing Layer
    subgraph "AI & Processing Layer"
        AI1["ModuleFolders/Translator"]:::ai
        AI2["ModuleFolders/LLMRequester"]:::ai
        AI3["ModuleFolders/PromptBuilder"]:::ai
        AI4["ModuleFolders/RequestLimiter"]:::ai
        AI5["ModuleFolders/ResponseChecker"]:::ai
        AI6["ModuleFolders/ResponseExtractor"]:::ai
    end

    %% Plugin Extensions Layer
    subgraph "Plugin Extensions Layer"
        PL1["PluginScripts"]:::plugin
    end

    %% Supporting Resources
    subgraph "Supporting Resources"
        SR1["Resource"]:::resource
    end

    %% Connections - Data Flow
    UI1 -->|"initiates"| CE1
    UI2 -->|"triggers"| CE1
    UI3 -->|"triggers"| CE1

    CE1 -->|"orchestrates"| CE2
    CE1 -->|"orchestrates"| CE3
    CE1 -->|"orchestrates"| CE4

    %% Core to File Handling
    CE1 -->|"processes"| FH1
    FH1 -->|"reads"| FH2
    FH2 -->|"converts"| FH3
    FH1 -->|"caches"| FH4

    %% Core to AI & Processing
    CE1 -->|"delegates"| AI1
    AI1 -->|"calls"| AI2
    AI1 -->|"builds"| AI3
    AI2 -->|"limits"| AI4
    AI2 -->|"validates"| AI5
    AI2 -->|"extracts"| AI6

    %% Plugin Integration
    CE4 -->|"loads"| PL1
    AI1 -->|"intercepts"| PL1

    %% Annotations for multi-format support and API connectivity are implied in these flows.

    %% Click Events for UI Components
    click UI1 "https://github.com/nekoparapa/ainiee/tree/main/UserInterface"
    click UI2 "https://github.com/nekoparapa/ainiee/tree/main/DRWidget"
    click UI3 "https://github.com/nekoparapa/ainiee/tree/main/Widget"

    %% Click Events for Core Engine and Base Modules
    click CE1 "https://github.com/nekoparapa/ainiee/blob/main/AiNiee.py"
    click CE2 "https://github.com/nekoparapa/ainiee/blob/main/Base/Base.py"
    click CE3 "https://github.com/nekoparapa/ainiee/blob/main/Base/EventManager.py"
    click CE4 "https://github.com/nekoparapa/ainiee/blob/main/Base/PluginManager.py"

    %% Click Events for File I/O and Conversion Layer
    click FH1 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/FileReader"
    click FH2 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/FileConverter"
    click FH3 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/FileOutputer"
    click FH4 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/Cache"

    %% Click Events for API & Translation Services
    click AI1 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/Translator"
    click AI2 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/LLMRequester"
    click AI3 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/PromptBuilder"
    click AI4 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/RequestLimiter"
    click AI5 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/ResponseChecker"
    click AI6 "https://github.com/nekoparapa/ainiee/tree/main/ModuleFolders/ResponseExtractor"

    %% Click Event for Plugin Extensions
    click PL1 "https://github.com/nekoparapa/ainiee/tree/main/PluginScripts"

    %% Click Event for Supporting Resources
    click SR1 "https://github.com/nekoparapa/ainiee/tree/main/Resource"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef core fill:#82E0AA,stroke:#000,stroke-width:2px;
    classDef file fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef ai fill:#F5B7B1,stroke:#000,stroke-width:2px;
    classDef plugin fill:#D2B4DE,stroke:#000,stroke-width:2px;
    classDef resource fill:#CCD1D1,stroke:#000,stroke-width:2px;
```
