# line/line-bot-sdk-java architecture

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

- Interactive diagram: https://gitdiagram.com/line/line-bot-sdk-java
- Repository: https://github.com/line/line-bot-sdk-java

## Overview

This project is a multi‐module Java SDK that supports the integration of LINE Messaging API services. The project is highly modular and uses Gradle (with build.gradle.kts files, buildSrc, etc.) to coordinate many distinct client components that encapsulate various parts of the LINE API (messaging API client, insight client, manage audience client, module attach, shop client, channel access token client, liff client, and so on) as well as additional components that support the parsing of webhook events, Spring Boot integration, and even code generation based on the OpenAPI specification.

##### Main Components
- Client Modules: Represent the core client libraries that interface with LINE APIs. For example, include:
- Messaging API Client (line-bot-messaging-api-client)
- Insight Client (line-bot-insight-client)
- Manage Audience Client (line-bot-manage-audience-client)
- Module Attach and Module Client (line-bot-module-attach-client, line-bot-module-client)
- Shop Client (line-bot-shop-client)
- Channel Access Token Client (line-channel-access-token-client)
- LIFF Client (line-liff-client)
- Webhook and Parser Modules:
- Webhook module (line-bot-webhook)
- Parser module (line-bot-parser)
- Jackson integration (line-bot-jackson)
- Spring Boot Integration Modules:
- These include the various Spring Boot support libraries found under spring-boot (line-bot-spring-boot-client, line-bot-spring-boot-handler, line-bot-spring-boot-web, line-bot-spring-boot-webmvc). They enable rapid development of bot applications within the Spring Boot ecosystem.
- Code Generation / SDK Generator:
- The ‘generator’ folder houses the code generator components (using OpenAPI specs and Pebble templates) that automatically produce parts of the client code.
- Samples and Integration Tests:
- Samples (such as sample-spring-boot-echo, sample-spring-boot-kitchensink, sample-manage-audience) and tests demonstrate how the SDK is used and verify functionality.
- Build and Infrastructure:
- Gradle scripts, GitHub workflows, and configuration files (e.g. .github, gradle.properties, etc.) that facilitate CI/CD, code validation, and the overall building of each module.

##### Relationships and Interactions
- That the sample projects rely on the client libraries (and Spring Boot modules where applicable) as well as integration test components.
- That the code generation module feeds into the client libraries by generating portions of the code or code templates.
- Data-flow direction:
- Outbound from a bot application (using Spring Boot framework or a plain Java application): building requests (e.g. reply, push, broadcast), sending them to the LINE API endpoints, and processing responses (including error handling using exception types provided by individual clients).
- Inbound webhook events are parsed by the parser and then routed to application modules such as those in the Spring Boot handler modules.

##### Architectural Patterns and Design Principles
- OpenAPI Code Generation: Emphasize that the design leverages an automated code generation workflow (located in the ‘generator’ directory) to quickly adapt to changes in the LINE API specifications.

##### Elements
- Optionally incorporate notes on exception/error handling flows, especially how request IDs and error details are captured from API responses.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Build and Infrastructure"
        build["Build and Infrastructure\n(build.gradle.kts, buildSrc, .github)"]:::build
    end

    subgraph "Code Generation"
        codeGen["Code Generation / SDK Generator"]:::generator
    end

    subgraph "API Clients"
        msg["Messaging API Client\n(Core messaging functionalities)"]:::client
        insight["Insight Client\n(Usage insights)"]:::client
        manage["Manage Audience Client\n(Audience management)"]:::client
        modAttach["Module Attach Client\n(Module attachment)"]:::client
        modClient["Module Client\n(General module operations)"]:::client
        shop["Shop Client\n(Shop services)"]:::client
        channel["Channel Access Token Client\n(Token management)"]:::client
        liff["LIFF Client\n(LIFF operations)"]:::client
    end

    subgraph "Webhook & Parser"
        webhook["Webhook Module\n(Receives webhook events)"]:::webhook
        parser["Parser Module\n(Parses webhook events)"]:::webhook
        jackson["Jackson Integration\n(JSON processing)"]:::webhook
    end

    subgraph "Spring Boot Integration"
        springClient["Spring Boot Client Integration\n(Integrates client support)"]:::spring
        springHandler["Spring Boot Handler Integration\n(Handles webhook events)"]:::spring
        springWeb["Spring Boot Web Integration\n(Web endpoints support)"]:::spring
        springWebMVC["Spring Boot WebMVC Integration\n(MVC pattern support)"]:::spring
    end

    subgraph "Samples & Tests"
        samples["Samples\n(Demo applications)"]:::sample
        integrationTests["Integration Tests\n(Validates functionality)"]:::sample
        botApp["Bot Application\n(Example bot using SDK)"]:::sample
    end

    external["LINE Server\n(External LINE API)"]:::external

    %% Dependencies and Data Flow
    build --> codeGen
    build --> msg
    build --> webhook
    build --> springClient
    build --> samples

    codeGen -->|"generates"| msg

    springWebMVC -->|"depends"| msg
    springWebMVC -->|"uses"| webhook
    springHandler -->|"integrates"| parser
    springClient -->|"calls"| msg
    springHandler -->|"depends"| msg

    botApp -->|"calls"| msg
    msg -->|"calls"| external
    webhook -->|"parses"| botApp

    samples -->|"uses"| msg
    samples -->|"uses"| springClient
    integrationTests -->|"tests"| msg
    integrationTests -->|"tests"| springHandler

    %% Click Events
    click msg "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-messaging-api-client"
    click insight "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-insight-client"
    click manage "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-manage-audience-client"
    click modAttach "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-module-attach-client"
    click modClient "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-module-client"
    click shop "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-bot-shop-client"
    click channel "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-channel-access-token-client"
    click liff "https://github.com/line/line-bot-sdk-java/tree/master/clients/line-liff-client"
    click webhook "https://github.com/line/line-bot-sdk-java/tree/master/line-bot-webhook"
    click parser "https://github.com/line/line-bot-sdk-java/tree/master/line-bot-parser"
    click jackson "https://github.com/line/line-bot-sdk-java/tree/master/line-bot-jackson"
    click springClient "https://github.com/line/line-bot-sdk-java/tree/master/spring-boot/line-bot-spring-boot-client"
    click springHandler "https://github.com/line/line-bot-sdk-java/tree/master/spring-boot/line-bot-spring-boot-handler"
    click springWeb "https://github.com/line/line-bot-sdk-java/tree/master/spring-boot/line-bot-spring-boot-web"
    click springWebMVC "https://github.com/line/line-bot-sdk-java/tree/master/spring-boot/line-bot-spring-boot-webmvc"
    click codeGen "https://github.com/line/line-bot-sdk-java/tree/master/generator"
    click samples "https://github.com/line/line-bot-sdk-java/tree/master/samples"
    click integrationTests "https://github.com/line/line-bot-sdk-java/tree/master/line-bot-integration-test"
    click build "https://github.com/line/line-bot-sdk-java/blob/master/build.gradle.kts"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef webhook fill:#ABEBC6,stroke:#1D8348,stroke-width:2px;
    classDef spring fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef generator fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef sample fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px;
    classDef build fill:#FAD7A0,stroke:#CA6F1E,stroke-width:2px;
    classDef external fill:#D5DBDB,stroke:#7F8C8D,stroke-width:2px;
```
