# hyphae/apis-web architecture

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

- Interactive diagram: https://gitdiagram.com/hyphae/apis-web
- Repository: https://github.com/hyphae/apis-web

## Overview

##### Project type and purpose
- apis-web is a Java‐based backend service (no UI) that exposes HTTP APIs to supply power-interchange and hardware status data.
- It uses Vert.x for a non-blocking HTTP server and Hazelcast for clustering.
- It connects to multiple apis-main nodes (Grid Master + members) to gather DC/DC converter, battery RSoC, and power-interchange info.
- It also includes “emulator” modules for generating test deals and errors.

##### File structure to derive components
- src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/ApiServer.java
→ The Vert.x HTTP server entry point
- src/main/java/.../api_handler/DealGeneration, ErrorGeneration, LogConfiguration
→ Core business‐logic handlers for specific endpoints
- src/main/java/.../web/BudoEmulator.java & EmulatorEmulator.java
→ Modules that simulate/generate test data
- src/main/resources + exe/
→ Configuration files (config.json, cluster.xml) and start/stop scripts
- pom.xml & assembly scripts
→ Build/distribution pipeline (Maven assembly to bundle exe/)

##### README for architectural clues
- Describes a cluster formed by Vert.x + Hazelcast to talk to multiple apis-main nodes
- Caller is a “Web service (visualization, etc.)” that hits apis-web’s HTTP endpoints
- Configurable via JSON/XML in the exe folder

##### Main components
a. External Client(s)
– Web UI / Visualization Service / CLI
b. apis-web API Server (Vert.x)
– Vert.x Event Loop & HTTP Router
– Loads config.json & cluster.xml at startup
c. API Handlers (DealGeneration, ErrorGeneration, LogConfiguration)
d. Emulator Modules (BudoEmulator, EmulatorEmulator)
e. Cluster Manager (Hazelcast instance)
f. External apis-main Node Cluster
– Grid Master + worker nodes on Ethernet
g. Build & Deployment
– Maven / Groovy scripts, assembly plugin, exe folder with start.sh / stop.sh

##### Relationships and data flow
- Client → HTTP request → ApiServer
- ApiServer → routes to appropriate API Handler or Emulator
- Handler → invokes Cluster Manager APIs to fetch data from apis-main nodes
- Cluster Manager ↔ Hazelcast network calls ↔ apis-main Node Cluster
- Handler responses → ApiServer → back to Client
- Emulators can bypass real nodes and generate synthetic data for debug
- Configuration files feed both ApiServer and Cluster Manager on startup

##### Highlighted architectural patterns
- Reactive, non-blocking HTTP layer (Vert.x)
- Peer-to-peer clustering (Hazelcast) for service discovery & data distribution
- Modular handler pattern for each API endpoint
- Externalized configuration for easy re-deployment
- Assembly/distribution via Maven assembly plugin and shell scripts

