{"id":18773527,"url":"https://github.com/farfetch/rules-framework","last_synced_at":"2025-04-13T09:12:50.472Z","repository":{"id":37491491,"uuid":"195823972","full_name":"Farfetch/rules-framework","owner":"Farfetch","description":"A generic framework that allows defining and evaluating rules for complex business scenarios.","archived":false,"fork":false,"pushed_at":"2025-02-22T17:23:53.000Z","size":3134,"stargazers_count":41,"open_issues_count":31,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T09:12:44.591Z","etag":null,"topics":["condition","hacktoberfest","priority","rule","rules-evaluation"],"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/Farfetch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-07-08T14:02:24.000Z","updated_at":"2025-02-25T16:59:34.000Z","dependencies_parsed_at":"2023-12-25T17:56:48.094Z","dependency_job_id":"dab0ea26-8c02-4080-9917-4bd7efce7cde","html_url":"https://github.com/Farfetch/rules-framework","commit_stats":null,"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Frules-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Frules-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Frules-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Frules-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Farfetch","download_url":"https://codeload.github.com/Farfetch/rules-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688565,"owners_count":21145766,"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":["condition","hacktoberfest","priority","rule","rules-evaluation"],"created_at":"2024-11-07T19:34:19.332Z","updated_at":"2025-04-13T09:12:50.437Z","avatar_url":"https://github.com/Farfetch.png","language":"C#","readme":"# Rules Framework\n\nRules.Framework is a generic framework that allows defining and evaluating rules for complex business scenarios.\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8b48f4541fba4d4b8bad2e9a8563ede3)](https://app.codacy.com/gh/Farfetch/rules-framework?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Farfetch/rules-framework\u0026utm_campaign=Badge_Grade_Settings)\n[![.NET build](https://github.com/luispfgarces/rules-framework/actions/workflows/dotnet-build.yml/badge.svg)](https://github.com/luispfgarces/rules-framework/actions/workflows/dotnet-build.yml)\n\n## What is a rule\n\nA rule is a data structure limited in time (`date begin` and `date end`), whose content is categorized by a `content type`. Its applicability is constrained by `conditions`, and a `priority` value is used as untie criteria when there are multiple rules applicable.\n\n## Why use rules\n\nBy using rules, we're able to abstract a multiplicity of business scenarios through rules configurations, instead of heavy code developments. Rules enable a fast response to change and a better control of the business logic by the product owners.\n\n## Packages\n\n|Name                             |nuget.org|downloads|fuget.org|\n|---------------------------------|----|---------|-----|\n|[Rules.Framework](#rulesframework)|[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.svg?logo=nuget)](https://www.nuget.org/packages/Rules.Framework/)|[![downloads](https://img.shields.io/nuget/dt/Rules.Framework.svg?logo=nuget\u0026color=blueviolet)](https://www.nuget.org/packages/Rules.Framework/)|[![Rules.Framework on fuget.org](https://www.fuget.org/packages/Rules.Framework/badge.svg)](https://www.fuget.org/packages/Rules.Framework)\n|[Rules.Framework.Providers.MongoDB](#rulesframeworkprovidersmongodb)|[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.Providers.MongoDB.svg?logo=nuget)](https://www.nuget.org/packages/Rules.Framework.Providers.MongoDB/)|[![downloads](https://img.shields.io/nuget/dt/Rules.Framework.Providers.MongoDB.svg?logo=nuget\u0026color=blueviolet)](https://www.nuget.org/packages/Rules.Framework.Providers.MongoDB/)|[![Rules.Framework on fuget.org](https://www.fuget.org/packages/Rules.Framework.Providers.MongoDB/badge.svg)](https://www.fuget.org/packages/Rules.Framework.Providers.MongoDB)\n|[Rules.Framework.WebUI](#rulesframeworkwebui)|[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.WebUI.svg?logo=nuget)](https://www.nuget.org/packages/Rules.Framework.WebUI/)|[![downloads](https://img.shields.io/nuget/dt/Rules.Framework.WebUI.svg?logo=nuget\u0026color=blueviolet)](https://www.nuget.org/packages/Rules.Framework.WebUI/)|[![Rules.Framework on fuget.org](https://www.fuget.org/packages/Rules.Framework.WebUI/badge.svg)](https://www.fuget.org/packages/Rules.Framework.WebUI)\n\n## Rules.Framework\n[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.svg?logo=nuget)](https://www.nuget.org/packages/Rules.Framework/)\n\nThe Rules.Framework package contains the core of the rules engine. It includes an in-memory provider for the rules data source.\n\n### Basic usage\n\nTo set up a `RulesEngine`, define the content types and condition types to be used.\n\n```csharp\nenum ContentType { FreeSample = 1, ShippingCost = 2 }\nenum ConditionType { ClientType = 1, Country = 2 }\n```\n\nBuild the engine with the `RulesEngineBuilder`.\n\n```csharp\nvar rulesEngine = RulesEngineBuilder.CreateRulesEngine()\n    .WithContentType\u003cContentType\u003e()\n    .WithConditionType\u003cConditionType\u003e()\n    .SetInMemoryDataSource()\n    .Configure(c =\u003e c.PriorityCriteria = PriorityCriterias.TopmostRuleWins)\n    .Build();\n```\nUse the `RuleBuilder` to assemble a rule.\n\n```csharp\nvar ruleForPremiumFreeSample = RuleBuilder\n    .NewRule\u003cContentType, ConditionType\u003e()\n    .WithName(\"Rule for perfume sample for premium clients.\")\n    .WithContent(ContentType.FreeSample, \"SmallPerfumeSample\")\n    .WithCondition(ConditionType.ClientType, Operators.Equal, \"Premium\")\n    .WithDateBegin(new DateTime(2020, 01, 01))\n    .Build();\n```\n\nAdd a rule to the engine with the `AddRuleAsync()`.\n\n```csharp\nrulesEngine.AddRuleAsync(ruleForPremiumFreeSample.Rule, RuleAddPriorityOption.ByPriorityNumber(1));\n```\n\nGet a matching rule by using the `MatchOneAsync()` and passing a date and conditions.\n\n```csharp\nvar matchingRule = rulesEngine.MatchOneAsync(\n        ContentType.FreeSample, \n        new DateTime(2021, 12, 25), \n        new[]\n        {\n            new Condition\u003cConditionType\u003e(ConditionType.ClientType, \"Premium\")\n        });\n```\n\n### Complex scenarios\n\nFor a more thorough explanation of the Rules.Framework and all it enables, check the [Wiki](https://github.com/Farfetch/rules-framework/wiki). \n\nCheck also the test scenarios and samples available within the source-code, to see more elaborated examples of its application.\n\n## Rules.Framework.Providers.MongoDB\n[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.Providers.MongoDb?logo=nuget)](https://www.nuget.org/packages/Rules.Framework.Providers.MongoDb/)\n\nTo keep rules persisted in a MongoDB database, use the extension method in the Providers.MongoDB package to pass your MongoClient and MongoDbProviderSettings to the `RulesEngineBuilder`.\n\n```csharp\nvar rulesEngine = RulesEngineBuilder.CreateRulesEngine()\n    .SetInMongoDBDataSource(mongoClient, mongoDbProviderSettings)\n```\n\n## Rules.Framework.WebUI\n[![Nuget Package](https://img.shields.io/nuget/v/Rules.Framework.WebUI?logo=nuget)](https://www.nuget.org/packages/Rules.Framework.WebUI/)\n\nThe WebUI package offers a way of visualizing the rules in your web service. To configure the UI, pass the rules engine as generic to the `IApplicationBuilder` extension method provided.\n\n```csharp\napp.UseRulesFrameworkWebUI(rulesEngine.CreateGenericEngine());\n```\n\nAccess is done via the endpoint `{host}/rules/index.html`.\n\n![webUISample](docs/WebUISample.png)\n\n## Features\n\nThe following list presents features already available and others planned:\n- [x] Rules evaluation (match one)\n- [x] Rules evaluation (match many)\n- [x] Rules content serialization\n- [x] Rules management (Create, Read, Update)\n- [x] In-memory data source support\n- [x] MongoDB data source support\n- [ ] SQL Server data source support\n- [ ] Rules data source caching\n- [x] Rules data source compilation\n- [x] WebUI for rules visualization\n\n## Documentation\n\nSee the [Wiki](https://github.com/Farfetch/rules-framework/wiki) for full documentation, short examples and other information.\n\n## Contributing\n\nContributions are more than welcome! Submit comments, issues or pull requests, we promise to keep an eye on them :)\n\nHead over to [CONTRIBUTING](CONTRIBUTING.md) for further details.\n\n## License\n\n[MIT License](LICENSE.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarfetch%2Frules-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarfetch%2Frules-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarfetch%2Frules-framework/lists"}