# psmri/ubi-eligibility-sdk architecture

> Architecture diagram of the GitHub repository psmri/ubi-eligibility-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/psmri/ubi-eligibility-sdk
- Repository: https://github.com/psmri/ubi-eligibility-sdk

## Overview

##### Project type and purpose
- This is a Node.js–based SDK exposing RESTful endpoints to determine benefit eligibility.
- It ingests user profiles and benefit schemas, applies configurable rules, and returns an eligibility result.

##### File structure
- Top-level files: Dockerfile, docker-compose.yml, deploy.sh, .env.example, GitHub workflows – this indicates containerized deployment and CI/CD.
- src/config/: Swagger/OpenAPI setup and environment config.
- src/index.js: Application entrypoint, bootstraps the HTTP server.
- src/schemas/: Joi or JSON schemas for validating incoming requests.
- src/services/:
– eligibilityService.js: Orchestrates the eligibility check.
– interfaces/RuleInterface.js: Defines the contract for rule modules.
– rules/: Concrete rule implementations (e.g., userProfileRule.js, userDocumentRule.js).
- src/utils/: Shared utilities (schema loaders, eligibility logic helpers, logger).

##### README
- Confirms it’s an SDK for benefit eligibility with RESTful API endpoints.
- Mentions Swagger/OpenAPI and environment variable configuration—key integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Clients["Clients/Consumers"]:::external
    end

    %% API Gateway
    subgraph "API Gateway"
        APIGateway["Express.js HTTP Server"]:::core
    end

    %% Configuration Layer
    subgraph "Configuration" 
        EnvConfig["Environment Variables"]:::config
        SwaggerJS["swagger.js"]:::config
        SwaggerYAML["swagger.yaml"]:::config
    end

    %% Validation Layer
    subgraph "Validation Layer"
        Schema1["check-eligibility-schema.js"]:::validation
        Schema2["check-users-eligibility-schema.js"]:::validation
    end

    %% Service Layer
    subgraph "Service Layer"
        Service["eligibilityService.js"]:::core
    end

    %% Rule Engine
    subgraph "Rule Engine"
        RuleInterface["RuleInterface.js"]:::plugin
        UserProfileRule["userProfileRule.js"]:::plugin
        UserDocumentRule["userDocumentRule.js"]:::plugin
    end

    %% Utility Layer
    subgraph "Utility Layer"
        BenefitSchemaLoader["benefitSchemaEligibility.js"]:::plugin
        EligibilityUtils["eligibilityUtils.js"]:::plugin
        Logger["logger.js"]:::plugin
    end

    %% External & Docs
    subgraph "API Spec & Testing Guides"
        DocsSwagger["docs/swagger.yaml"]:::external
        Postman1["Benefit Eligibility API.postman_collection.json"]:::external
        Postman2["Benefit_Eligibility_SDK.postman_collection.json"]:::external
    end

    %% Deployment Stack
    subgraph "Deployment & CI/CD"
        DockerfileNode["Dockerfile"]:::deploy
        Compose["docker-compose.yml"]:::deploy
        DeploySh["deploy.sh"]:::deploy
        GH1["build-ghcr.yaml"]:::deploy
        GH2["UBA-DEV.yml"]:::deploy
        GH3["UBA-PILOT.yaml"]:::deploy
        GH4["uba-depwd-pilot.yaml"]:::deploy
    end

    %% Flow
    Clients -->|"HTTP Request"| APIGateway
    APIGateway -->|"load config"| EnvConfig
    APIGateway -->|"load spec"| SwaggerJS
    APIGateway -->|"load spec"| SwaggerYAML
    APIGateway -->|"route & validate"| Schema1
    APIGateway -->|"route & validate"| Schema2
    Schema1 -->|"validated payload"| Service
    Schema2 -->|"validated payload"| Service
    Service -->|"load schema"| BenefitSchemaLoader
    Service -->|"iterate rules"| RuleInterface
    RuleInterface -->|"execute"| UserProfileRule
    RuleInterface -->|"execute"| UserDocumentRule
    UserProfileRule -->|"use utils"| EligibilityUtils
    UserDocumentRule -->|"use utils"| EligibilityUtils
    Service -->|"log"| Logger
    Service -->|"result"| APIGateway
    APIGateway -->|"HTTP Response"| Clients

    %% External docs linkage
    APIGateway --> DocsSwagger
    APIGateway --> Postman1
    APIGateway --> Postman2

    %% Deployment links
    APIGateway --> DockerfileNode
    DockerfileNode --> Compose
    Compose --> DeploySh
    DeploySh --> GH1
    DeploySh --> GH2
    DeploySh --> GH3
    DeploySh --> GH4

    %% Click Events
    click APIGateway "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/index.js"
    click SwaggerJS "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/config/swagger.js"
    click SwaggerYAML "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/config/swagger.yaml"
    click EnvConfig "https://github.com/psmri/ubi-eligibility-sdk/blob/main/.env.example"
    click Schema1 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/schemas/check-eligibility-schema.js"
    click Schema2 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/schemas/check-users-eligibility-schema.js"
    click Service "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/services/eligibilityService.js"
    click RuleInterface "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/services/interfaces/RuleInterface.js"
    click UserProfileRule "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/services/rules/userProfileRule.js"
    click UserDocumentRule "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/services/rules/userDocumentRule.js"
    click BenefitSchemaLoader "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/utils/benefitSchemaEligibility.js"
    click EligibilityUtils "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/utils/eligibilityUtils.js"
    click Logger "https://github.com/psmri/ubi-eligibility-sdk/blob/main/src/utils/logger.js"
    click DocsSwagger "https://github.com/psmri/ubi-eligibility-sdk/blob/main/docs/swagger.yaml"
    click Postman1 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/docs/Benefit Eligibility API.postman_collection.json"
    click Postman2 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/docs/Benefit_Eligibility_SDK.postman_collection.json"
    click DockerfileNode "https://github.com/psmri/ubi-eligibility-sdk/tree/main/Dockerfile"
    click Compose "https://github.com/psmri/ubi-eligibility-sdk/blob/main/docker-compose.yml"
    click DeploySh "https://github.com/psmri/ubi-eligibility-sdk/blob/main/deploy.sh"
    click GH1 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/.github/workflows/build-ghcr.yaml"
    click GH2 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/.github/workflows/UBA-DEV.yml"
    click GH3 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/.github/workflows/UBA-PILOT.yaml"
    click GH4 "https://github.com/psmri/ubi-eligibility-sdk/blob/main/.github/workflows/uba-depwd-pilot.yaml"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef plugin fill:#90EE90,stroke:#000,stroke-width:1px
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef validation fill:#E6E6FA,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef deploy fill:#F0F0F0,stroke:#000,stroke-width:1px
```
