Skip to content

A **Rule Engine** with an **AST** evaluates rules by breaking them into a tree structure. Each node in the tree represents a part of the rule (like conditions or actions). This makes rule evaluation efficient and easier to understand.

Notifications You must be signed in to change notification settings

Kavyacodingg/Application-1-Rule-Engine-with-AST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rule Engine

A React application that allows users to create, combine, and evaluate rules. The rules are represented as Abstract Syntax Trees (AST) and can be visualized using a tree structure.

Features

  • Create Rule: Allows users to input a rule in the format field operator value (e.g., age > 30). The rule is validated and converted into an AST.

  • Combine Rules: Combines multiple rules using logical operators (AND, OR) to create a more complex rule represented as a single AST.

  • Evaluate Rule: Evaluates the combined AST against provided JSON data to determine if the data satisfies the rule.

  • Visualize AST: Displays the AST of individual rules and the combined AST as a tree structure using react-d3-tree.

  • NOTE : when we click on create rule -> a tree is generated and shown at frontend but it is in left-most corner , you need to drag it to the center to clearly see it , same happens when we click on combine rules.

Prerequisites

  • Node.js (v14 or later)
  • npm (v6 or later)

Getting Started

Clone the Repository

git clone https://github.com/amantripathigithub/Application-1-Rule-Engine-with-AST.git

cd Application-1-Rule-Engine-with-AST.git



Backend Setup
Navigate to the backend directory:

---cd backend



Install dependencies:

---npm install



Start the backend server:

---node index.js

The backend server will run on http://localhost:5000.





Frontend Setup

Navigate to the frontend directory:

---cd frontend

Install dependencies:

---npm install


Start the frontend development server:

---npm start


The frontend server will run on http://localhost:3000.





Usage
Open your web browser and navigate to http://localhost:3000.

Create Rule: Enter a rule in the input field and click "Create Rule". The rule should be in the format field operator value (e.g., age > 30).

Combine Rules: After creating at least two rules, click "Combine Rules" to combine them into a single AST.

Evaluate Rule: Enter JSON data in the textarea (e.g., {"age": 32, "department": "Sales"}) and click "Evaluate Rule". The result (true/false) will be displayed based on whether the data satisfies the combined rule.

Visualize AST: The AST for individual rules and the combined AST will be displayed as tree structures.

Example : 
Create the following rules:

age > 30
department = Sales
age < 25
department = Marketing
Combine the rules.

Enter the following JSON data for evaluation:
{
  "age": 32,
  "department": "Sales"
}
The evaluation result should be true if the combined AST is satisfied by the provided data.

screenshots

Screenshot (2392) Screenshot (2391) Screenshot (2390) Screenshot (2389) Screenshot (2388) Screenshot (2387) Screenshot (2386) Screenshot (2385) Screenshot (2384)

About

A **Rule Engine** with an **AST** evaluates rules by breaking them into a tree structure. Each node in the tree represents a part of the rule (like conditions or actions). This makes rule evaluation efficient and easier to understand.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published