{"id":17777945,"url":"https://github.com/yuvraj0028/rule-engine-ast","last_synced_at":"2026-04-12T15:04:32.260Z","repository":{"id":258674832,"uuid":"874387733","full_name":"yuvraj0028/rule-engine-AST","owner":"yuvraj0028","description":"User friendly rule engine implemented with Abstract Syntax Tree for making a logical data structure to evaluate attributes.","archived":false,"fork":false,"pushed_at":"2024-10-19T10:17:04.000Z","size":389,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-09T01:38:42.443Z","etag":null,"topics":["angular","angular-cli","backend","bootstrap5","data-structures","docker","java","logic-programming","material-ui","mongodb","spring-boot","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuvraj0028.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-17T18:28:00.000Z","updated_at":"2025-04-21T19:27:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce49a6b7-f940-4e2b-8b95-d8a766e2c0cc","html_url":"https://github.com/yuvraj0028/rule-engine-AST","commit_stats":null,"previous_names":["yuvraj0028/rule-engine-ast"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yuvraj0028/rule-engine-AST","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0028%2Frule-engine-AST","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0028%2Frule-engine-AST/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0028%2Frule-engine-AST/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0028%2Frule-engine-AST/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuvraj0028","download_url":"https://codeload.github.com/yuvraj0028/rule-engine-AST/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0028%2Frule-engine-AST/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274232032,"owners_count":25245856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-cli","backend","bootstrap5","data-structures","docker","java","logic-programming","material-ui","mongodb","spring-boot","tree-structure"],"created_at":"2024-10-27T00:03:19.700Z","updated_at":"2026-04-12T15:04:32.172Z","avatar_url":"https://github.com/yuvraj0028.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rule Engine Server\n\nThis backend application is a rule engine that accepts conditional rules as strings through API calls, builds an [Abstract Syntax Tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) from these rules, stores them in a MongoDB database, and evaluates incoming data against the saved rules. The project uses **Spring Boot** for backend development and **MongoDB** as the database.\n\n## Features\n\n- **Spring Boot** framework for backend logic.\n- **MongoDB** for storing rules.\n- **REST APIs** to create, combine, and evaluate rules.\n- **Validation logic** for rules and evaluation response data.\n- **Exception handling and logging** mechanisms for better debugging.\n- **AST (Abstract Syntax Tree)** to represent and evaluate complex rules.\n\n## Prerequisites\n\nBefore running the application, ensure that the following are installed:\n\n1. **Java 21** - [Download Java](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html).\n2. **Gradle 8** - [Download Gradle](https://gradle.org/install/).\n3. **MongoDB** - [Download MongoDB](https://www.mongodb.com/try/download/community).\n4. **Docker** (optional for running MongoDB) - [Download Docker](https://docs.docker.com/get-docker/).\n\n## MongoDB Setup via Docker\n\nYou can set up MongoDB using Docker with the following commands:\n\n```bash\n# Pull the MongoDB Docker image\ndocker pull mongo:latest\n\n# Run the MongoDB container\ndocker run -d -p 27017:27017 --name=rule_engine mongo:latest\n\n# Verify the state\ndocker ps\n```\n\n## Running the Spring Boot Application\n\nOnce Java, Gradle, and MongoDB are installed, follow these steps:\n\n1. Clone the repository\n\n```bash\ngit clone https://github.com/yuvraj0028/rule-engine-AST\n```\n\n2. Change your directory\n\n```bash\ncd rule-engine-AST/rule_engine_server/engine\n```\n\n3. Build the application\n\n```bash\ngradlew build\n```\n\n4. Run the application\n\n```bash\ngradlew bootRun\n```\n\nThe application will be accessible at `http://localhost:9191`.\n\n## Application Port\n\nThe application runs on port `9191`. To access the APIs, use the base URL `http://localhost:9191`.\n\n## API Endpoints\n\nHere are the available APIs in the application, with details of required parameters and expected responses:\n\n1. **Create Rule (POST `/application/api/rule/create_rule`)**\n   This endpoint allows you to create a new rule.\n\n#### Request Body\n\n```json\n{\n  \"metaData\": {\n    \"uploadedBy\": \"string\"\n  },\n  \"ruleExpression\": \"string\"\n}\n```\n\n#### Response Body\n\n```json\n{\n  \"errorMessage\": \"\u003cerrorMessage\u003e or null\",\n  \"responseData\": {\n    \"id\": \"objectID\",\n    \"metaData\": {\n      \"uploadedBy\": \"string\",\n      \"createdAt\": \"date\"\n    },\n    \"ruleExpression\": \"string\",\n    \"ruleAST\": {\n      \"type\": \"string\",\n      \"left\": \"\u003cRuleNodeModel Instance\u003e or null\",\n      \"right\": \"\u003cRuleNodeModel Instance\u003e or null\",\n      \"value\": \"string\"\n    }\n  }\n}\n```\n\n2. **Combine Rules (POST `/application/api/rule/combine_rule`)**\n   This endpoint combines multiple existing rules into one rule.\n\n#### Request Body\n\n```json\n{\n  \"metaData\": {\n    \"uploadedBy\": \"string\"\n  },\n  \"ruleExpression\": \"List\u003cstring\u003e\"\n}\n```\n\n#### Response Body\n\n```json\n{\n  \"errorMessage\": \"\u003cerrorMessage\u003e or null\",\n  \"responseData\": {\n    \"id\": \"objectID\",\n    \"metaData\": {\n      \"uploadedBy\": \"string\",\n      \"createdAt\": \"date\"\n    },\n    \"ruleExpression\": \"string\",\n    \"ruleAST\": {\n      \"type\": \"string\",\n      \"left\": \"\u003cRuleNodeModel Instance\u003e or null\",\n      \"right\": \"\u003cRuleNodeModel Instance\u003e or null\",\n      \"value\": \"string\"\n    }\n  }\n}\n```\n\n3. **Evaluate Rule (POST `/application/api/rule/evaluate_rule`)**\n   This endpoint evaluates incoming data against an existing rule and return a field `isEligible` for the same.\n\n#### Request Body\n\n```json\n{\n  \"age\": \"number\",\n  \"department\": \"string\",\n  \"salary\": \"number\",\n  \"experience\": \"number\"\n}\n```\n\n#### Response Body\n\n```json\n{\n  \"errorMessage\": \"\u003cerrorMessage\u003e or null\",\n  \"responseData\": {\n    \"age\": \"number\",\n    \"department\": \"string\",\n    \"salary\": \"number\",\n    \"experience\": \"number\",\n    \"isEligible\": \"boolean\"\n  }\n}\n```\n\n4. **Get All Rules (GET `/application/api/rule/get_all_rules`)**\n   This endpoint retrieves all stored rules from the database.\n\n#### Request Body\n\n```json\nNot Required\n```\n\n#### Response Body\n\n```json\n{\n  \"errorMessage\": \"\u003cerrorMessage\u003e or null\",\n  \"responseData\": [\n    {\n      \"id\": \"objectID\",\n      \"metaData\": {\n        \"uploadedBy\": \"string\",\n        \"createdAt\": \"date\"\n      },\n      \"ruleExpression\": \"string\",\n      \"ruleAST\": {\n        \"type\": \"string\",\n        \"left\": \"\u003cRuleNodeModel Instance\u003e or null\",\n        \"right\": \"\u003cRuleNodeModel Instance\u003e or null\",\n        \"value\": \"string\"\n      }\n    }\n  ]\n}\n```\n\n## Error Handling \u0026 Logging\n\nThe application includes proper error handling for invalid rule expressions, evaluation errors, and MongoDB connectivity issues. Comprehensive logging is implemented to track request and response data, aiding in debugging and improving traceability.\n\n## Validation\n\nThe application also implements validation logic:\n\n- Rules Validation: Ensures that rule expressions are well-formed and valid.\n- Evaluation Data Validation: Validates the input data used in the rule evaluation.\n\n## Exception Handling\n\nA detailed exception-handling mechanism is in place to address issues such as invalid rule formats, malformed requests, and database connection problems. These errors are logged for debugging.\n\n## Running Test Cases\n\nBelow are some test cases to ensure the proper functionality of the application:\n\n### Test Case 1: Create Rule\n\n```json\nPOST /application/api/rule/create_rule\n\n{\n  \"metaData\": {\n    \"uploadedBy\": \"testUser\"\n  },\n  \"ruleExpression\": \"(age \u003e 30 AND department = 'Sales')\"\n}\n```\n\n**Expected Output**: Rule should be successfully created and saved in the database.\n\n### Test Case 2: Combine Rules\n\n```json\nPOST /application/api/rule/combine_rule\n\n{\n  \"metaData\": {\n    \"uploadedBy\": \"testUser\"\n  },\n  \"ruleExpression\": [\n    \"((age \u003e 30 AND department = 'Sales') OR (age \u003c 25 AND department = 'Marketing')) AND (salary \u003e 50000 OR experience \u003e 5)\",\n    \"((age \u003e 35 OR department = 'Sales')) AND (salary \u003e 20000 OR experience \u003e 5)\"\n  ]\n}\n```\n\n**Expected Output**: A new combined rule should be created and saved.\n\n### Test Case 3: Evaluate Rule\n\n```json\nPOST /application/api/rule/evaluate_rule\n\n{\n  \"age\": 35,\n  \"department\": \"Sales\",\n  \"salary\": 60000,\n  \"experience\": 6\n}\n```\n\n**Expected Output**: `true` if the data satisfies the rule present in database, otherwise `false`.\n\n# Rule Engine Client\n\nThis project also includes a frontend developed using Angular 18 with Bootstrap and Material UI for styling and responsiveness. The frontend allows users to create rules, evaluate them, and view results with a modern, intuitive, and responsive UI.\n\n## Features\n\n- **Rule Creation**: A form-based UI to input rule expressions.\n- **Rule Evaluation**: Evaluate input data against created rules with a clean and interactive design.\n- **Responsive UI**: Ensures smooth experience across different screen sizes using Bootstrap and Material UI components.\n\n## Frontend Tech Stack\n\n- **Angular** 18: Framework for building the UI.\n- **Angular** CLI: For project scaffolding and development.\n- **Node.js**: Backend for development tools and server-side rendering.\n- **Bootstrap**: For responsive grid and components.\n- **Material UI**: For enhanced user interface design.\n\n## Running the Frontend Application\n\nBefore running the frontend, ensure Node.js and Angular CLI are installed.\n\n1. **Install Node.js** - [Download Node.js](https://nodejs.org/en/download/package-manager)\n2. **Install Angular CLI** - [Angular CLI Installation Guide](https://v17.angular.io/cli)\n\n## Steps to Run:\n\n1. Navigate to the frontend directory:\n\n```bash\ncd rule-engine-AST/rule_engine_client\n```\n\n2. Install dependencies:\n\n```bash\nnpm install\n```\n\n3. Run the frontend application:\n\n```bash\nnpm start\n```\n\nThe frontend will be accessible at `http://localhost:4200`.\n\n## Ports and Backend Integration\n\n- **Frontend Port**: 4200\n- **Backend Port**: 9191\n\nThe frontend interacts with the backend rule engine described above, allowing seamless rule creation and evaluation.\n\n## Conclusion\n\nThis rule engine provides both a robust backend for complex rule evaluation and a responsive frontend UI for easy interaction. It can be further extended to support more advanced rules and evaluation conditions.\n\nThe application can be further extended with additional APIs, more advanced rule structures, or additional validation mechanisms for more complex use cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuvraj0028%2Frule-engine-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuvraj0028%2Frule-engine-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuvraj0028%2Frule-engine-ast/lists"}