# seeongh/ttsengine architecture

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

- Interactive diagram: https://gitdiagram.com/seeongh/ttsengine
- Repository: https://github.com/seeongh/ttsengine

## Overview

##### Main Components
- Frontend / Web Presentation Layer:
- Represented by the controllers under the "src/main/java/com/kosaf/core/web" directory (e.g., for bbs, code, frequencyPhrases, log, member, menu, monitoring, replaceKeyword, ttsDemo).
- Indicates how web pages (HTML, CSS, JavaScript, JQuery code) interact with backend endpoints.
- API / Backend REST Layer:
- Components under "src/main/java/com/kosaf/core/api" (e.g., the different domain APIs such as TTS Demo, ReplaceKeyword, Log, Member, etc.) expose REST controllers (presentation sub-packages) for various functionalities.
- Application & Business Logic Layer:
- Located in subpackages called "application" under each module (for example, ttsDemo/application, frequencyPhrases/application, etc.). This layer contains services (e.g., RequestTTSRestService, FrequencyPhrasesService) that encapsulate business logic.
- Domain Layer:
- Contains entity definitions and domain objects (e.g., User, Author, Bbs, CodeDetail, ReplaceKw) that represent the core business data.
- Infrastructure / Persistence Layer:
- Consists of Mappers and repositories, found in "infrastructure" subpackages and mybatis XML configurations under "src/main/resources/mybatis". This is where the project interacts with databases such as ORACLE and POSTGRESQL.
- Batch Processing Component:
- Under "src/main/java/com/kosaf/core/batch", the batch jobs (e.g., SyncJob, SyncSchedular) use Spring Batch to synchronize data between the TTS engine server and the WAS DB.
- Cross-Cutting Concerns & Configurations:
- Security configurations (Spring Security, interceptors, authentication/authorization handlers).
- Exception handling (CustomException handling via CustomException classes and ResponseExceptionHandler).
- Logging (custom logging aspects under config/logging and dedicated controllers for log modules).
- WebClient configuration for external API communication.
- Tiles configuration for view templating.

##### Relationships and Interactions
- Users interact either via the browser (web controllers) or through mobile/desktop client calls to REST endpoints.
- The Web Presentation Layer and API REST Controllers serve as entry points, routing requests to corresponding application services.
- Application services coordinate with the Domain Layer (entities and business rules) and then interact with the Infrastructure layer (using mappers and repositories) for data persistence.
- Batch jobs run independently to sync data between the TTS engine server and the application's databases.
- Security, interceptors (e.g., AuthInterceptor, UserAuthInterceptor, WebLogInterceptor), and exception handlers are applied across multiple layers to enforce authentication, logging, and error handling.
- Outbound calls via WebClient allow the application to interact with external services (e.g., possibly calling the TTS engine API or other external systems).

##### Architectural Patterns and Design Principles
- Layered Architecture (Presentation → Application → Domain → Infrastructure).
- Domain-Driven Design (clear separation between domain, application, and infrastructure components).
- MVC Pattern within the web component (separation of controllers, views, and models).
- Use of interceptors for cross-cutting concerns (security, logging).
- Batch processing using Spring Batch for asynchronous synchronization.
- External API integration managed via WebClient.

