https://github.com/sandesh300/rule-engine-application
rule engine application using AST
https://github.com/sandesh300/rule-engine-application
java postgresql react spring-boot
Last synced: about 2 months ago
JSON representation
rule engine application using AST
- Host: GitHub
- URL: https://github.com/sandesh300/rule-engine-application
- Owner: sandesh300
- Created: 2024-10-17T15:13:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-25T07:45:45.000Z (over 1 year ago)
- Last Synced: 2025-04-14T00:50:03.654Z (about 1 year ago)
- Topics: java, postgresql, react, spring-boot
- Language: Java
- Homepage: https://rule-engine-bd7555.netlify.app/
- Size: 54.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rule Engine with Abstract Syntax Tree
A rule engine application that uses Abstract Syntax Tree (AST) to create, evaluate, and manage complex business rules. The system supports dynamic rule creation, combination, and modification with a focus on user attribute evaluation.
---
### Application Deployment Link - https://rule-engine-bd7555.netlify.app
### Deployment
The application has been deployed with the following technologies and services:
1. **Backend (Spring Boot):**
- Deployed to **Docker Hub** as a containerized application.
- [Docker Hub Repository URL](sandesh030/rule-engine-deployment)
2. **Backend Docker Image:**
- Docker image deployed to **Render.com** for hosting the backend services.
- [Render Deployment URL](https://rule-engine-deployment-latest.onrender.com)
3. **Database:**
- PostgreSQL database deployed on **Neon Postgres Cloud Database** for efficient and scalable data management.
- [Neon Postgres Cloud URL](https://console.neon.tech/app/projects/solitary-forest-16973334/branches/br-spring-butterfly-a8e2xdam/tables)
4. **Frontend:**
- React application deployed to **Netlify** for seamless frontend hosting.
- [Frontend Deployment URL](https://rule-engine-bd7555.netlify.app/)
---
## ๐ Features
- Create complex rules using logical operators (AND/OR)
- Evaluate user data against defined rules
- Combine multiple rules into a single rule
- Modify existing rules
- Visualize rules as Abstract Syntax Trees
- RESTful API for rule management
- React-based UI for rule visualization and management
## ๐ Technology Stack
### Backend
- Java 17
- Spring Boot 3.1.0
- PostgreSQL 15
- JUnit 5
- Mockito
- Spring Data JPA
### Frontend
- React 18
- TypeScript
- Tailwind CSS
- Axios
- React Query
- React Flow (for AST visualization)
## ๐ Prerequisites
- Java 17 or higher
- Node.js 18 or higher
- PostgreSQL 15
- Maven 3.8+
## ๐ Project Structure
```
rule-engine/
โโโ backend/
โ โโโ src/
โ โ โโโ main/
โ โ โ โโโ java/com/ruleengine/
โ โ โ โ โโโ controller/
โ โ โ โ โ โโโ RuleController.java
โ โ โ โ โโโ service/
โ โ โ โ โ โโโ RuleServices.java
โ โ โ โ โโโ model/
โ โ โ โ โ โโโ Node.java
โ โ โ โ โ โโโ Rule.java
โ โ โ โ โโโ repository/
โ โ โ โ โ โโโ RuleRepository.java
โ โ โ โ โโโ exception/
โ โ โ โ โโโ GlobalHandlerException.java
โ โ โ โ โโโ CustomException.java
โ โ โ โโโ resources/
โ โ โ โโโ application.properties
โ โ โโโ test/
โ โ โโโ RuleServiceTest.java
โ โโโ pom.xml
โโโ frontend/
โ โโโ src/
โ โ โโโ components/
โ โ โโโ CombineRule.js
โ โ โโโ CreateRule.js
โ โ โโโ EvaluateRule.js
โ โ โโโ Home.js
โ โ โโโ ModifyRule.js
โ โ โโโ Navbar.js
โ โ
โ โโโ package.json
โ โโโ tsconfig.json
โโโ README.md
```
## ๐ง Installation & Setup
### Backend Setup
1. Clone the repository:
```bash
git clone https://github.com/sandesh300/Rule-Engine-Application.git
cd rule-engine
```
2. Configure PostgreSQL:
```properties
# application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/rule_engine
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database=postgresql
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=false
```
3. Build and run the application:
```bash
mvn clean install
mvn spring-boot:run
```
### Frontend Setup
1. Navigate to the frontend directory:
```bash
cd rule-engine-ui
```
2. Install dependencies:
```bash
npm install
```
3. Start the development server:
```bash
npm start
```
## ๐ฏ API Endpoints
### Rule Management
```
POST /api/rules/create - Create a new rule
GET /api/rules/getRules - Get all rules
PUT /api/rules/modify - Modify existing rule
DELETE /api/rules/delete - Delete a rule
POST /api/rules/evaluate - Evaluate data against a rule
POST /api/rules/combine - Combine multiple rules
```
### Backend REST APIs Documentation Link
[Backend REST APIs Documentation](https://walnut-wrist-9da.notion.site/Rule-Engine-with-AST-129a272bc3e580c0ac0cfc7f01e5c221)
## ๐จ Design Choices
### Abstract Syntax Tree (AST)
- Nodes represent operators (AND/OR) and operands (conditions)
- Binary tree structure for efficient rule evaluation
- Node structure:
```java
class Node {
String type; // "operator" or "operand"
Node left; // Left child
Node right; // Right child
String value; // Operator or condition value
}
```
### Database Schema
```sql
CREATE TABLE rules (
id BIGSERIAL PRIMARY KEY,
rule_name VARCHAR(255) NOT NULL,
root_node JSONB NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```
### Rule Combination Strategy
- AND operator for combining multiple rules
- Preserves individual rule integrity
- Optimizes for evaluation performance
## ๐งช Testing
### Test Coverage
- Unit tests for services and controllers
- Integration tests for API endpoints
- Frontend component tests
- End-to-end testing for critical flows
### Test Cases Documentation Link
[Test Cases Documentation](https://walnut-wrist-9da.notion.site/Rule-Engine-using-AST-Test-Cases-129a272bc3e580a082e9c45cc99ccc51)
### Running Tests
Backend:
```bash
cd backend
mvn test
```
Frontend:
```bash
cd frontend
npm test
```
## โ ๏ธ Validation & Error Handling
### Rule String Validation
- Syntax validation for rule strings
- Parentheses balance checking
- Operator validation
- Data type compatibility checks
### User Data Validation
- Required field validation
- Data type validation
- Value range validation
- Department catalog validation
### Error Response Format
```json
{
"error": "Error message",
"details": "Additional error details",
"timestamp": "2024-10-24T10:00:00Z"
}
```
### Validation Error Handling Link
[Validation Error Handling](https://walnut-wrist-9da.notion.site/Rule-Engine-using-AST-Validation-Error-Handling-129a272bc3e580bb9a1acd849dee8eb7)
## ๐ฆ Dependencies
### Backend Dependencies
```xml
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-data-jpa
org.postgresql
postgresql
org.projectlombok
lombok
org.springframework.boot
spring-boot-starter-test
test
org.mockito
mockito-core
5.11.0
test
org.junit.jupiter
junit-jupiter-api
5.10.3
test
```
### Frontend Dependencies
```json
{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"axios": "^1.6.0",
"react-query": "^3.39.3",
"reactflow": "^11.10.1",
"tailwindcss": "^3.3.5"
}
}
```
---