# sun0lee/del_gesg_nh architecture

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

- Interactive diagram: https://gitdiagram.com/sun0lee/del_gesg_nh
- Repository: https://github.com/sun0lee/del_gesg_nh

## Overview

##### Project type and purpose
- This is a standalone Java/Maven batch ETL application for financial risk curves (ESG) computations.
- It uses Hibernate (ORM) to read/write from a relational database, applies quantitative models, and exports results (e.g., CSV).

##### File structure
- Top-level layers in src/com/gof:
– process: orchestrator classes (Main.java, Process.java, EsgXXX job steps)
– dao: data access layer (Hibernate DAOs)
– entity: JPA/Hibernate entity definitions
– model: quantitative model implementations (Nelson-Siegel, CIR, Smith‐Wilson, etc.)
– annotation: custom annotations (ToCsv, ToCsvMethod) to mark outputs for CSV export
– util: shared utilities (HibernateUtil, FileUtils, DateUtil, ReflectionUtil, etc.)
- Configuration files: hibernate.cfg.xml, log4j2.xml, gesg.properties.
- Build: pom.xml (Maven), .gitignore.

##### (minimal) README
- No details beyond “aa.” Rely on the code structure to infer that Main → Process → individual Esg*** classes form a sequence of batch jobs.

##### Main components and interactions
a. Components
1. Client/Scheduler – triggers Main (command-line or cron).
2. Main & Process Engine – bootstraps Hibernate, logging, loads properties, iterates through configured EsgXXX jobs.
3. DAO Layer – CoEsgMetaDao, IrCurveDao, etc., use Hibernate sessions to fetch/persist Entity objects.
4. Domain Entities – JPA-annotated classes representing database tables.
5. Business Logic/Model Layer – implements financial models (AFNelsonSiegel, CIRSimulationForcast, SmithWilson*, etc.).
6. Annotation Processor – ReflectionUtil reads @ToCsv annotations on entities/methods to export CSV files.
7. Utilities – common functions (file I/O, date math, encryption, logging).
8. External Systems – RDBMS, file system for scripts and CSV outputs.

b. Relationships & data flow
- Main → initializes HibernateUtil → opens SessionFactory → instantiates Process.
- Process → iterates through EsgXXX job classes in a configured order.
- Each job → calls DAO methods → retrieves Entity data → passes to Model classes → computes results → wraps into Entity objects → DAO persists or writes via ToCsv.
- Utilities support logging, file export, math routines.

c. Architectural patterns/design principles
- Layered architecture: Presentation (CLI), Orchestration, DAO, Domain Model, Utility.
- DAO pattern with Hibernate (ORM).
- Annotation-driven CSV export (custom annotation + reflection).
- Single-threaded batch pipeline (Process class as a command dispatcher).
- Configuration externalization (XML, properties files).