##### Relevant Technologies and Frameworks
- Spring Boot, Spring Batch, Spring Security.
- Java as the primary language.
- Oracle and PostgreSQL for databases.
- MyBatis with XML mapping.
- Frontend tools: HTML, CSS, JavaScript, JQuery.
- Tiles for view templating.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    U["User/Browser"]:::user

    %% Frontend / Web Presentation Layer
    subgraph "Frontend / Web Presentation Layer"
        FE["Web Controllers"]:::frontend
        TDemo["TTSDemoController"]:::frontend
    end

    %% API / Backend REST Layer
    subgraph "API / Backend REST Layer"
        API["REST Controllers"]:::api
        ReqTTS["RequestTTSRestController"]:::api
        RKeyword["ReplaceKeywordRestController"]:::api
    end

    %% Application & Business Logic Layer
    subgraph "Application & Business Logic Layer"
        App["Application Services"]:::app
        ReqTTSService["RequestTTSRestService"]:::app
        FreqPhraseService["FrequencyPhrasesService"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Dom["Domain Entities"]:::domain
        Member["Member Entity"]:::domain
    end

    %% Infrastructure / Persistence Layer
    subgraph "Infrastructure / Persistence Layer"
        Infra["Mappers/Repositories"]:::infra
        BbsMapperJava["BbsMapper (Java)"]:::infra
        BbsMapperXML["BbsMapper (XML)"]:::infra
    end

    %% Batch Processing Component
    subgraph "Batch Processing Component"
        BatchJob["Batch Jobs"]:::batch
        SyncJob["SyncJob"]:::batch
        SyncSched["SyncSchedular"]:::batch
    end

    %% Cross-Cutting Concerns & Configurations
    subgraph "Cross-Cutting Concerns & Configurations"
        SecGroup["Security & Interceptors"]:::crosscut
        SecConfig["SecurityConfig"]:::crosscut
        Interceptors["Interceptors"]:::crosscut
        RespException["ResponseExceptionHandler"]:::crosscut
        SysLog["SysLogAspect"]:::crosscut
        WebClientCfg["WebClient Config"]:::crosscut
        TilesCfg["TilesConfig"]:::crosscut
    end

    %% External Systems
    subgraph "External Systems"
        TTS["External TTS Engine API"]:::external
        Oracle["Oracle DB"]:::database
        Postgres["PostgreSQL DB"]:::database
    end

    %% Relationships
    U -->|"HTTP"| TDemo
    U -->|"REST"| ReqTTS

    TDemo -->|"calls"| ReqTTSService
    ReqTTS -->|"calls"| ReqTTSService
    RKeyword -->|"calls"| ReqTTSService

    ReqTTSService -->|"business logic"| Dom
    FreqPhraseService -->|"business logic"| Dom

    Dom -->|"data access"| BbsMapperJava
    BbsMapperJava -->|"mapper call"| BbsMapperXML
    BbsMapperXML -->|"DB operation"| Oracle
    BbsMapperXML -->|"DB operation"| Postgres

    SyncJob -->|"sync data"| Oracle
    SyncJob -->|"sync data"| TTS
    SyncSched -->|"orchestrates"| SyncJob

    %% Cross cutting applied on Controllers and Services
    SecConfig --- TDemo
    SecConfig --- ReqTTS
    Interceptors --- TDemo
    Interceptors --- ReqTTS
    RespException --- TDemo
    RespException --- ReqTTS
    SysLog --- TDemo
    SysLog --- ReqTTS

    %% WebClient for external calls
    WebClientCfg -->|"calls"| TTS

    %% Tiles used for view templating in Frontend layer
    TDemo -->|"renders view via"| TilesCfg

    %% Click Events
    click FE "https://github.com/seeongh/ttsengine/tree/master/src/main/java/com/kosaf/core/web"
    click TDemo "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/web/ttsDemo/presentation/TTSDemoController.java"

    click API "https://github.com/seeongh/ttsengine/tree/master/src/main/java/com/kosaf/core/api"
    click ReqTTS "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/ttsDemo/presentation/RequestTTSRestController.java"
    click RKeyword "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/replaceKeyword/presentation/ReplaceKeywordRestController.java"

    click ReqTTSService "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/ttsDemo/application/RequestTTSRestService.java"
    click FreqPhraseService "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/frequencyPhrases/application/FrequencyPhrasesService.java"

    click Member "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/member/domain/Member.java"

    click BbsMapperJava "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/api/bbs/infrastructure/BbsMapper.java"
    click BbsMapperXML "https://github.com/seeongh/ttsengine/blob/master/src/main/resources/mybatis/mapper/bbs/BbsMapper.xml"

    click SyncJob "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/batch/application/core/SyncJob.java"
    click SyncSched "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/batch/application/core/SyncSchedular.java"

    click SecConfig "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/config/security/SecurityConfig.java"
    click Interceptors "https://github.com/seeongh/ttsengine/tree/master/src/main/java/com/kosaf/core/config/interceptor"
    click RespException "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/config/exception/ResponseExceptionHandler.java"
    click SysLog "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/config/logging/SysLogAspect.java"

    click WebClientCfg "https://github.com/seeongh/ttsengine/tree/master/src/main/java/com/kosaf/core/config/webClient"
    click TilesCfg "https://github.com/seeongh/ttsengine/blob/master/src/main/java/com/kosaf/core/config/tiles/TilesConfig.java"

    %% Styles
    classDef user fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef app fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef domain fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFD580,stroke:#333,stroke-width:2px;
    classDef batch fill:#D8BFD8,stroke:#333,stroke-width:2px;
    classDef crosscut fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef database fill:#FF9999,stroke:#333,stroke-width:2px;
```
