# doguto/writer-elyza architecture

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

- Interactive diagram: https://gitdiagram.com/doguto/writer-elyza
- Repository: https://github.com/doguto/writer-elyza

## Overview

##### Project type and purpose
- From the README (“writer-elyza: 日本語の学習がされたLLMであるELYZAを用い、全自動でアルファポリスに投稿を行ってくれるアプリです”), this is a full-stack automation tool. It uses an LLM (ELYZA) to generate Japanese novel text, then posts it automatically to the Alphapolis web service.

##### File structure
Top-level:
- src/main.py            – the entrypoint/orchestrator
- src/novel/novel.py     – novel‐domain model
- src/writer             – modules handling AI prompts, installer, writer logic
– ai.py, prompts.py, writer.py, installer.py
- src/web_operation_py   – modules handling web automation (Selenium)
- src/test               – unit tests
- works/                 – output folder for generated and posted files

Patterns:
- Clear separation between “Novel generation” (writer + novel) and “Web operation” (posting).
- A CLI (main.py) that ties together AI, domain model, file storage, and web automation.

##### README for additional insights
- Dependencies implied: an LLM client library, Selenium (or similar), a file system for intermediate storage.

##### Main components and their interactions
a. Components:
1) Orchestrator (src/main.py)
2) Novel Domain (src/novel/novel.py)
3) Writer Service
– prompts.py: constructs LLM prompts
– ai.py: calls the LLM API (ELYZA)
– writer.py: high-level orchestration of generate→serialize
– installer.py: installs/configures any needed local resources/plugins
4) Storage (works/ directory)
5) Web Automation (src/web_operation_py)
– alphapolis_operater.py: login + post flows
– selenium_sample.py: sample reference code
6) External LLM Service (ELYZA API)
7) External Web Service (Alphapolis)

b. Relationships & data flow:
1) CLI → Writer Service (via prompts & ai) → Novel objects
2) Novel objects → Serialized to works/ folder
3) CLI → Web Automation Component reads works/ → drives browser to Alphapolis
4) External calls: LLM API ← ai.py, Alphapolis website ← Selenium driver

c. Architectural patterns/design principles:
- Single-responsibility: each module handles one concern (prompting, AI call, web posting)
- Layered: CLI orchestrator, domain model, service layer, infrastructure (storage, Selenium)
- Plug-in friendly: installer.py could register additional LLMs

d. Key technologies/frameworks:
- Python 3
- LLM API client (ELYZA)
- Selenium (web driver) for Alphapolis posting
- pytest for tests

##### Elements
- Internal modules (blue)
- External services (green)
- Data stores (yellow)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestrator
    CLI["CLI Orchestrator\nsrc/main.py"]:::internal

    %% Novel Generation Layer
    subgraph "Novel Generation Layer"
        direction TB
        Installer["Installer / Plugin Setup\nsrc/writer/installer.py"]:::internal
        Prompt["Prompt Engine\nsrc/writer/prompts.py"]:::internal
        LLMClient["LLM API Client\nsrc/writer/ai.py"]:::internal
        GenOrch["Generation Orchestrator\nsrc/writer/writer.py"]:::internal
    end

    %% Domain Model
    NovelModel["Novel Domain Model\nsrc/novel/novel.py"]:::internal

    %% Storage
    Storage["File Storage\nworks/"]:::datastore

    %% Web Posting Layer
    subgraph "Web Posting Layer"
        direction TB
        WebAutomator["Web Automator\nsrc/web_operation_py/alphapolis_operater.py"]:::internal
        SeleniumRef["Selenium Sample Reference\nsrc/web_operation_py/sample/selenium_sample.py"]:::internal
    end

    %% External Services
    ExternalLLM["External LLM Service\nELYZA API"]:::external
    ExternalWeb["External Web Service\nAlphapolis"]:::external

    %% Testing
    subgraph "Tests"
        direction TB
        TestsAll["Unit Tests All\nsrc/test/test_all.py"]:::internal
        TestsWriter["Unit Tests Writer\nsrc/test/test_writer.py"]:::internal
        TestsWeb["Unit Tests Web Automator\nsrc/test/test_alphapolis_operater.py"]:::internal
    end

    %% Flows
    CLI -->|"invoke generation"| Installer
    Installer -->|"setup plugins"| Prompt
    Prompt -->|"construct_prompt"| LLMClient
    LLMClient -->|"ai.generate()"| ExternalLLM
    ExternalLLM -->|"AI response"| LLMClient
    LLMClient -->|"response_to_model"| NovelModel
    NovelModel -->|"create_text"| GenOrch
    GenOrch -->|"write_file"| Storage

    CLI -->|"post_novel"| WebAutomator
    WebAutomator -->|"read_file"| Storage
    WebAutomator -->|"use_driver"| SeleniumRef
    SeleniumRef -->|"driver.post()"| ExternalWeb
    ExternalWeb -->|"response"| SeleniumRef

    %% Test Flows
    TestsAll --> TestsWriter
    TestsAll --> TestsWeb

    %% Click Events
    click CLI "https://github.com/doguto/writer-elyza/blob/main/src/main.py"
    click NovelModel "https://github.com/doguto/writer-elyza/blob/main/src/novel/novel.py"
    click Prompt "https://github.com/doguto/writer-elyza/blob/main/src/writer/prompts.py"
    click LLMClient "https://github.com/doguto/writer-elyza/blob/main/src/writer/ai.py"
    click GenOrch "https://github.com/doguto/writer-elyza/blob/main/src/writer/writer.py"
    click Installer "https://github.com/doguto/writer-elyza/blob/main/src/writer/installer.py"
    click Storage "https://github.com/doguto/writer-elyza/tree/main/works/"
    click WebAutomator "https://github.com/doguto/writer-elyza/blob/main/src/web_operation_py/alphapolis_operater.py"
    click SeleniumRef "https://github.com/doguto/writer-elyza/blob/main/src/web_operation_py/sample/selenium_sample.py"
    click TestsAll "https://github.com/doguto/writer-elyza/blob/main/src/test/test_all.py"
    click TestsWriter "https://github.com/doguto/writer-elyza/blob/main/src/test/test_writer.py"
    click TestsWeb "https://github.com/doguto/writer-elyza/blob/main/src/test/test_alphapolis_operater.py"

    %% Styles
    classDef internal fill:#D6EAF8,stroke:#3498DB,color:#1B4F72
    classDef external fill:#D5F5E3,stroke:#27AE60,color:#1D8348
    classDef datastore fill:#FCF3CF,stroke:#D68910,color:#7E5109
```
