# ispirt/ocen-authstarter architecture

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

- Interactive diagram: https://gitdiagram.com/ispirt/ocen-authstarter
- Repository: https://github.com/ispirt/ocen-authstarter

## Overview

- The “common” module contains shared utilities, data transfer objects (DTOs), controllers, and components for handling security (JWS/signatures), heartbeat events, and registry interactions.
- The “lender” module represents the Lender Application (running on port 8084) that signs and responds to loan applications.
- The “loanagent” module represents the Loan Agent Application (running on port 8085) which initiates the “create loan application” flow.
- An “api-collection” folder containing Postman collections provides sample API calls.

The README further explains that the sample loan application flow involves obtaining authentication tokens, registering via the registry service, and then triggering asynchronous flows between the loan agent and lender applications – each using their respective key pair sets for request signing/verification.

##### Main Components and Their Roles
- Loan Agent Application (port 8085): Initiates the create-loan-application request. It handles signing requests using its private/public key pair from its resource JSON.
- Lender Application (port 8084): Receives the loan application request, verifies signatures, and sends back responses using its corresponding private/public key pair.
- Common Module: Contains shared services, utilities, controllers (e.g., CommonController), DTOs for heartbeat, journey, and registry operations, as well as security (JWS signing/validation) components.
- External Services:
- Authentication Service: (https://auth.ocen.network) used for token generation and JWT verification.
- Registry Service: (https://dev.ocen.network/service) providing role information, product details, and more.
- Heartbeat/Analytics Service: (http://analytics-dev.ocen.network/ocen/v4/event) to update heartbeat events.

##### Relationships and Interactions
- The Loan Agent calls an API to trigger the create loan application; it uses the common module for request signing and talks to the authentication service to generate tokens.
- The Lender Application, upon receiving the request on its controller, uses its components from the common module (e.g., signature verification utilities) to verify the incoming request.
- Both applications interact with external services (Registry and Auth) to get required configurations or to verify tokens.
- The Common module’s shared utilities ensure consistency across applications (e.g., DTOs, header constants, and utility functions for JSON processing).

##### Architectural Patterns
- Modular design via Maven multi-module setup.
- Separation of concerns: distinct modules (loan agent, lender) with shared common library.
- API-driven design with clearly defined endpoints (Health Test, Generate Signature, Trigger Create Loan Application).
- Asynchronous processing for the create loan application flow.
- Use of external authentication and registry services, highlighting integration patterns.

##### Detailed Elements
- To indicate loan application requests flowing from the Loan Agent to the Lender.
- To show that the Common module is accessed by both applications.
- To illustrate external dependency flows (e.g., token verification and registry configuration updates).
- Annotations for important configuration details (e.g., public/private key details, port numbers, API URIs).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Loan Agent Application (8085)
    subgraph "Loan Agent Application (8085)"
        LAApp["Loan Agent Application (8085)"]:::internal
        LACtrl["LoanAgentController"]:::internal
        LAService["LoanAgentService"]:::internal
        LAApp -->|"calls"| LACtrl
        LACtrl -->|"invokes"| LAService
    end

    %% Lender Application (8084)
    subgraph "Lender Application (8084)"
        LenderApp["Lender Application (8084)"]:::internal
        LenderCtrl["LenderController"]:::internal
        LenderService["LenderService"]:::internal
        LenderApp -->|"calls"| LenderCtrl
        LenderCtrl -->|"invokes"| LenderService
    end

    %% Common Module
    subgraph "Common Module"
        Common["Common Module (Shared Utilities, DTOs, JWS, Heartbeat, Registry)"]:::internal
    end

    %% External Services
    subgraph "External Services"
        Auth["Authentication Service"]:::external
        Registry["Registry Service"]:::external
        Heartbeat["Heartbeat/Analytics Service"]:::external
    end

    %% API Collection Node
    APICollection["API Collection (Postman)"]:::internal

    %% Interactions and Data Flow
    LAApp -->|"getToken"| Auth
    LAApp -->|"lookupRole"| Registry
    LAApp -->|"signRequest"| Common
    Common -->|"processLoanApplication"| LenderApp
    LenderApp -->|"verifySignature"| Common
    LenderApp -->|"sendHeartbeat"| Heartbeat
    APICollection -->|"sampleAPICalls"| LAApp

    %% Click Events
    click LAApp "https://github.com/ispirt/ocen-authstarter/blob/main/loanagent/src/main/java/org/example/LoanAgentApplication.java"
    click LACtrl "https://github.com/ispirt/ocen-authstarter/blob/main/loanagent/src/main/java/org/example/controller/LoanAgentController.java"
    click LAService "https://github.com/ispirt/ocen-authstarter/tree/main/loanagent/src/main/java/org/example/service/"
    click LenderApp "https://github.com/ispirt/ocen-authstarter/blob/main/lender/src/main/java/org/example/LenderApplication.java"
    click LenderCtrl "https://github.com/ispirt/ocen-authstarter/blob/main/lender/src/main/java/org/example/controller/LenderController.java"
    click LenderService "https://github.com/ispirt/ocen-authstarter/tree/main/lender/src/main/java/org/example/service/"
    click Common "https://github.com/ispirt/ocen-authstarter/tree/main/common/"
    click APICollection "https://github.com/ispirt/ocen-authstarter/tree/main/api-collection/"

    %% Styles
    classDef internal fill:#d9e8fc,stroke:#1665c1,color:#000,stroke-width:2px;
    classDef external fill:#fef9c3,stroke:#f39c12,color:#000,stroke-width:2px;
```
