{"id":15011531,"url":"https://github.com/timophe-91/rulesengine","last_synced_at":"2025-04-12T03:31:49.670Z","repository":{"id":246184934,"uuid":"820118857","full_name":"timophe-91/RulesEngine","owner":"timophe-91","description":"A Json based Rules Engine with extensive Dynamic expression support","archived":false,"fork":false,"pushed_at":"2024-10-11T17:36:24.000Z","size":697,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-10-15T03:02:56.912Z","etag":null,"topics":["bre","business","dotnet","engine","expression-evaluatior","nuget","rules","rules-engine","workflow"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timophe-91.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-25T20:55:15.000Z","updated_at":"2024-10-15T01:21:26.000Z","dependencies_parsed_at":"2024-07-22T22:29:26.038Z","dependency_job_id":"ab8ebb68-9098-4675-ac66-e65647ac1d2a","html_url":"https://github.com/timophe-91/RulesEngine","commit_stats":{"total_commits":230,"total_committers":31,"mean_commits":7.419354838709677,"dds":0.7130434782608696,"last_synced_commit":"07223389aa631b0c42da39de1177436c52403989"},"previous_names":["timophe-91/rulesengine"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timophe-91%2FRulesEngine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timophe-91%2FRulesEngine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timophe-91%2FRulesEngine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timophe-91%2FRulesEngine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timophe-91","download_url":"https://codeload.github.com/timophe-91/RulesEngine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248512763,"owners_count":21116674,"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","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":["bre","business","dotnet","engine","expression-evaluatior","nuget","rules","rules-engine","workflow"],"created_at":"2024-09-24T19:41:12.891Z","updated_at":"2025-04-12T03:31:49.326Z","avatar_url":"https://github.com/timophe-91.png","language":"C#","readme":"![build](https://github.com/timophe-91/RulesEngine/actions/workflows/dotnetcore-build.yml/badge.svg?branch=main)\n[![Coverage Status](https://coveralls.io/repos/github/timophe-91/RulesEngine/badge.svg?branch=main)](https://coveralls.io/github/timophe-91/RulesEngine?branch=main)\n[![Nuget download][download-image]][download-url]\n\n[download-image]: https://img.shields.io/nuget/dt/timophe.RulesEngine\n\n[download-url]: https://www.nuget.org/packages/timophe.RulesEngine/\n\n# Rules Engine ##\n\nNOTICE: This is a FORK of [microsoft/RulesEngine]( https://github.com/microsoft/RulesEngine)\n\nThis fork will develop detached from the original project.\n\n## Now with Interface\n\nI added Interfaces for Rule and Workflow, to easier customize the behaviour of the rule to personal needs. Tried to not\ndo breaking changes.\n\n## Roadmap\n\nThis is the Roadmap of this RulesEngine fork.\n\n- Add Event to OnFailed\n- Enhance and Correct the Wiki\n- Add LogicalRule and LeafRule as classes for easier use\n- Add AI Support for the RulesEngine (OpenAI and Google probably)\n\n\nSomewhat later:\nProbably breaking changes:\n- Migrate from Newtonsoft.Json to System.Text.Json\n\n\n## Overview\n\nRules Engine is a library/NuGet package for abstracting business logic/rules/policies out of a system. It provides a\nsimple way of giving you the ability to put your rules in a store outside the core logic of the system, thus ensuring\nthat any change in rules don't affect the core system.\n\n## Installation\n\nTo install this library, download the latest version\nof [NuGet Package](https://www.nuget.org/packages/timophe.RulesEngine/) from [nuget.org](https://www.nuget.org/) and\nrefer it into your project.\n\n## How to use it\n\nThere are several ways to populate workflows for the Rules Engine as listed below.\n\nYou need to store the rules based on\nthe [schema definition](https://github.com/timophe-91/RulesEngine/blob/main/schema/workflow-schema.json) given, and they\ncan be stored in any store as deemed appropriate like Azure Blob Storage, Cosmos DB, Azure App\nConfiguration, [Entity Framework](https://github.com/timophe-91/RulesEngine#entity-framework), SQL Servers, file systems\netc. For RuleExpressionType `LambdaExpression`, the rule is written as\na [lambda expressions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions).\n\nAn example rule:\n\n```json\n[\n  {\n    \"WorkflowName\": \"Discount\",\n    \"Rules\": [\n      {\n        \"RuleName\": \"GiveDiscount10\",\n        \"SuccessEvent\": \"10\",\n        \"ErrorMessage\": \"One or more adjust rules failed.\",\n        \"ErrorType\": \"Error\",\n        \"RuleExpressionType\": \"LambdaExpression\",\n        \"Expression\": \"input1.country == \\\"india\\\" AND input1.loyaltyFactor \u003c= 2 AND input1.totalPurchasesToDate \u003e= 5000\"\n      },\n      {\n        \"RuleName\": \"GiveDiscount20\",\n        \"SuccessEvent\": \"20\",\n        \"ErrorMessage\": \"One or more adjust rules failed.\",\n        \"ErrorType\": \"Error\",\n        \"RuleExpressionType\": \"LambdaExpression\",\n        \"Expression\": \"input1.country == \\\"india\\\" AND input1.loyaltyFactor \u003e= 3 AND input1.totalPurchasesToDate \u003e= 10000\"\n      }\n    ]\n  }\n]\n```\n\nYou can inject the rules into the Rules Engine by initiating an instance by using the following code -\n\n```c#\nvar rulesEngine = new RulesEngine(workflow);\n```\n\nHere, *workflow* is a list of deserialized objects based on the schema explained above\nOnce initialised, the Rules Engine needs to execute the rules for a given input. This can be done by calling the\nmethod `ExecuteAllRulesAsync`:\n\n```c#\nList\u003cRuleResultTree\u003e response = await rulesEngine.ExecuteAllRulesAsync(workflowName, input);\n```\n\nHere, *workflowName* is the name of the workflow, which is *Discount* in the above-mentioned example. And *input* is the\nobject which needs to be checked against the rules, which itself may consist of a list of class instances.\n\nThe *response* will contain a list of [\n*RuleResultTree*](https://github.com/timophe-91/RulesEngine/wiki/Getting-Started#ruleresulttree) which gives information\nif a particular rule passed or failed.\n\n_A demo app for the is available at [this location](https://github.com/timophe-91/RulesEngine/tree/main/demo)._\n\n## Basic\n\n\u003cdetails\u003e\nA simple example via code only is as follows:\n\n```c#\nList\u003cRule\u003e rules = new List\u003cRule\u003e();\n\nRule rule = new Rule();\nrule.RuleName = \"Test Rule\";\nrule.SuccessEvent = \"Count is within tolerance.\";\nrule.ErrorMessage = \"Over expected.\";\nrule.Expression = \"count \u003c 3\";\nrule.RuleExpressionType = RuleExpressionType.LambdaExpression;\nrules.Add(rule);\n\nvar workflows = new List\u003cWorkflow\u003e();\n\nWorkflow exampleWorkflow = new Workflow();\nexampleWorkflow.WorkflowName = \"Example Workflow\";\nexampleWorkflow.Rules = rules;\n\nworkflows.Add(exampleWorkflow);\n\nvar bre = new RulesEngine.RulesEngine(workflows.ToArray());\n```\n\n\u003c/details\u003e\n\n## Entity Framework\n\n\u003cdetails\u003e\nConsuming Entity Framework and populating the Rules Engine is shown in\nthe [EFDemo class](https://github.com/microsoft/RulesEngine/blob/main/demo/DemoApp/EFDemo.cs) with Workflow rules\npopulating the array and passed to the Rules Engine, The Demo App includes an\nexample [RulesEngineDemoContext](https://github.com/microsoft/RulesEngine/blob/main/demo/DemoApp.EFDataExample/RulesEngineDemoContext.cs)\nusing SQLite and could be swapped out for another provider.\n\n```c#\nvar wfr = db.Workflows.Include(i =\u003e i.Rules).ThenInclude(i =\u003e i.Rules).ToArray();\nvar bre = new RulesEngine.RulesEngine(wfr, null);\n```\n\n*Note: For each level of nested rules expected, a ThenInclude query appended will be needed as shown above.*\n\u003c/details\u003e\n\n## How it works\n\n\u003cdetails\u003e\n\n![](https://github.com/timophe-91/RulesEngine/blob/main/assets/BlockDiagram.png)\n\nThe rules can be stored in any store and be fed to the system in a structure which adheres to\nthe [schema](https://github.com/timophe-91/RulesEngine/blob/main/schema/workflow-schema.json) of WorkFlow model.\n\nA wrapper needs to be created over the Rules Engine package, which will get the rules and input message(s) from any\nstore that your system dictates and put it into the Engine. The wrapper then handles the output using appropriate means.\n\n_Note: To know in detail of the workings of Rules Engine, please\nvisit [How it works section](https://github.com/timophe-91/RulesEngine/wiki/Introduction#how-it-works)\nin [Rules Engine Wiki](https://github.com/timophe-91/RulesEngine/wiki)._\n\n\u003c/details\u003e\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution.\n\n---\n\n_For more details please check out [Rules Engine Wiki](https://github.com/timophe-91/RulesEngine/wiki)._\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimophe-91%2Frulesengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimophe-91%2Frulesengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimophe-91%2Frulesengine/lists"}