# washmore/batchhacker architecture

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

- Interactive diagram: https://gitdiagram.com/washmore/batchhacker
- Repository: https://github.com/washmore/batchhacker

## Overview

##### Project type and purpose
- This is an open-source Java utility library (jar) called BatchHacker.
- Its goal is to transparently intercept and split large batch operations (lists/maps) so you never exceed MyBatis’s 2,100-parameter limit (or overwhelm any database) without touching existing business code.

##### File structure
- Top-level files:
- pom.xml → Maven coordinates & build config
- readme.md → usage guide
- src/main/java/tech/washmore/util/batchhacker → core interceptor + annotations
- Resources:
- src/main/resources/batchhacker/spring-aop.xml → AOP bean definitions
- No UI, no controllers, no REST endpoints—this is purely a library injected into a host Spring application.

##### README for insights
- Describes two integration modes: XML import of spring-aop.xml or @ImportResource in a SpringBoot starter.
- Annotation-driven: @BatchHacker on methods, optional @BatchHackerParam on specific List parameters.
- Runtime behavior: intercept method call, split input list(s) into sub-lists, invoke original logic multiple times, aggregate results.

a. Host Application (Spring Container)
- Your business Service or DAO class (with methods annotated @BatchHacker)
- spring-aop config or @ImportResource registering BatchHackerInterceptor bean
b. BatchHacker Library
- BatchHackerInterceptor (Spring AOP Advice)
- Annotation definitions: @BatchHacker, @BatchHackerParam
c. Underlying Persistence Layer
- MyBatis Mappers or JDBC template
- Database (e.g., Oracle, SQLServer, etc.)
d. (Optional) Maven Repository / Build
- Maven coordinates, artifact upload to nexus

##### Relationships & interactions
1. Client (other beans) calls a method in your Service/DAO annotated @BatchHacker.
2. Spring AOP proxy (created from spring-aop.xml) intercepts the call.
3. BatchHackerInterceptor reads annotation metadata, examines List/Map parameters.
4. It splits large collections into sub-lists of configurable size (<=2100).
5. For each sub-list, the interceptor invokes the original method on the target bean.
6. Those invocations flow into MyBatis (or JDBC) and hit the database as smaller batches.
7. Results (e.g., total inserted row counts) are aggregated, returned to the caller.

##### Architectural patterns & design principles
- AOP / Proxy pattern to weave in behavior without code changes
- Annotation-driven configuration for clarity & minimal intrusion
- Batch-split algorithm encapsulated in a single interceptor class
- Externalized configuration via spring-aop.xml

##### Relevant technologies/frameworks
- Java 8+
- Spring Framework (Core & AOP)
- MyBatis (or any JDBC‐based DAO)
- Maven for build & dependency management

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application
    subgraph "Host Application"
        direction TB
        Client["Client Bean"]:::hostapp
        SpringContainer["Spring Container"]:::hostapp
        Config["spring-aop.xml"]:::config
        Service["ServiceBean.method()\\n@BatchHacker"]:::hostapp
        Client -->|"calls method"| SpringContainer
        SpringContainer -->|"loads config"| Config
        SpringContainer -->|"creates proxy"| ServiceProxy
        ServiceProxy["ServiceBean (AOP Proxy)"]:::hostapp
        ServiceProxy -->|"invokes method"| Service
    end

    %% BatchHacker Library
    subgraph "BatchHacker Library"
        direction TB
        Interceptor["BatchHackerInterceptor"]:::lib
        Annotation1["@BatchHacker"]:::lib
        Annotation2["@BatchHackerParam"]:::lib
        ServiceProxy -->|"advice applied"| Interceptor
        Annotation1 --> Interceptor
        Annotation2 --> Interceptor
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        MyBatis["MyBatis Mapper"]:::persistence
        DB["Database"]:::db
        Interceptor -->|"split into sub-lists"| SplitLoop
        SplitLoop(("loop")):::lib
        SplitLoop -->|"invoke original method"| Service
        Service -->|"calls SQL"| MyBatis
        MyBatis -->|"executes batch"| DB
        DB -->|"returns results"| MyBatis
        MyBatis -->|"returns results"| Service
        Service -->|"aggregated result"| Interceptor
    end

    %% Build & Docs
    subgraph "Build & Documentation"
        direction TB
        POM["pom.xml"]:::doc
        README["readme.md"]:::doc
    end

    %% Click Events
    click Interceptor "https://github.com/washmore/batchhacker/blob/master/src/main/java/tech/washmore/util/batchhacker/BatchHackerInterceptor.java"
    click Annotation1 "https://github.com/washmore/batchhacker/blob/master/src/main/java/tech/washmore/util/batchhacker/annotation/BatchHacker.java"
    click Annotation2 "https://github.com/washmore/batchhacker/blob/master/src/main/java/tech/washmore/util/batchhacker/annotation/BatchHackerParam.java"
    click Config "https://github.com/washmore/batchhacker/blob/master/src/main/resources/batchhacker/spring-aop.xml"
    click POM "https://github.com/washmore/batchhacker/blob/master/pom.xml"
    click README "https://github.com/washmore/batchhacker/blob/master/readme.md"

    %% Styles
    classDef hostapp fill:#D6E9FE,stroke:#4A90E2,color:#000;
    classDef lib fill:#DFF0D8,stroke:#3C763D,color:#000;
    classDef persistence fill:#FCF8E3,stroke:#8A6D3B,color:#000;
    classDef db fill:#F2DEDE,stroke:#A94442,color:#000,shape:cylinder;
    classDef config fill:#F5F5F5,stroke:#999,color:#000,shape:rect;
    classDef doc fill:#EFEFEF,stroke:#666,color:#000;
```
