Skip to content

siddharthgupta5/Rule_Engine_AST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rule Engine Application

Project Description

This project implements a Rule Engine that uses Abstract Syntax Trees (AST) to evaluate complex rules and conditions based on user-defined attributes. This engine allows for dynamic rule creation, combination, modification, and evaluation for various use cases, such as determining user eligibility based on attributes like age, department, income, and experience. The application follows a 3-tier architecture, comprising a backend API, data storage, and a simple frontend for interaction.

The frontend provides a simple UI to create, view, combine, and evaluate rules.

Features

  1. Create rules using simple expressions like js(age > 30 && salary > 50000).
  2. Combine rules logically (e.g., using 'AND' or 'OR').
  3. Evaluate rules against user data to check eligibility.
  4. Update rules by modifying existing expressions.
  5. Validation for valid attributes and handling of invalid rules.

Rules are stored as ASTs, making evaluation and modification efficient.

Data Storage

  • The backend uses Mongoose for defining models and interacting with MongoDB.

Tech Stacks:

  • Tech stack: MERN stack.
  • Error handling both on the server and on the client

Prerequisites

  • Ensure you have Node.js and npm installed.

Dependencies:

Backend:

-  Node.js (v18.12.1)
-  Express (v4.x)
-  Axios (v1.x)
-  Mongoose (v6.x)
-  dotenv (v16.x)
-  Nodemon (v2.x) (for development) 

Frontend:

-  React (v18.x)
-  Axios (v1.x)

Testing:

-  Supertest (v7.x)
-  Jest (v29.x)

Here all the enclosed braces indicate the version of these Tech Stacks used.

Installation and Setup

  1. Clone the repository:
git clone https://github.com/siddharthgupta5/Rule_Engine_AST.git
  1. Change Directory:
cd backend
  1. Install dependencies:
npm install
  1. Create the .env file with your values for PORT and USERNAME and PASSWORD for the MONGO_URI (for the MongoDB database or add your MONGODB_URL in the MONGO_URI).
PORT=...
MONGO_URI=mongodb+srv://<USERNAME>:<PASSWORD>@cluster0.lw6c7.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
  1. Start the development server:
npm start
  1. Open another terminal. Navigate into the project directory:
cd frontend
  1. Install dependencies:
npm install
  1. Start the frontend server:
npm start

For Testing the suit cases and testcases

  1. Navigate back to the backend directory:
cd backend
  1. Run tests:
npm tests

Example

  • Create a Rule
 {
  "ruleString": "(age > 28 && department == 'Marketing')",
  "name": "Marketing Eligibility"
 }
  • Evaluate a Rule
 {
  "ruleId": "<ruleId>",
  "data": {
    "age": 30,
    "department": "Marketing",
    "salary": 50000
  }
}

API Endpoints

  • Create a Rule: js POST /api/rules/create
  • Combine Rules: js POST /api/rules/combine
  • Evaluate Rule: js POST /api/rules/evaluate
  • Get ALL Rules: js GET /api/rules
  • Evaluate Rule: js POST /api/rules/update/:id

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published