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
The application has been deployed with the following technologies and services:
-
Backend (Spring Boot):
- Deployed to Docker Hub as a containerized application.
- Docker Hub Repository URL
-
Backend Docker Image:
- Docker image deployed to Render.com for hosting the backend services.
- Render Deployment URL
-
Database:
- PostgreSQL database deployed on Neon Postgres Cloud Database for efficient and scalable data management.
- Neon Postgres Cloud URL
-
Frontend:
- React application deployed to Netlify for seamless frontend hosting.
- Frontend Deployment URL
- 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
- Java 17
- Spring Boot 3.1.0
- PostgreSQL 15
- JUnit 5
- Mockito
- Spring Data JPA
- React 18
- TypeScript
- Tailwind CSS
- Axios
- React Query
- React Flow (for AST visualization)
- Java 17 or higher
- Node.js 18 or higher
- PostgreSQL 15
- Maven 3.8+
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
- Clone the repository:
git clone https://github.com/sandesh300/Rule-Engine-Application.git
cd rule-engine- Configure PostgreSQL:
# 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- Build and run the application:
mvn clean install
mvn spring-boot:run- Navigate to the frontend directory:
cd rule-engine-ui- Install dependencies:
npm install- Start the development server:
npm startPOST /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
- Nodes represent operators (AND/OR) and operands (conditions)
- Binary tree structure for efficient rule evaluation
- Node structure:
class Node { String type; // "operator" or "operand" Node left; // Left child Node right; // Right child String value; // Operator or condition value }
CREATE TABLE rules (
id BIGSERIAL PRIMARY KEY,
rule_name VARCHAR(255) NOT NULL,
root_node JSONB NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- AND operator for combining multiple rules
- Preserves individual rule integrity
- Optimizes for evaluation performance
- Unit tests for services and controllers
- Integration tests for API endpoints
- Frontend component tests
- End-to-end testing for critical flows
Backend:
cd backend
mvn testFrontend:
cd frontend
npm test- Syntax validation for rule strings
- Parentheses balance checking
- Operator validation
- Data type compatibility checks
- Required field validation
- Data type validation
- Value range validation
- Department catalog validation
{
"error": "Error message",
"details": "Additional error details",
"timestamp": "2024-10-24T10:00:00Z"
}<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.3</version> <!-- Or any latest stable version -->
<scope>test</scope>
</dependency>
</dependencies>{
"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"
}
}