Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rule Engine with AST Application

Overview

This application is a rule engine that determines user eligibility based on attributes such as age, department, salary, and experience. It uses an Abstract Syntax Tree (AST) to represent and manage conditional rules, allowing for dynamic rule creation, combination, and evaluation.

Features

  • Create Rules: Define rules using a string format that gets converted into an AST.

  • Combine Rules: Combine multiple rules into a single AST for more complex evaluations.

  • Evaluate Rules: Check if the given data meets the criteria defined by the AST.

  • Tree Visualization: Define or Combine Rule would should show Tree Representation.

Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB

Getting Started

Prerequisites

  • Node.js and npm installed
  • MongoDB installed and running

Installation

  1. Clone the Repository

    git clone "https://github.com/Devleena2003/Rule-Engine-with-AST.git"
    
  2. Install Backend Dependencies

    npm install
  3. Start MongoDB

    Ensure that MongoDB is running on your local machine:

    mongod
  4. Start the Backend Server

    npm start

API Endpoints

  1. Create a Rule
    • Endpoint: /api/create_rule

    • Method: POST

    • Body:

      {
        "ruleString": "((age > 30 AND department = 'Sales') OR (age < 25 AND department = 'Marketing')) AND (salary > 50000 OR experience > 5)",
        "ruleName": "Rule 1"
      }

use appropriate spaces in Rules for correct results.

Rule should be in follow format: variable operator value

  • Response:

    {
      "_id": "605c72ef1f4e3a001f4d2e9a",
      "rule_name": "Rule1",
      "rule_ast": { ... }
    }
  1. Combine Rules

    • Endpoint: /api/rules/combine_rules

    • Method: POST

    • Body:

      {
        "ruleIds": ["605c72ef1f4e3a001f4d2e9a", "605c730f1f4e3a001f4d2e9b"]
        "operators: op
      }
    • Response:

      {
        "type": "operator",
        "value": operator,
        "left": { ... },
        "right": { ... }
      }
  2. Evaluate a Rule

    • Endpoint: /api/rules/evaluate_rule

    • Method: POST

    • Body:

      {
        "rule": { ... },
        "data": {
          "age": 35,
          "department": "Sales",
          "salary": 60000,
          "experience": 3
        }
      }
    • Response:

      {
        "result": true
      }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages