# cjyyx/ai_gen_novel architecture

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

- Interactive diagram: https://gitdiagram.com/cjyyx/ai_gen_novel
- Repository: https://github.com/cjyyx/ai_gen_novel

## Overview

##### Project Type and Purpose
- The README and file structure reveal that this is an AI-content generation application focused on automatically writing web novels.
- Its goal is to overcome typical LLM limitations (like handling long-text generation and creativity issues) via multi-agent discussions and iterative text refinement (inspired by approaches like RecurrentGPT).

##### File Structure and Main Components
- Top-level Files/Scripts:
- AIGN.py and AIGN_Prompt.py: Likely contain the core logic for generating novel content using AI, applying multi-step prompt methodologies.
- LLM.py: Contains the LLM interface—specifically, the chatLLM function that you must implement to interface with the chosen language model.
- app.py: Launches a Gradio-based web application to allow users to visually interact with the novel-generation process.
- demo.py: Provides a command-line demo that auto-generates a novel and saves it.
- ideas.py: Likely includes supplemental functions or ideas pertaining to content generation or experimentation.
- uniai/ directory: Holds alternative or experimental modules (such as aliAI.py, deepseekAI.py, and zhipuAI.py), which could represent different LLM API integrations or multi-agent strategies.
- requirements.txt, LICENSE, README.md, and other files are standard project metadata and assets.

##### And Define the Key Components
a. Core AI Novel Generation Engine:
- AIGN.py and AIGN_Prompt.py: Central to the novel generation process, handling the iterative prompt and refinement logic.
- ideas.py: Supporting experimental or additional logic to refine narrative ideas.
b. LLM Interface:
- LLM.py: Define a clear interface for chatLLM that interacts with an external large language model API.
c. Multi-agent Modules:
- Modules within the uniai directory (aliAI.py, deepseekAI.py, and zhipuAI.py): Represent alternative AI “agents” that might handle specific tasks or alternative LLM integrations.
d. User Interaction Layers:
- app.py: The Gradio-based UI that provides a visual interface for users to trigger novel generation and view results.
- demo.py: A script for quick CLI demo generation which outputs the text into a file (novel_record.md as per README).
e. External Dependencies and Assets:
- requirements.txt: The list of dependencies that power the application.

##### Relationships and Interactions
- User interacting either with the web frontend (app.py) or via CLI (demo.py).
- Both interfaces funnel user input into the Core Novel Generation Engine (AIGN modules and ideas.py).
- The Core Engine communicates with the LLM Interface (LLM.py) to generate and refine text.
- Optionally, indicate that the multi-agent modules (in uniai) are alternative or complementary layers that can be invoked to explore different creative directions or LLM endpoints.

##### Architectural Patterns and Design Principles
- Modular Design: Separate responsibilities into distinct modules (e.g., generation logic, LLM interfacing, UI components, and alternative agents).
- Iterative and Looping Data Flow: Emphasize the cycle of prompt generation, LLM querying, and revision (reflecting the RecurrentGPT-inspired approach).
- Multi-Agent Collaboration: Show how different AI agents may interact or be coordinated to enhance creativity and overcome the LLM’s inherent limitations.

##### Final Elements
- Components: “User Interface” (Gradio via app.py & demo.py), “Core Novel Generation Engine” (includes AIGN.py, AIGN_Prompt.py, ideas.py), “LLM Interface” (LLM.py), “Alternative AI Agents” (uniai modules), and “External Resources/Dependencies” (e.g., external LLM API, images in PasteImage).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction Layers
    subgraph "User Interaction Layers"
        UI1("app.py (Gradio UI)"):::ui
        UI2("demo.py (CLI Demo)"):::ui
    end

    %% Core Novel Generation Engine
    subgraph "Core Novel Generation Engine"
        CE1("AIGN.py"):::core
        CE2("AIGN_Prompt.py"):::core
        CE3("ideas.py"):::core
    end

    %% LLM Interface
    LLM("LLM.py"):::llm

    %% Multi-Agent Modules
    subgraph "Multi-Agent Modules"
        MA1("aliAI.py"):::agent
        MA2("deepseekAI.py"):::agent
        MA3("zhipuAI.py"):::agent
    end

    %% External Dependencies/Assets
    subgraph "External Dependencies/Assets"
        ED1("requirements.txt"):::external
        ED2("PasteImage"):::external
    end

    %% Connections
    UI1 -->|"submit"| CE1
    UI2 -->|"submit"| CE1
    CE1 -->|"initiates"| CE2
    CE2 -->|"iterative_logic"| CE3
    CE1 -->|"sends_prompt"| LLM
    LLM -->|"returns_response"| CE1
    CE1 -->|"uses_agent"| MA1
    CE1 -->|"uses_agent"| MA2
    CE1 -->|"uses_agent"| MA3
    CE3 -->|"output"| UI1
    CE3 -->|"output"| UI2
    ED1 ---|"dependency"| LLM
    ED2 ---|"assets"| UI1

    %% Click Events
    click UI1 "https://github.com/cjyyx/ai_gen_novel/blob/main/app.py"
    click UI2 "https://github.com/cjyyx/ai_gen_novel/blob/main/demo.py"
    click CE1 "https://github.com/cjyyx/ai_gen_novel/blob/main/AIGN.py"
    click CE2 "https://github.com/cjyyx/ai_gen_novel/blob/main/AIGN_Prompt.py"
    click CE3 "https://github.com/cjyyx/ai_gen_novel/blob/main/ideas.py"
    click LLM "https://github.com/cjyyx/ai_gen_novel/blob/main/LLM.py"
    click MA1 "https://github.com/cjyyx/ai_gen_novel/blob/main/uniai/aliAI.py"
    click MA2 "https://github.com/cjyyx/ai_gen_novel/blob/main/uniai/deepseekAI.py"
    click MA3 "https://github.com/cjyyx/ai_gen_novel/blob/main/uniai/zhipuAI.py"
    click ED1 "https://github.com/cjyyx/ai_gen_novel/blob/main/requirements.txt"
    click ED2 "https://github.com/cjyyx/ai_gen_novel/tree/main/PasteImage"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef core fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef llm fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef agent fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef external fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
