This project implements a rule engine system where rules can be dynamically created, combined, and evaluated using an Abstract Syntax Tree (AST). The system consists of a React frontend and a Node.js backend.
- Create Rules: Users can define rules based on attributes such as age, department, salary, etc.
- Combine Rules: Combine multiple rules into a single AST for evaluation.
- Evaluate Rules: Evaluate user attributes (like age, department) against a combined set of rules.
- UI: A simple React-based UI to input rules, display the rules list, and evaluate them.
- Backend: A Node.js and Express backend to handle rule creation, combination, and evaluation.
- Frontend: React components (Rule input, list, evaluation form).
- Backend: Node.js with Express to handle rule-related API calls.
- AST (Abstract Syntax Tree): Custom data structure to represent rules logically and allow easy evaluation.
- Node.js (v14 or higher)
- npm or yarn
- (Optional) MongoDB or another database if you want to persist rules.
git clone https://github.com/your-repo/rule-engine.git
cd rule-engine
Navigate to the backend directory:
cd backend
Install dependencies:
npm install
Start the backend server:
npm start
By default, the backend will run on http://localhost:5000.
Open a new terminal and navigate to the frontend directory:
cd frontend
Install frontend dependencies:
npm install
Start the frontend server:
npm start
By default, the frontend will run on http://localhost:3000.
If you want to test the backend API separately:
POST http://localhost:5000/api/rules
Body: { "ruleString": "age > 30 AND department = 'Sales'" }
POST http://localhost:5000/api/combine-rules
Body: { "ruleStrings": ["age > 30 AND department = 'Sales'", "salary > 50000"] }
POST http://localhost:5000/api/evaluate-rule
Body: { "ast": {YOUR_AST_HERE}, "data": { "age": 35, "department": "Sales", "salary": 60000 } }
You can configure the environment variables for both frontend and backend by creating a .env file in the respective directories:
PORT: The port on which the backend runs (default is 5000).
REACT_APP_API_URL: The backend API URL (default is http://localhost:5000).