# Com / Optage / Kopt

## Overview

The `com.optage.kopt` package is a subpackage within the Optage codebase that houses batch processing and order dispatch logic. It appears to be part of a larger financial or trading operations system, specifically centered around the **JKK Hakko SOD** (Stock Order Dispatch) subsystem.

At a high level, this area of the codebase is responsible for:

- **Batch orchestration** — coordinating batch operations through entry-point classes that delegate to underlying processing engines.
- **SOD dispatch** — validating, formatting, and sending stock order dispatch requests to external destinations.

The package currently consists of **auto-generated fixture classes** designed for SPEC-SCOPED-WIKI test infrastructure. These are scaffolding stubs rather than production code, meaning the actual implementations are either still under development or live in sibling packages (notably `com.optage.kopt.ekk`).

## Sub-module Guide

### `com.optage.kopt.batch`

The batch sub-package provides three minimal fixture classes (`KKPRC14901`, `KKPRC24901`, `KKPRC34901`) that serve as test entry points for batch operations. Their roles:

- **KKPRC14901** — The primary batch entry point. Its `run()` method delegates the actual work to `EKK0301A010.process()` in the `com.optage.kopt.ekk` package. It also has a no-op `check()` method intended as a pre-flight validation hook.
- **KKPRC24901** and **KKPRC34901** — Secondary and tertiary batch stubs with no-op `run()` methods. They are structurally identical placeholders.

These classes follow a simple delegation pattern: a test harness calls `run()`, and the class either delegates to the `ekk` package or does nothing.

### `com.optage.kopt.bp`

The `bp` sub-package provides base service and dispatch scaffolding for the **JKK Hakko SOD** subsystem. It contains five classes:

- **JKKHakkoSODCC** — The central coordination facade. It exposes `dispatch()` (which creates a `JKKSodSendCC` and calls `send()`) and `validate()` (which calls `KKPRC14901.check()` for pre-dispatch data integrity checks).
- **JKKSodSendCC** — The workhorse component that contains the actual SOD sending/dispatch logic. Called by `JKKHakkoSODCC.dispatch()`.
- **JKKBpServiceBase** — A base class following the template method pattern. Subclasses extend it and call `baseInit()` during their own initialization to establish common setup (logging, connection pools, config loading).
- **JKKHakkoSODHelper** — A utility class with a simple `format()` method that trims whitespace from strings, used to normalize SOD-related identifiers before processing.
- **JKKHakkoSODCCTest** — An auto-generated JUnit 4 test placeholder for the dispatch component.

### How the Sub-modules Relate

The two sub-packages are tightly coupled through cross-package delegation:

1. **Validation chain** — `JKKHakkoSODCC.validate()` delegates to `KKPRC14901.check()`, meaning the `bp` package depends on a class from the `batch` package to perform pre-dispatch validation. This creates a dependency edge from `bp` into `batch`.

2. **Batch engine delegation** — `KKPRC14901.run()` delegates further into `com.optage.kopt.ekk`, making `batch` the gateway between the KOPT subsystem and the actual batch processing engine in `ekk`.

3. **Unified flow** — A typical end-to-end flow for dispatching an SOD request looks like:

   ```
   Caller
     --> JKKHakkoSODCC.validate()
     --> KKPRC14901.check()    (pre-dispatch validation)
     --> JKKHakkoSODCC.dispatch()
     --> JKKSodSendCC.send()   (actual dispatch)
   ```

The `batch` package handles batch-level orchestration and engine delegation, while `bp` handles the higher-level SOD dispatch workflow and service initialization. Together they form a layered architecture: `bp` is the facade layer, `batch` is the batch orchestration layer, and `ekk` (external to `kopt`) is the processing engine layer.

## Key Patterns and Architecture

### Facade Pattern

`JKKHakkoSODCC` acts as a Facade for the SOD dispatch flow. Consumers call `dispatch()` or `validate()` on this single class, and internal delegation to `JKKSodSendCC`, `KKPRC14901`, and `JKKHakkoSODHelper` keeps each concern in its own component.

### Template Method Pattern

`JKKBpServiceBase` uses the template method pattern. Subclasses extend it and call `baseInit()` during their initialization to establish common setup, allowing shared concerns (logging, connection pools, config loading) to be centralized while specialized initialization lives in subclasses.

### Delegation Chain

Both sub-packages follow a consistent delegation model:

