# freeok/so-novel architecture

> Architecture diagram of the GitHub repository freeok/so-novel, 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/freeok/so-novel
- Repository: https://github.com/freeok/so-novel

## Overview

##### Main Components to Identify and Represent
- User Interface / Entry Point:
- CLI or script-based interface, given that the installation instructions indicate “解压即用” and separate deployment shell scripts.

- Action Layer:
- Distinct “Action” components (BatchDownloadAction, CheckUpdateAction, SearchAndDownloadAction, ShowSourcesAction). These represent discrete user commands/features.
- That each action channels user input to specific processing flows.

- Core / Crawler Component:
- “Crawler” module under the “core” package, which is responsible for fetching and crawling novel data.
- Alongside, include supporting utilities like ChapterFilter, ChapterFormatter, and CoverUpdater that process the data.

- Parsing and Conversion:
- “parse” components (e.g., BookParser, ChapterParser, SearchParser, TocParser) that extract data from the fetched content.
- “convert” package modules (ChapterConverter, ChineseConverter) that prepare chapter content for various output formats.

- Post-Processing / Handle Module:
- Set of post-handlers (CrawlerPostHandler, EpubMergeHandler, HtmlTocHandler, TxtMergeHandler, etc.) which further process and format the downloaded content.
- Existence of a factory (PostHandlerFactory) that dynamically selects the correct post-handling routine.

- Model and Configuration:
- “model” package components (Book, Chapter, Rule, AppConfig, etc.) which model the domain entities and application configuration.
- Also, capture external configurations such as “config.ini”, “src/main/resources/application.properties”, and rule JSON files (in the “src/main/resources/rule” directory). These files indicate external DSLs or rules that guide the crawling/parsing logic.

- Utilities and Libraries:
- Utility layer (“util” package with FileUtils, JsoupUtils, etc.) which supports the overall logic.
- External libraries (e.g., Jsoup for HTML parsing) integrated through Maven (pom.xml).

##### Relationships and Interactions Between Components
- Actions invoke the Crawler and Parser modules to fetch and interpret novel data.
- Parser outputs feed into the Conversion layer which prepares content for being output as EPUB, TXT, or HTML.
- Post-Processing handlers (invoked via a Factory pattern) then merge or format the outputs as necessary.
- Throughout the process, configuration and rule sets (provided in JSON and JavaScript files) act as a guiding policy for crawling and parsing.

##### Highlighting Architectural Patterns and Design Principles
- The project is modular, broken down into clear packages that separate concerns.
- Patterns such as Factory (e.g., PostHandlerFactory) and potentially Chain of Responsibility (for post-handling) can be depicted.
- The design also emphasizes extensibility (support for multiple “书源” — book sources) and adaptability (via external rule files and dynamic configuration).

##### Specific Elements
- User commands → Actions
- Actions → Crawler / Parsing → Processing
- Processing → Conversion → Post-Handler → Output files
- Core business logic (actions, crawler, parser, converter)
- Supporting configuration (INI, JSON, properties files)
- External deployment components (scripts in bin, Dockerfile)