##### Final checklist
- [ ] All main components included and labeled
- [ ] Configuration sources and build/deploy scripts shown
- [ ] Call out protocols (HTTP, Hazelcast messaging) explicitly

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["External Client(s)"]:::external

    %% apis-web Cluster
    subgraph "apis-web Service" 
        direction TB
        ApiServer["Vert.x HTTP Server"]:::core
        Starter["Starter Utility"]:::core

        subgraph "API Handlers" 
            direction TB
            DealGen["DealGeneration Handler"]:::core
            ErrGen["ErrorGeneration Handler"]:::core
            LogConf["LogConfiguration Handler"]:::core
        end

        subgraph "Emulator Modules"
            direction TB
            BudoEmu["BudoEmulator"]:::core
            EmuEmu["EmulatorEmulator"]:::core
        end
    end

    %% Cluster Manager and external cluster
    subgraph "Cluster Layer"
        direction TB
        Hazelcast["Hazelcast Instance"]:::core
        ExtCluster["apis-main Node Cluster"]:::external
    end

    %% Configuration & Scripts
    subgraph "Config & Scripts"
        direction TB
        ConfigJSON["config.json"]:::config
        ClusterXML["cluster.xml"]:::config
        StartSh["start.sh"]:::config
        StopSh["stop.sh"]:::config
        KillSh["kill.sh"]:::config
        StopKillSh["stop-kill.sh"]:::config
        CertPem["cert.pem / key.pem"]:::config
        SampleConfig["sample-config.json"]:::config
        VertxLog["vertx-default-jul-logging.properties"]:::config
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment"
        direction TB
        POM["pom.xml"]:::pipeline
        DistXML["distribution.xml"]:::pipeline
        AntBuild["build.xml"]:::pipeline
        Makefile["Makefile"]:::pipeline
        Groovy["generateVerifyInfo.groovy"]:::pipeline
    end

    %% Data Flows
    Client -->|HTTP Request| ApiServer
    ApiServer -->|routes to| DealGen
    ApiServer -->|routes to| ErrGen
    ApiServer -->|routes to| LogConf
    ApiServer -->|routes to| BudoEmu
    ApiServer -->|routes to| EmuEmu

    DealGen -->|uses| Hazelcast
    ErrGen -->|uses| Hazelcast
    LogConf -->|uses| Hazelcast

    BudoEmu -->|generates synthetic data| ApiServer
    EmuEmu -->|generates synthetic data| ApiServer

    Hazelcast -->|Hazelcast TCP| ExtCluster
    Starter -->|initializes| ApiServer
    Starter -->|initializes| Hazelcast

    %% Config flows
    StartSh -.->|executes| Starter
    StartSh -.->|loads| ConfigJSON
    StartSh -.->|loads| ClusterXML
    StartSh -.->|loads| CertPem

    %% Build flows
    POM -->|Maven build| DistXML
    AntBuild -->|legacy build| Makefile
    Groovy -->|verification| Makefile

    %% Click Events
    click ApiServer "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/ApiServer.java"
    click DealGen "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/api_handler/DealGeneration.java"
    click ErrGen "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/api_handler/ErrorGeneration.java"
    click LogConf "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/api_handler/LogConfiguration.java"
    click BudoEmu "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/BudoEmulator.java"
    click EmuEmu "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/EmulatorEmulator.java"
    click Starter "https://github.com/hyphae/apis-web/blob/master/src/main/java/jp/co/sony/csl/dcoes/apis/tools/web/util/Starter.java"
    click ConfigJSON "https://github.com/hyphae/apis-web/blob/master/exe/config.json"
    click ClusterXML "https://github.com/hyphae/apis-web/blob/master/exe/cluster.xml"
    click StartSh "https://github.com/hyphae/apis-web/blob/master/exe/start.sh"
    click StopSh "https://github.com/hyphae/apis-web/blob/master/exe/stop.sh"
    click KillSh "https://github.com/hyphae/apis-web/blob/master/exe/kill.sh"
    click StopKillSh "https://github.com/hyphae/apis-web/blob/master/exe/stop-kill.sh"
    click CertPem "https://github.com/hyphae/apis-web/blob/master/exe/cert.pem"
    click SampleConfig "https://github.com/hyphae/apis-web/blob/master/src/main/resources/sample-config.json"
    click VertxLog "https://github.com/hyphae/apis-web/blob/master/src/main/resources/vertx-default-jul-logging.properties"
    click POM "https://github.com/hyphae/apis-web/blob/master/pom.xml"
    click DistXML "https://github.com/hyphae/apis-web/blob/master/src/main/assembly/distribution.xml"
    click AntBuild "https://github.com/hyphae/apis-web/blob/master/build.xml"
    click Makefile "https://github.com/hyphae/apis-web/tree/master/Makefile"
    click Groovy "https://github.com/hyphae/apis-web/blob/master/generateVerifyInfo.groovy"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#0366d6,stroke-width:2px
    classDef external fill:#DDFFDD,stroke:#228B22,stroke-width:2px
    classDef config fill:#FFECD1,stroke:#DD8800,stroke-width:2px
    classDef pipeline fill:#F3E6FF,stroke:#8A2BE2,stroke-width:2px
```