- **`bp` → `batch` → `ekk`** — The dispatch flow passes through multiple layers, each delegating to the next. No single class does all the work.
- **`batch` classes are standalone** — `KKPRC14901`, `KKPRC24901`, and `KKPRC34901` share no common interface or abstract base class. They are independent stubs with no shared state.

### Data Flow

SOD-related data flows through the system as follows:

```
String inputs --> JKKHakkoSODHelper.format()  (normalize whitespace)
                --> JKKHakkoSODCC.validate()   (integrity checks via KKPRC14901)
                --> JKKHakkoSODCC.dispatch()   (coordinate send)
                --> JKKSodSendCC.send()        (transmit)
                --> EKK0301A010.process()      (batch engine - if triggered)
```

## System Architecture Diagram

```mermaid
flowchart TD
    subgraph Kopt["com.optage.kopt"]
        direction TB
        subgraph Bp["com.optage.kopt.bp"]
            P1["JKKHakkoSODCC"]
            P2["JKKSodSendCC"]
            P3["JKKBpServiceBase"]
            P4["JKKHakkoSODHelper"]
        end
        subgraph Batch["com.optage.kopt.batch"]
            B1["KKPRC14901"]
            B2["KKPRC24901"]
            B3["KKPRC34901"]
        end
    end
    subgraph Ekk["com.optage.kopt.ekk"]
        E1["EKK0301A010"]
    end
    P1 --> P2
    P1 --> B1
    P1 --> P3
    P1 --> P4
    P1 --> E1
    B1 --> E1
```

- **`JKKHakkoSODCC`** (in `bp`) is the central coordination point, delegating to `JKKSodSendCC` for dispatch, `KKPRC14901` (in `batch`) for validation, and `JKKBpServiceBase` / `JKKHakkoSODHelper` as supporting components.
- **`KKPRC14901`** bridges `bp` and the `ekk` processing engine — it delegates validation to `batch`, and its `run()` method delegates actual batch work to `EKK0301A010`.
- **`KKPRC24901`** and **`KKPRC34901`** are standalone stubs not currently connected to any dispatch flow.

## Dependencies and Integration

### Internal Dependencies

| Dependency | Direction | Purpose |
|---|---|---|
| `com.optage.kopt.batch` | `bp` depends on it | `JKKHakkoSODCC.validate()` calls `KKPRC14901.check()` |
| `com.optage.kopt.ekk` | `batch` depends on it | `KKPRC14901.run()` instantiates and calls `EKK0301A010.process()` |
| `com.optage.kopt.ekk` | `bp` may depend on it | `JKKHakkoSODCC` may delegate to `EKK0301A010` directly |

### External Dependencies

- **JUnit 4** — Used by the test class `JKKHakkoSODCCTest` (auto-generated stub).
- **No other resolved external package dependencies** — The module currently has no declared dependencies beyond standard Java and JUnit.

### Cross-module Relationships

The `kopt` package sits above `batch` and `bp` as their parent. Neither sub-package has child sub-packages. The `ekk` package (`com.optage.kopt.ekk`) is a sibling that `batch` delegates to, forming a chain of responsibility across sibling packages.

## Notes for Developers

- **All current classes are auto-generated test fixtures.** They should not be treated as production code. Do not add business logic directly in these stubs — if real batch or dispatch behavior is needed, it belongs in the `ekk` package or new non-test packages.
- **The naming convention** (`KKPRC` + 5-digit suffix, `JKK*` prefixes) appears to be code-generated and may not map to human-readable names. Expect these to change as fixtures are replaced with real implementations.
- **`KKPRC14901.check()`** is a no-op pre-flight hook. If validation logic is needed for batch operations, this is the intended entry point.
- **`JKKBpServiceBase` is designed to be subclassed.** When creating new services in the SOD subsystem, extend it and override `baseInit()` for specialized initialization.
- **`JKKHakkoSODCC` is the main facade.** New dispatch flows should be added as methods on this class, delegating to existing or new helper components rather than placing logic inline.
- **`JKKHakkoSODHelper.format()`** is a trivial string trim. For more complex formatting needs (padding, encoding), consider extending this helper class.
- **The test class `JKKHakkoSODCCTest`** has a placeholder test (`assertTrue(true)`). Replace it with real unit or integration tests covering `dispatch()` and `validate()` behavior.
- **No shared interfaces or abstract classes** connect `KKPRC14901`, `KKPRC24901`, and `KKPRC34901`. They are independent stubs. If batch operation polymorphism is needed in the future, introducing a common interface would be a sensible next step.