##### Final Representation
- Provide a clear separation between configuration resources (stored in the resources folder and external input directory) and the executable modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface / Entry Point
    subgraph "User Interface / Entry Point"
        UI_Main["Main Class"]:::ui
        UI_DeployLinux["Deploy Script (Linux)"]:::ui
        UI_DeployMacos["Deploy Script (macOS)"]:::ui
        UI_DeployWindows["Deploy Script (Windows)"]:::ui
    end

    %% Action Layer
    subgraph "Action Layer"
        ACTION_Batch["BatchDownloadAction"]:::action
        ACTION_Check["CheckUpdateAction"]:::action
        ACTION_Search["SearchAndDownloadAction"]:::action
        ACTION_Show["ShowSourcesAction"]:::action
    end

    %% Core / Crawler Component
    subgraph "Core / Crawler Component"
        CORE_Crawler["Crawler"]:::crawler
        CORE_Filter["ChapterFilter"]:::crawler
        CORE_Formatter["ChapterFormatter"]:::crawler
        CORE_Cover["CoverUpdater"]:::crawler
    end

    %% Parsing and Conversion
    subgraph "Parsing and Conversion"
        PARSER_Book["BookParser"]:::parse
        PARSER_Chapter["ChapterParser"]:::parse
        PARSER_Search["SearchParser"]:::parse
        PARSER_Search6["SearchParser6"]:::parse
        PARSER_Toc["TocParser"]:::parse
        CONVERTER_Chapter["ChapterConverter"]:::convert
        CONVERTER_Chinese["ChineseConverter"]:::convert
    end

    %% Post-Processing / Handle Module
    subgraph "Post-Processing / Handle Module"
        HANDLE_Crawler["CrawlerPostHandler"]:::handle
        HANDLE_Epub["EpubMergeHandler"]:::handle
        HANDLE_Html["HtmlTocHandler"]:::handle
        HANDLE_Txt["TxtMergeHandler"]:::handle
        HANDLE_Factory["PostHandlerFactory"]:::handle
    end

    %% Model and Configuration
    subgraph "Model and Configuration"
        MODEL_Model["Model Package"]:::config
        CONFIG_AppProp["application.properties"]:::config
        CONFIG_Rules["Rule Files"]:::config
        CONFIG_INI["config.ini"]:::config
    end

    %% Utilities and Libraries
    subgraph "Utilities and Libraries"
        UTIL_File["FileUtils"]:::util
        UTIL_Jsoup["JsoupUtils"]:::util
        UTIL_Others["Other Utilities"]:::util
        EXTERNAL_Maven["Maven (pom.xml)"]:::external
    end

    %% Data Flow Connections
    UI_Main -->|"triggers"| ACTION_Batch
    UI_Main -->|"triggers"| ACTION_Check
    UI_Main -->|"triggers"| ACTION_Search
    UI_Main -->|"triggers"| ACTION_Show

    ACTION_Batch -->|"invokes"| CORE_Crawler
    ACTION_Check -->|"invokes"| CORE_Crawler
    ACTION_Search -->|"invokes"| CORE_Crawler
    ACTION_Show -->|"invokes"| CORE_Crawler

    CORE_Crawler -->|"fetches data"| PARSER_Book
    CORE_Crawler -->|"fetches data"| PARSER_Chapter
    CORE_Crawler -->|"fetches data"| PARSER_Search
    CORE_Crawler -->|"fetches data"| PARSER_Toc

    PARSER_Book -->|"prepares"| CONVERTER_Chapter
    PARSER_Chapter -->|"prepares"| CONVERTER_Chapter
    PARSER_Search -->|"prepares"| CONVERTER_Chapter
    PARSER_Search6 -->|"prepares"| CONVERTER_Chapter
    PARSER_Toc -->|"prepares"| CONVERTER_Chapter

    CONVERTER_Chapter -->|"formats output"| HANDLE_Crawler
    CONVERTER_Chinese -->|"formats output"| HANDLE_Epub

    HANDLE_Crawler -->|"post-processes"| HANDLE_Epub
    HANDLE_Epub -->|"post-processes"| HANDLE_Html
    HANDLE_Html -->|"post-processes"| HANDLE_Txt
    HANDLE_Factory -->|"selects routine"| HANDLE_Crawler

    %% Configuration and Utilities influence various components
    CONFIG_AppProp --- CORE_Crawler
    CONFIG_Rules --- PARSER_Book
    CONFIG_Rules --- PARSER_Chapter
    CONFIG_INI --- MODEL_Model

    UTIL_File --- CORE_Crawler
    UTIL_File --- PARSER_Book
    UTIL_Jsoup --- PARSER_Chapter
    UTIL_Others --- ACTION_Batch

    EXTERNAL_Maven --- UTIL_Others

    %% Click Events for User Interface / Entry Point
    click UI_Main "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/Main.java"
    click UI_DeployLinux "https://github.com/freeok/so-novel/blob/main/bin/deploy-linux.sh"
    click UI_DeployMacos "https://github.com/freeok/so-novel/blob/main/bin/deploy-macos.sh"
    click UI_DeployWindows "https://github.com/freeok/so-novel/blob/main/bin/deploy-windows.sh"

    %% Click Events for Action Layer
    click ACTION_Batch "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/action/BatchDownloadAction.java"
    click ACTION_Check "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/action/CheckUpdateAction.java"
    click ACTION_Search "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/action/SearchAndDownloadAction.java"
    click ACTION_Show "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/action/ShowSourcesAction.java"

    %% Click Events for Core / Crawler Component
    click CORE_Crawler "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/core/Crawler.java"
    click CORE_Filter "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/core/ChapterFilter.java"
    click CORE_Formatter "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/core/ChapterFormatter.java"
    click CORE_Cover "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/core/CoverUpdater.java"

    %% Click Events for Parsing and Conversion
    click PARSER_Book "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/parse/BookParser.java"
    click PARSER_Chapter "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/parse/ChapterParser.java"
    click PARSER_Search "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/parse/SearchParser.java"
    click PARSER_Search6 "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/parse/SearchParser6.java"
    click PARSER_Toc "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/parse/TocParser.java"
    click CONVERTER_Chapter "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/convert/ChapterConverter.java"
    click CONVERTER_Chinese "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/convert/ChineseConverter.java"

    %% Click Events for Post-Processing / Handle Module
    click HANDLE_Crawler "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/handle/CrawlerPostHandler.java"
    click HANDLE_Epub "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/handle/EpubMergeHandler.java"
    click HANDLE_Html "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/handle/HtmlTocHandler.java"
    click HANDLE_Txt "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/handle/TxtMergeHandler.java"
    click HANDLE_Factory "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/handle/PostHandlerFactory.java"

    %% Click Events for Model and Configuration
    click MODEL_Model "https://github.com/freeok/so-novel/tree/main/src/main/java/com/pcdd/sonovel/model"
    click CONFIG_AppProp "https://github.com/freeok/so-novel/blob/main/src/main/resources/application.properties"
    click CONFIG_Rules "https://github.com/freeok/so-novel/tree/main/src/main/resources/rule"
    click CONFIG_INI "https://github.com/freeok/so-novel/blob/main/config.ini"

    %% Click Events for Utilities and Libraries
    click UTIL_File "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/util/FileUtils.java"
    click UTIL_Jsoup "https://github.com/freeok/so-novel/blob/main/src/main/java/com/pcdd/sonovel/util/JsoupUtils.java"
    click UTIL_Others "https://github.com/freeok/so-novel/tree/main/src/main/java/com/pcdd/sonovel/util"
    click EXTERNAL_Maven "https://github.com/freeok/so-novel/blob/main/pom.xml"

    %% Styling Classes
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef action fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef crawler fill:#F5CBA7,stroke:#9A7D0A,stroke-width:2px;
    classDef parse fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef convert fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef handle fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef config fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef util fill:#D5F5E3,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
