# thanhtrixx/rule-engine architecture

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

- Interactive diagram: https://gitdiagram.com/thanhtrixx/rule-engine
- Repository: https://github.com/thanhtrixx/rule-engine

## Overview

##### Main Components

a) Core Rule Engine Components:
- Rule Engine Core
- Rule Configuration Service
- Rule Execution Pipeline
- Database Layer

b) External Interfaces:
- REST API Interface (RuleConfigController)
- Configuration Loading System
- Database Integration

**┌─ API Layer ─────────────────┐**
- RuleConfigController        │
- Configuration Endpoints   │
- Rule Management API      │
- ┘

**┌─ Rule Configuration Service ─┐    ┌─ Rule Engine Core ──────┐**
- Rule Loading              │    │ - Condition Evaluation  │
- Configuration Management  │◄───►│ - Action Execution     │
- Validation               │    │ - Rule Set Processing   │
- ┘    └────────────────────────┘

**┌─ Rule Models ──────┐  ┌─ Conditions ────┐  ┌─ Actions ────────┐**
- RuleDefinition     │  │ EqualsCondition │  │ EarnPointByRate  │
- RuleSetDefinition  │  │ OperatorCond.   │  │ (Other Actions)  │
- ┘  └───────────────┘  └────────────────┘

**┌─ Database Layer ────────────┐**
- DbRuleConfigService        │
- RuleConfigRepositories     │
- ┘

##### Key Relationships to Highlight

- Data flow from API → Service → Engine
- Bidirectional communication between Engine and Models
- Database interactions
- Configuration loading paths

##### Technical Details

- Kotlin/Spring Boot framework indication
- Database connection (shown in compose.yaml)
- Configuration loading from YAML/JSON
- Test infrastructure integration

##### The configuration-driven nature of the system

This system design should help developers understand both the static structure and runtime behavior of the Rule Engine, making it easier to maintain and extend the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph API
        RC["RuleConfigController"]:::api
    end

    subgraph Services
        RCS["Rule Configuration Service"]:::service
        RE["Rule Engine"]:::service
    end

    subgraph Domain
        subgraph Models
            RD["Rule Definitions"]:::model
            TC["Transaction Context"]:::model
            RSW["Rule Set Wrapper"]:::model
        end

        subgraph "Conditions Framework"
            BC["Base Condition"]:::condition
            EC["Equals Condition"]:::condition
            OC["Operator Condition"]:::condition
        end

        subgraph "Actions Framework"
            BA["Base Action"]:::action
            EPA["Earn Point By Rate Action"]:::action
        end
    end

    subgraph "Database Layer"
        DBRC["DB Rule Config Service"]:::db
        RCR["Rule Config Repositories"]:::db
        RCE["Rule Config Entities"]:::db
    end

    subgraph Configuration
        RCONF["Rule Configuration"]:::config
        ACONF["Application Config"]:::config
    end

    %% Relationships
    RC --> RCS
    RCS --> RE
    RE --> RD
    RE --> TC
    RE --> RSW

    RCS --> DBRC
    DBRC --> RCR
    RCR --> RCE

    RE --> BC
    BC --> EC
    BC --> OC

    RE --> BA
    BA --> EPA

    RCS --> RCONF
    RCS --> ACONF

    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef model fill:#FFC107,stroke:#FFA000,color:black
    classDef condition fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef action fill:#FF5722,stroke:#E64A19,color:white
    classDef db fill:#607D8B,stroke:#455A64,color:white
    classDef config fill:#795548,stroke:#5D4037,color:white

    %% Click events
    click RC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/RuleConfigController.kt"
    click RCS "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/RuleConfigService.kt"
    click RE "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/engine/RuleEngine.kt"
    click RD "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/model/RuleDefinitions.kt"
    click TC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/model/TransactionContext.kt"
    click RSW "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/engine/RuleSetWrapper.kt"
    click BC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/condition/Condition.kt"
    click EC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/condition/EqualsCondition.kt"
    click OC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/condition/OperatorCondition.kt"
    click BA "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/action/Action.kt"
    click EPA "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/action/EarnPointByRateAction.kt"
    click DBRC "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/db/DbRuleConfigService.kt"
    click RCR "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/db/RuleConfigRepositories.kt"
    click RCE "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/db/RuleConfigEntities.kt"
    click RCONF "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/kotlin/trile/rule/config/RuleConfiguration.kt"
    click ACONF "https://github.com/thanhtrixx/rule-engine/blob/main/src/main/resources/application.yml"
```
