# tamikip/ai-gal architecture

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

- Interactive diagram: https://gitdiagram.com/tamikip/ai-gal
- Repository: https://github.com/tamikip/ai-gal

## Overview

##### Project type and purpose
- This is a desktop visual‐novel “launcher” and generator built on Ren’Py (script.rpy) that integrates multiple AI services (text, image, voice, music).
- Purpose: let end users configure and generate galgame storylines, images, voice lines, and background music via local or cloud AI models, then run the generated content in Ren’Py.

##### File structure
- Top‑level Python modules:
- gui.py, main.py – the launcher’s GUI entrypoint and controller
- config.ini – user settings for choosing local vs. cloud, API keys, themes
- update.py & update_docx.txt – built‑in update/fixer service
- script.rpy – the Ren’Py game script template into which generated assets are injected
- Generator modules by domain:
- GPT.py, trs2.py – story and dialogue generation (LLM interfaces)
- local_image_generator.py / cloud_image_generator.py – Stable Diffusion interfaces
- local_vocal_generator.py / cloud_vocal_generator.py – SOVITS TTS interfaces
- music_generator.py – AI music composer
- Supporting scripts:
- cloud_image_generator.py and cloud_vocal_generator.py – wrappers for remote API calls
- update.py – checks and pulls bug fixes or new versions

##### Insights from the README
- Dual‐mode AI: local vs. cloud for image and voice
- Dependencies: stable diffusion API, gpt-sovits API or local LLM
- Features: story branching, snapshots, multi‐language support, custom themes
- Output pipeline: generate text → generate images/audio/music → assemble into Ren’Py project

a. Main components
- User Interface (GUI Launcher)
- Configuration Store (config.ini, logs, snapshots)
- Story Generator (GPT module + branching logic)
- Image Generator (local & cloud SD)
- Voice Generator (local & cloud SOVITS)
- Music Generator
- Update Service
- Ren’Py Engine (script.rpy + assets)
- External AI Services (LLM endpoints, ComfyUI, gpt-sovits API)
- Local AI Engines (local Stable Diffusion, local gpt-sovits)
b. Relationships & data flow
1. UI reads config → user clicks “Generate”
2. Story Generator invokes GPT module → returns dialogue/branch choices
3. For each scene:
- Image Generator ↔ (local SD or cloud API) → image assets
- Voice Generator ↔ (local SOVITS or cloud API) → audio files
4. Music Generator → background music file
5. Assets + script.rpy → Ren’Py Engine → game runtime
6. Update Service runs in parallel to check for new code/bug fixes
c. Architectural patterns & principles
- Modular separation by concern (Story vs. Image vs. Voice vs. Music)
- Strategy pattern for local vs. cloud AI providers
- Pipeline assembly pattern: sequential content generation steps
- Configuration‐driven behavior (mode switching)
d. Key technologies & libraries
- Python 3.x and Ren’Py
- stable-diffusion (ComfyUI plugin)
- gpt-sovits TTS models
- OpenAI or local LLM endpoints
- Ren’Py script integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef local fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef cloud fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef core fill:#ffe5cc,stroke:#333,stroke-width:1px
    classDef config fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef update fill:#e6ccff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5

    %% Configuration and UI
    UILauncher["GUI Launcher"]:::core
    UIController["Main Controller"]:::core
    Config["Configuration Store\n(config.ini)"]:::config

    %% Story Generation
    subgraph "Story Generator Module"
        StoryGen["Story Generator"]:::core
        GPT["GPT Module"]:::core
        TRS["Branching Logic"]:::core
    end

    %% Image Generation
    subgraph "Image Generator Module"
        ImageGen["Image Generator"]:::core
        LocalImg["Local Mode\n(local_image_generator.py)"]:::local
        CloudImg["Cloud Mode\n(cloud_image_generator.py)"]:::cloud
    end

    %% Voice Generation
    subgraph "Voice Generator Module"
        VoiceGen["Voice Generator"]:::core
        LocalVoice["Local Mode\n(local_vocal_generator.py)"]:::local
        CloudVoice["Cloud Mode\n(cloud_vocal_generator.py)"]:::cloud
    end

    %% Music Generation
    MusicGen["Music Generator\n(music_generator.py)"]:::core

    %% Ren'Py Runtime
    RenPy["Ren'Py Engine\n(script.rpy)"]:::core

    %% Update Service
    Update["Update Service"]:::update

    %% External and Local Engines
    subgraph "External AI Services"
        ExternalLLM["LLM Endpoint"]:::cloud
        ExternalSD["ComfyUI API"]:::cloud
        ExternalTTS["gpt-sovits API"]:::cloud
    end

    subgraph "Local AI Engines"
        LocalSD["Local Stable Diffusion"]:::local
        LocalTTS["Local gpt-sovits"]:::local
    end

    %% Flows
    UILauncher -->|reads config| Config
    UIController -->|reads config| Config
    UILauncher --> UIController
    UIController -->|start generation| StoryGen

    StoryGen --> GPT
    StoryGen --> TRS
    GPT -->|POST prompt → LLM| ExternalLLM
    TRS --> StoryGen

    StoryGen -->|scene data| ImageGen
    ImageGen -->|choose strategy| LocalImg
    ImageGen -->|choose strategy| CloudImg
    LocalImg -->|invoke| LocalSD
    CloudImg -->|SD image request| ExternalSD

    StoryGen -->|scene data| VoiceGen
    VoiceGen -->|choose strategy| LocalVoice
    VoiceGen -->|choose strategy| CloudVoice
    LocalVoice -->|generate| LocalTTS
    CloudVoice -->|TTS request| ExternalTTS

    UIController -->|compose music| MusicGen

    StoryGen -->|text assets| RenPy
    ImageGen -->|image assets| RenPy
    VoiceGen -->|audio assets| RenPy
    MusicGen -->|music assets| RenPy

    %% Update flow
    Update -.->|checks for updates| UILauncher
    Update -.->|pull fixes| UIController
    Update -.-> StoryGen
    Update -.-> ImageGen
    Update -.-> VoiceGen
    Update -.-> MusicGen

    %% Click Events
    click UILauncher "https://github.com/tamikip/ai-gal/blob/main/gui.py"
    click UIController "https://github.com/tamikip/ai-gal/blob/main/main.py"
    click Config "https://github.com/tamikip/ai-gal/blob/main/config.ini"
    click GPT "https://github.com/tamikip/ai-gal/blob/main/GPT.py"
    click TRS "https://github.com/tamikip/ai-gal/blob/main/trs2.py"
    click LocalImg "https://github.com/tamikip/ai-gal/blob/main/local_image_generator.py"
    click CloudImg "https://github.com/tamikip/ai-gal/blob/main/cloud_image_generator.py"
    click LocalVoice "https://github.com/tamikip/ai-gal/blob/main/local_vocal_generator.py"
    click CloudVoice "https://github.com/tamikip/ai-gal/blob/main/cloud_vocal_generator.py"
    click MusicGen "https://github.com/tamikip/ai-gal/blob/main/music_generator.py"
    click RenPy "https://github.com/tamikip/ai-gal/blob/main/script.rpy"
    click Update "https://github.com/tamikip/ai-gal/blob/main/update.py"
```