d. Key technologies/frameworks
- Java 8+
- Maven for build and dependency management
- Hibernate (hibernate.cfg.xml) for ORM
- Log4j2 for logging
- Custom Java annotations for export
- JUnit/TestNG for DbTest
- SQL scripts under “table script”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Trigger
    CLI["CLI/Scheduler"]:::external
    CLI --> Main

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Main["Main (Entry)"]:::orches
        Process["Process Engine"]:::orches
    end
    click Main "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/process/Main.java"
    click Process "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/process/Process.java"

    %% Batch Jobs
    subgraph "Batch Jobs"
        Esg120["Esg120_SetVolSwpn"]:::jobs
        Esg130["Esg130_SetYtm"]:::jobs
    end
    click Esg120 "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/process/Esg120_SetVolSwpn.java"
    click Esg130 "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/process/Esg130_SetYtm.java"

    %% DAO Layer
    subgraph "DAO Layer"
        CoEsgMetaDao["CoEsgMetaDao"]:::dao
        IrCurveDao["IrCurveDao"]:::dao
        IrCurveSpotDao["IrCurveSpotDao"]:::dao
    end
    click CoEsgMetaDao "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/dao/CoEsgMetaDao.java"
    click IrCurveDao "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/dao/IrCurveDao.java"
    click IrCurveSpotDao "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/dao/IrCurveSpotDao.java"

    %% Domain Entities
    subgraph "Domain Entities"
        CoEsgMetaEnt["CoEsgMeta"]:::entity
        IrCurveEnt["IrCurve"]:::entity
        IrCurveSpotEnt["IrCurveSpot"]:::entity
    end
    click CoEsgMetaEnt "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/entity/CoEsgMeta.java"
    click IrCurveEnt "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/entity/IrCurve.java"
    click IrCurveSpotEnt "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/entity/IrCurveSpot.java"

    %% Model Layer
    subgraph "Model Layer"
        AFNS["AFNelsonSiegel"]:::model
        CIR["CIRSimulationForcast"]:::model
        SW["SmithWilsonKics"]:::model
    end
    click AFNS "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/model/AFNelsonSiegel.java"
    click CIR "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/model/CIRSimulationForcast.java"
    click SW "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/model/SmithWilsonKics.java"

    %% Model Entity Subpackage
    subgraph "Model Entities"
        SWRslt["SmithWilsonRslt"]:::modelEnt
        IrModelSce["IrModelSce"]:::modelEnt
    end
    click SWRslt "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/model/entity/SmithWilsonRslt.java"
    click IrModelSce "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/model/entity/IrModelSce.java"

    %% Annotations & Utilities
    subgraph "Annotations & Utilities"
        ToCsv["ToCsv"]:::anno
        ToCsvM["ToCsvMethod"]:::anno
        ReflectionUtil["ReflectionUtil"]:::util
        HibernateUtil["HibernateUtil"]:::util
        FileUtils["FileUtils"]:::util
        DateUtil["DateUtil"]:::util
        MathUtil["MathUtil"]:::util
        StreamUtil["StreamUtil"]:::util
    end
    click ToCsv "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/annotation/ToCsv.java"
    click ToCsvM "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/annotation/ToCsvMethod.java"
    click ReflectionUtil "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/ReflectionUtil.java"
    click HibernateUtil "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/HibernateUtil.java"
    click FileUtils "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/FileUtils.java"
    click DateUtil "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/DateUtil.java"
    click MathUtil "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/MathUtil.java"
    click StreamUtil "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/util/StreamUtil.java"

    %% Configuration Artifacts
    subgraph "Configuration"
        Hbcfg["hibernate.cfg.xml"]:::config
        Log4j["log4j2.xml"]:::config
        Props["gesg.properties"]:::config
        POM["pom.xml"]:::config
    end

    %% Test Suite
    DbTest["DbTest (Test Suite)"]:::test
    click DbTest "https://github.com/sun0lee/del_gesg_nh/blob/master/src/com/gof/test/DbTest.java"

    %% External Systems
    ExternalDB[(RDBMS)]:::external
    FileSys[(File System)]:::external

    %% Data Flow
    Main -->|"init logging"| Log4j
    Main -->|"init ORM"| HibernateUtil
    Main --> Process
    Process --> Esg120
    Process --> Esg130
    Esg120 --> CoEsgMetaDao
    Esg120 --> IrCurveDao
    Esg120 -->|"fetch metadata"| CoEsgMetaEnt
    Esg120 --> AFNS
    AFNS --> IrModelSce
    IrModelSce --> IrCurveDao
    Esg120 --> ToCsvM
    ToCsvM --> FileSys
    CoEsgMetaDao --> ExternalDB
    IrCurveDao --> ExternalDB
    IrCurveSpotDao --> ExternalDB

    DbTest --> HibernateUtil
    DbTest --> ExternalDB

    Hbcfg --> Main
    Props --> Main

    %% Styles
    classDef orches fill:#f9f,stroke:#333,stroke-width:2px
    classDef jobs fill:#ff9,stroke:#333
    classDef dao fill:#9ff,stroke:#333
    classDef entity fill:#9f9,stroke:#333
    classDef model fill:#f99,stroke:#333
    classDef modelEnt fill:#fdd,stroke:#333
    classDef anno fill:#ddd,stroke:#333
    classDef util fill:#ccc,stroke:#333
    classDef config fill:#eef,stroke:#333,stroke-dasharray: 5 5
    classDef test fill:#eef,stroke:#333,stroke-dasharray: 2 2
    classDef external fill:#fee,stroke:#333,stroke-dasharray: 4 2
```
