# javanance/gcfg architecture

> Architecture diagram of the GitHub repository javanance/gcfg, 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/javanance/gcfg
- Repository: https://github.com/javanance/gcfg

## Overview

##### Project type and purpose
- This is a backend Java batch‐style application for financial asset valuation under the KICS framework.
- It reads market data and KICS asset records from a relational database, runs interest‐rate scenario models (Nelson‐Siegel, Smith‐Wilson), prices various instruments (bonds, loans, derivatives), and writes valuation results back to the database.

##### File structure
- Top‐level “src/com/gof” packages map directly to logical layers:
- dao (data access objects using Hibernate)
- entity (JPA‐mapped domain objects)
- enums (domain‐specific enumerations)
- instrument (pricing implementations per instrument type)
- irmodel (IR scenario generators)
- process (Main entrypoints and orchestration)
- util (common utilities: math, file, Hibernate session, logging)
- Configuration files: hibernate.cfg.xml, log4j2.xml under src/ and bin/
- pom.xml for Maven build; secr.properties for secrets
- bin/ and target/ contain compiled classes and property files for runtime.

##### README for additional insights
- Minimal description: “Asset Valuation under KICS”, version HK_2023, changes for FRN and KTB Forward.

a. Main components:
- External RDBMS (KICS asset tables, interest‐rate curves, reference rates)
- Data Access Layer (com.gof.dao + HibernateUtil)
- Domain Model (JPA Entities in com.gof.entity + com.gof.enums)
- Business Logic Layer:
– IR Model Engines (com.gof.irmodel: Nelson‐Siegel, Smith‐Wilson)
– Instrument Pricing (com.gof.instrument: bonds, loans, derivatives)
– Utilities (com.gof.util: math, RNG, file I/O, logging)
- Orchestration Layer (com.gof.process: Main.java)
- External Tools/Services (optional R integration via RScriptData, file system)
b. Relationships and interactions:
– Main process starts → uses DAO to read entities → passes data to IRModel → generates scenarios → passes scenarios and entities to Instrument classes → calculates valuations → uses DAO to persist results → logs progress via Log4J → optionally invokes R scripts.
– HibernateUtil manages session/transaction to RDBMS.
c. Architectural patterns and principles:
– Layered architecture: Persistence (DAO + Entities), Service/Domain (IR models + instruments + utils), Orchestration (process).
– Use of Dependency Injection via Hibernate configuration (PhysicalNamingStrategy)
– Separation of concerns: each instrument or model implements a common interface.
d. Technologies, frameworks, and libraries:
– Java (JDK 8+), Maven
– Hibernate ORM (hibernate.cfg.xml)
– Log4J2 for logging
– JUnit/Test classes under com.gof.test
– Optional R integration (com.gof.test.RScriptData)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global components
    Database[(External RDBMS)]:::external

    subgraph "Configuration"
        CFG1["hibernate.cfg.xml"]:::config
        CFG2["log4j2.xml"]:::config
        CFG3["pom.xml"]:::config
        CFG4["secr.properties"]:::config
    end

    subgraph "Persistence Layer"
        DAO["DAO Layer\n(src/com/gof/dao)"]:::persistence
        HU["HibernateUtil\n(src/com/gof/util/HibernateUtil.java)"]:::persistence
    end

    subgraph "Domain Model"
        ENT["Entities\n(src/com/gof/entity)"]:::domain
        ENM["Enums\n(src/com/gof/enums)"]:::domain
    end

    subgraph "Business Logic Layer"
        IRM["IR Models\n(src/com/gof/irmodel)"]:::domain
        INS["Instrument Pricing\n(src/com/gof/instrument)"]:::domain
        UTIL["Utilities\n(src/com/gof/util)"]:::domain
    end

    subgraph "Orchestration Layer"
        MAIN["Main Processes\n(src/com/gof/process)"]:::orchestration
    end

    subgraph "External/Test Tools"
        RINT["RScriptData\n(src/com/gof/test/RScriptData.java)"]:::external
        TEST["Test Harness\n(src/com/gof/test)"]:::external
    end

    %% Workflow
    CFG1 -->|"configures"| HU
    CFG2 -->|"configures logging"| MAIN
    MAIN -->|"reads/writes"| DAO
    DAO -->|"queries"| Database
    HU -->|"manages session"| Database
    MAIN -->|"loads entities"| ENT
    MAIN -->|"uses enums"| ENM
    MAIN -->|"runs models"| IRM
    MAIN -->|"prices instruments"| INS
    MAIN -->|"uses utilities"| UTIL
    MAIN -->|"invokes"| RINT
    MAIN -->|"runs tests"| TEST

    DAO -->|"populates"| ENT
    IRM -->|"uses entities & utils"| ENT
    IRM -->|"uses utilities"| UTIL
    INS -->|"uses entities & utils"| ENT
    INS -->|"uses utilities"| UTIL

    %% Click Events
    click DAO "https://github.com/javanance/gcfg/tree/main/src/com/gof/dao"
    click HU "https://github.com/javanance/gcfg/blob/main/src/com/gof/util/HibernateUtil.java"
    click ENT "https://github.com/javanance/gcfg/tree/main/src/com/gof/entity"
    click ENM "https://github.com/javanance/gcfg/tree/main/src/com/gof/enums"
    click IRM "https://github.com/javanance/gcfg/tree/main/src/com/gof/irmodel"
    click INS "https://github.com/javanance/gcfg/tree/main/src/com/gof/instrument"
    click UTIL "https://github.com/javanance/gcfg/tree/main/src/com/gof/util"
    click MAIN "https://github.com/javanance/gcfg/tree/main/src/com/gof/process"
    click RINT "https://github.com/javanance/gcfg/blob/main/src/com/gof/test/RScriptData.java"
    click TEST "https://github.com/javanance/gcfg/tree/main/src/com/gof/test"
    click CFG1 "https://github.com/javanance/gcfg/blob/main/src/hibernate.cfg.xml"
    click CFG2 "https://github.com/javanance/gcfg/blob/main/src/log4j2.xml"
    click CFG3 "https://github.com/javanance/gcfg/blob/main/pom.xml"
    click CFG4 "https://github.com/javanance/gcfg/blob/main/secr.properties"

    %% Styles
    classDef persistence fill:#e0f7fa,stroke:#0277bd,color:#000;
    classDef domain fill:#e8f5e9,stroke:#2e7d32,color:#000;
    classDef orchestration fill:#fff3e0,stroke:#ef6c00,color:#000;
    classDef config fill:#eceff1,stroke:#607d8b,color:#000;
    classDef external fill:#f3e5f5,stroke:#6a1b9a,color:#000;
```
