# yesnomore/screw architecture

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

- Interactive diagram: https://gitdiagram.com/yesnomore/screw
- Repository: https://github.com/yesnomore/screw

## Overview

##### Project Type and Purpose
- This is an open-source database documentation generation tool.
- Its purpose is to ease the process of generating up-to-date database documentation by scanning database schemas and creating documentation in various formats (HTML, Word, Markdown) using customizable templates (Freemarker, Velocity).
- The README emphasizes features like multi-database support, extensibility, and the ability to integrate via both direct API usage and via a Maven plugin.

##### Analyzing the File Structure and Main Components
- The project is split into several core sub-systems:
- screw-core: The heart of the tool that contains the main Java code. Within this module, you see several packages divided by responsibility:
- core/configuration: Handles Configuration classes (like Configuration.java, EngineConfig) that manage the overall settings.
- core/engine: Contains abstract classes and implementations for template engine processing (AbstractTemplateEngine, FreemarkerTemplateEngine, VelocityTemplateEngine) and file format/type management.
- core/metadata: Deals with database metadata (mapping tables, columns, keys) and model classes.
- core/query: Contains implementations of database query interfaces for multiple supported databases (MySQL, MariaDB, Oracle, PostgreSQL, etc.) along with their model representations.
- core/process: Contains the processing logic for generating the documentation (DataModelProcess, AbstractProcess, etc.).
- core/exception and core/util: Provide error handling and utility functions to assist with data manipulation and validations.
- screw-maven-plugin: A wrapper module that integrates the core functionality into Maven builds via a custom plugin (with a mojo class like RunDocMojo.java).
- secrw-dashboard: A web-based dashboard (likely a Spring Boot application, given the presence of a ServletInitializer and configuration files) that may offer an interactive UI for running or managing documentation generation, along with additional features like version management and licensing.

- Main Components to Include:
1. API/Client Layer: Code/Clients that invoke the screw documentation generation
- This could be custom Java applications using the screw-core API or a Maven build invoking the screw-maven-plugin.
2. Documentation Generation Engine (screw-core):
- Configuration Module: Contains settings (Configuration, EngineConfig, ProcessConfig) that define documentation parameters.
- Query Module: Contains various implementations for querying database metadata. This module handles connections (potentially via HikariCP) and abstracts different databases.
- Template Engine Module: Implements template processing with support for both Freemarker and Velocity to generate output in multiple formats.
- Metadata and Mapping Module: Responsible for converting database structures (tables, columns, keys) into internal models.
- Processing Module: Orchestrates the overall flow. It receives configuration, fetches metadata and data using the Query Module, and finally produces the documentation using the Template Engine.
- Exception and Utility Modules: Provide helpers and error handling throughout the process.
3. Integration Layer (screw-maven-plugin):
- A thin wrapper around the core engine that is invoked during a Maven build lifecycle.
- It passes configuration details from the pom.xml to the core engine and triggers documentation generation.
4. Web Dashboard (secrw-dashboard):
- Acts as a frontend/UI layer.
- Likely built with Spring Boot wrapping the core functionalities.
- Contains controllers, services, repository access, and static web content to interact with users.
- Data Flow / Interactions:
- Clients (or the Maven plugin dashboard) supply configuration parameters and initialize the documentation generation process.
- The core engine queries the database metadata using a database-specific Query implementation.
- The retrieved metadata is mapped to internal models and then passed to the processing module.
- The Processing module calls one of the Template Engine modules which uses the chosen templates (either Freemarker or Velocity) to generate the formatted documentation.
- Finally, the output (HTML, Word, Markdown) is saved to a specified location and optionally displayed or served via the dashboard.
- Technologies and Frameworks:
- Java (minimum JDK 1.8) and Maven for building.
- HikariCP for database connection pooling.
- Template libraries: Freemarker and Velocity.
- Spring Boot components in the dashboard module.
- Various database drivers as dependencies (MySQL, Oracle, etc.).

##### Special Points to Emphasize
- To capture the modular design. For example, list out each supported database query implementation as part of the “Database Query” component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    ClientAPI["Client Application"]:::client

    %% Integration Layers
    mavenPlugin["Maven Plugin Wrapper"]:::plugin
    dashboard["Web Dashboard"]:::dashboard

    %% Documentation Output
    output["Documentation Output"]:::output

    %% Screw Core Subsystem
    subgraph "Screw Core"
        config["Configuration"]:::core
        engineConfig["Engine Config"]:::core
        dbQuery["Database Query Module"]:::core
        metadata["Metadata Models"]:::core
        mapping["Mapping Module"]:::core
        processing["Processing Module"]:::core
        freemarker["Freemarker Engine"]:::core
        velocity["Velocity Engine"]:::core
        exception["Exception Handling"]:::core
        utility["Utility Module"]:::core
    end

    %% Relationships from External Sources to Screw Core
    ClientAPI -->|"configures"| config
    ClientAPI -->|"configures"| engineConfig
    ClientAPI -->|"invokes"| mavenPlugin
    ClientAPI -->|"invokes"| dashboard

    mavenPlugin -->|"calls"| processing
    dashboard   -->|"calls"| processing

    %% Internal Screw Core Flow
    config -->|"feeds"| processing
    engineConfig -->|"feeds"| processing
    dbQuery -->|"fetches"| metadata
    metadata -->|"maps to"| mapping
    mapping -->|"supplies"| processing
    processing -->|"generates via"| freemarker
    processing -->|"generates via"| velocity
    freemarker -->|"produces"| output
    velocity -->|"produces"| output
    processing -->|"handles"| exception
    processing -->|"assists via"| utility

    %% Styles
    classDef client fill:#FFDD57,stroke:#333,stroke-width:2px;
    classDef core fill:#ACE,stroke:#333,stroke-width:2px;
    classDef plugin fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef dashboard fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef output fill:#F0F4C3,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mappings
    click config "https://github.com/yesnomore/screw/blob/master/screw-core/src/main/java/cn/smallbun/screw/core/Configuration.java"
    click engineConfig "https://github.com/yesnomore/screw/blob/master/screw-core/src/main/java/cn/smallbun/screw/core/engine/EngineConfig.java"
    click freemarker "https://github.com/yesnomore/screw/blob/master/screw-core/src/main/java/cn/smallbun/screw/core/engine/freemark/FreemarkerTemplateEngine.java"
    click velocity "https://github.com/yesnomore/screw/blob/master/screw-core/src/main/java/cn/smallbun/screw/core/engine/velocity/VelocityTemplateEngine.java"
    click metadata "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/metadata/model"
    click mapping "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/mapping"
    click processing "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/process"
    click dbQuery "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/query"
    click exception "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/exception"
    click utility "https://github.com/yesnomore/screw/tree/master/screw-core/src/main/java/cn/smallbun/screw/core/util"
    click mavenPlugin "https://github.com/yesnomore/screw/blob/master/screw-maven-plugin/src/main/java/cn/smallbun/screw/maven/plugin/mojo/RunDocMojo.java"
    click dashboard "https://github.com/yesnomore/screw/tree/master/secrw-dashboard/src/main/java/cn/smallbun/screw/dashboard"
```
