This is a Rule Engine with AST. It is an implementation of Rule Engine with AST in Javascript. It is a rule engine that uses AST to evaluate JSON data against a given rule string or multiple rule strings that are combined into a single AST and then evaluates the JSON data against the AST. It can be used to perform the following tasks:
- Create a new AST from a given rule string
- Combine multiple rule strings into a single AST
- Evaluate a JSON data against the AST
I used a node with left and right pointer to create a tree like structure for easy evaluation.
It is basically of two types:
- Operator:
{
"type": "operator",
"left": Node,
"right": Node,
"value": string ("AND" or "OR")
}
- Operand(leaf node):
{
"type": "operand",
"left": null,
"right": null,
"value": string (e.g. "Salary>50000")
}
Rule:
{
"name": string,
"description": string,
"ruleString": string(e.g. "(age > 30 AND department = 'Marketing')"),
"ast": Node,
"createdAt": date,
"updatedAt": date,
}
Some features of the RuleEngine:
- Parsed the rule string in Linear Time
- Easy to add more operators or add priority to operators in future
- Implemented error handling in Rule string parsing like invalid syntax and invalid type comparison.
- Used promise in rule evaluation for parallel processing to fasten the process
-
Run git clone in terminal
git clone https://github.com/jatinxkirito/RuleEngine_ATS.git
-
In zeotap_backend folder
- Create config.env file with following content
DATABASE_LINK="Your MongoDB database link"
- Run following in terminal
npm install npm start
- Create config.env file with following content
-
In zeotap__frontend folder
- Run following in terminal
npm install npm run dev
- Run following in terminal
-
Open http://localhost:5173 in you browser
-
To run tests, go to zeotap_backend folder and run following command in terminal
npx mocha --file test/testSetup.js test/**/*.test.js