{"id":13600649,"url":"https://github.com/hyperjumptech/grule-rule-engine","last_synced_at":"2025-05-14T13:04:21.214Z","repository":{"id":37484594,"uuid":"227806703","full_name":"hyperjumptech/grule-rule-engine","owner":"hyperjumptech","description":"Rule engine implementation in Golang","archived":false,"fork":false,"pushed_at":"2024-07-29T00:08:28.000Z","size":11132,"stargazers_count":2322,"open_issues_count":78,"forks_count":355,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-05-13T18:11:27.648Z","etag":null,"topics":["golang","hacktoberfest","hacktoberfest2021","inference-engine","rule","rule-based","rule-based-engine","rule-engine"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperjumptech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":"CODE_OF_CONDUCTS.md","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":"2019-12-13T09:45:58.000Z","updated_at":"2025-05-12T00:49:11.000Z","dependencies_parsed_at":"2024-01-14T04:45:21.160Z","dependency_job_id":"aec48aad-48b4-4471-810f-fe6e75adbc69","html_url":"https://github.com/hyperjumptech/grule-rule-engine","commit_stats":{"total_commits":209,"total_committers":45,"mean_commits":4.644444444444445,"dds":"0.36363636363636365","last_synced_commit":"e4e90fe744ffffc1010edb7d12c5693a0b9ce477"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fgrule-rule-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fgrule-rule-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fgrule-rule-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fgrule-rule-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperjumptech","download_url":"https://codeload.github.com/hyperjumptech/grule-rule-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149863,"owners_count":22022850,"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":["golang","hacktoberfest","hacktoberfest2021","inference-engine","rule","rule-based","rule-based-engine","rule-engine"],"created_at":"2024-08-01T18:00:45.752Z","updated_at":"2025-05-14T13:04:21.157Z","avatar_url":"https://github.com/hyperjumptech.png","language":"Go","readme":"\n[![Gopheer Holds The Rule](https://github.com/hyperjumptech/grule-rule-engine/blob/master/gopher-grule.png?raw=true)](https://github.com/hyperjumptech/grule-rule-engine/blob/master/gopher-grule.png?raw=true)\n\n[![Go Report Card](https://github.com/hyperjumptech/grule-rule-engine/actions/workflows/build-test-workflow.yml/badge.svg)](https://github.com/hyperjumptech/grule-rule-engine/actions/workflows/build-test-workflow.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hyperjumptech/grule-rule-engine)](https://goreportcard.com/report/github.com/hyperjumptech/grule-rule-engine)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n__\"Gopher Holds The Rules\"__\n\n# Grule-Rule-Engine\n\n```go\nimport \"github.com/hyperjumptech/grule-rule-engine\"\n```\n\n## Rule Engine for Go\n\n**Grule** is a Rule Engine library for the Go (Golang) programming language. Inspired by the acclaimed JBOSS Drools, and done in a much simpler manner.\n\nLike **Drools**, **Grule** has its own *DSL* or Domain-Specific Language.\n\nBelow is an example of Drools's DRL or Drools Rule Language:\n\n```drool\nrule \"SpeedUp\"\n    salience 10\n    when\n        $TestCar : TestCarClass( speedUp == true \u0026\u0026 speed \u003c maxSpeed )\n        $DistanceRecord : DistanceRecordClass()\n    then\n        $TestCar.setSpeed($TestCar.Speed + $TestCar.SpeedIncrement);\n        update($TestCar);\n        $DistanceRecord.setTotalDistance($DistanceRecord.getTotalDistance() + $TestCar.Speed);\n        update($DistanceRecord);\nend\n```\n\nGrule's GRL is as follows:\n\n```go\nrule SpeedUp \"When testcar is speeding up we keep increase the speed.\" salience 10  {\n    when\n        TestCar.SpeedUp == true \u0026\u0026 TestCar.Speed \u003c TestCar.MaxSpeed\n    then\n        TestCar.Speed = TestCar.Speed + TestCar.SpeedIncrement;\n        DistanceRecord.TotalDistance = DistanceRecord.TotalDistance + TestCar.Speed;\n}\n```\n\n# What is a Rule Engine\n\nThere isn't a better explanation than the article authored by Martin Fowler. You can read the article here ([RulesEngine by Martin Fowler](https://martinfowler.com/bliki/RulesEngine.html)).\n\nTaken from **TutorialsPoint** website (with slight modifications),\n\nThe **Grule** Rule Engine is a Production Rule System that uses the rule-based approach to implement an Expert System. Expert Systems are knowledge-based systems that use knowledge representations to process acquired knowledge into a knowledgebase that can be used for reasoning.\n\nA Production Rule System is Turing complete with a focus on knowledge representation to express propositional and first-order logic in a concise, non-ambiguous and declarative manner.\n\nThe brain of a Production Rules System is an *Inference Engine* that can scale to a large number of rules and facts. The Inference Engine matches facts and data against Production Rules – also called **Productions** or just **Rules** – to infer conclusions which result in actions.\n\nA Production Rule is a two-part structure that uses first-order logic for reasoning over knowledge representation. A business rule engine is a software system that executes one or more business rules in a runtime production environment.\n\nA Rule Engine allows you to define **“What to Do”** and not **“How to do it.”**\n\n## What is a Rule\n\n*(also taken from TutorialsPoint)*\n\nRules are pieces of knowledge often expressed as, \"When some conditions occur, then do some tasks.\"\n\n```go\nWhen\n   \u003cCondition is true\u003e\nThen\n   \u003cTake desired Action\u003e\n```\n\nThe most important part of a Rule is its when part. If the **when** part is satisfied, the **then** part is triggered.\n\n```go\nrule  \u003crule_name\u003e \u003crule_description\u003e\n   \u003cattribute\u003e \u003cvalue\u003e {\n   when\n      \u003cconditions\u003e\n\n   then\n      \u003cactions\u003e\n}\n```\n\n## Advantages of a Rule Engine\n\n### Declarative Programming\n\nRules make it easy to express solutions to difficult problems and get the verifications as well. Unlike code, Rules are written with less complex language; Business Analysts can easily read and verify a set of rules.\n\n### Logic and Data Separation\n\nThe data resides in the Domain Objects and the business logic resides in the Rules. Depending upon the kind of project, this kind of separation can be very advantageous.\n\n### Centralization of Knowledge\n\nBy using Rules, you create a repository of knowledge (a knowledge base) which is executable. It is a single point of truth for business policy. Ideally, Rules are so readable that they can also serve as documentation.\n\n### Agility To Change\n\nSince business rules are actually treated as data. Adjusting the rule according to business's dynamic nature becomes trivial. No need to re-build code or deploy as normal software development does - you only need to roll out sets of rules and apply them to knowledge repository.\n\n## Use Cases\n\nThe following cases are better solved with a rule-engine:\n\n1. An expert system that must evaluate facts to provide some sort of real-world\n   conclusion. If not using a RETE-style rule engine, one would code up a\n   cascading set of `if`/`else` statements, and the permutations of the\n   combinations of how those might be evaluated would quickly become impossible\n   to manage. A table-based rule engine might suffice, but it is still more\n   brittle against change, and is not terribly easy to code. A system like Grule\n   allows you to describe the rules and facts of your system, releasing you from\n   the need to describe how the rules are evaluated against those facts, and hiding\n   the bulk of that complexity from you.\n\n2. A rating system. For example, a bank system may want to create a \"score\" for\n   each customer based on the customer's transaction records (facts). We could\n   see their score change based on how often they interact with the bank, how\n   much money they transfer in and out, how quickly they pay their bills, how\n   much interest they accrue, how much they earn for themselves or for the bank, \n   and so on. A rule engine could be provided by a developer, and the specification \n   of the facts and rules can then be supplied by subject matter experts within the \n   bank's customer analytics department. Decoupling these different teams puts the \n   responsibilities where they should be.\n\n3. Computer games. Player status, rewards, penalties, damage, scores, and\n   probability systems are many different examples of where rules play a\n   significant part in most computer games. These rules can interact in\n   very complex ways, often times in ways that the developer didn't foresee.\n   Coding these dynamic situations through the use of a scripting language \n   (e.g. Lua) can get quite complex, and a rule engine can help simplify \n   the work tremendously.\n\n4. Classification systems. This is actually a generalization of the rating\n   system described above. Using a rule engine, we can classify things such as\n   credit eligibility, biochemical identification, risk assessment for\n   insurance products, potential security threats, and many more.\n\n5. Advice/suggestion system. A \"rule\" is simply another kind of data, which\n   makes it a prime candidate for definition by another program. This program\n   can be another expert system or artificial intelligence. Rules can be\n   manipulated by other systems in order to deal with new types of facts or\n   newly discovered information about the domain which the ruleset is intending\n   to model.\n\nThere are many other use-cases that would benefit from the use of a Rule-Engine. \nThe above cases represent only a small number of the potential ones.\n\nHowever, it is important to remember that a Rule-Engine not a silver bullet, of\ncourse. Many alternatives exist to solve \"knowledge\" problems in software, and\nthose should be employed where they are most appropriate. One would not employ a\nrule engine where a simple `if` / `else` branch would suffice, for instance.\n\nTheres's something else to note: some rule engine implementations are extremely\nexpensive, yet many businesses gain so much value from them that the cost of\nrunning them is easily offset by that value. For even moderately complex use\ncases, the benefit of a strong rule engine that can decouple teams and tame\nbusiness complexity seems to be quite clear.\n\n\n## Docs\n\nDocumentation page [here](docs/Documentation.md)\n\nTo dive into the Tutorial, see the Wiki Docs [here on Github](docs/en/Tutorial_en.md).\n\n### Benchmark\n`Loading rules into KnowledgeBase`:\n\n* To load `100` rules into knowledgeBase it took `99342047 ns/op` (took the highest value) that is equal to `~99.342047ms` and (`49295906 B/op`) `~49.295906MB` memory per operation\n\n* To load `1000` rules into knowledgeBase it took `933617752 ns/op` (took the highest value) that is equal to `~933.617752ms` and (`488126636 B/op`) `~488.126636` memory per operation\n\n`Executing rules against a fact`:\n\n* To execute a fact against 100 rules, Grule Engine took `~9697 ns/op` (took the highest value as base) that is hardly `~0.009697ms` and `3957 B/op` which is pretty fast.\n\n* To execute a fact against 1000 rules, Grule Engine took `~568959 ns/op` (took the highest value as base) that is hardly `~0.568959ms` and `293710 B/op` which is also pretty fast.\n\n\nYou can read the [detail report here](docs/en/Benchmarking_en.md)\n\n# Tasks and Help Wanted\n\nYes. We need contributors to make Grule even better and useful to the Open Source Community.\n\n* Need to do more and more and more tests.\n* Better code coverage test.\n* Better commenting for go doc best practice.\n* Improve function argument handling to be more fluid and intuitive.\n\nIf you really want to help us, simply `Fork` the project and apply for Pull Request.\nPlease read our [Contribution Manual](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCTS.md)\n","funding_links":[],"categories":["Go","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Fgrule-rule-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperjumptech%2Fgrule-rule-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Fgrule-rule-engine/lists"}