{"id":19028599,"url":"https://github.com/project-flogo/rules","last_synced_at":"2025-07-04T06:07:17.685Z","repository":{"id":41162046,"uuid":"125570640","full_name":"project-flogo/rules","owner":"project-flogo","description":"Golang based Rules for Real-time Contextual Decisions","archived":false,"fork":false,"pushed_at":"2023-02-14T15:00:19.000Z","size":10273,"stargazers_count":114,"open_issues_count":13,"forks_count":39,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-17T12:34:08.316Z","etag":null,"topics":["edge","edge-computing","event-driven","event-processing","events","golang","golang-library","rete","rules-engine","rules-processor","ruleset"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/project-flogo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-03-16T21:15:04.000Z","updated_at":"2025-03-11T01:58:11.000Z","dependencies_parsed_at":"2024-06-18T15:32:57.129Z","dependency_job_id":"6855a54e-1bf8-4589-9dd9-3ea2fbf766cd","html_url":"https://github.com/project-flogo/rules","commit_stats":null,"previous_names":["tibcosoftware/bego"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/project-flogo/rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/project-flogo%2Frules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/project-flogo%2Frules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/project-flogo%2Frules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/project-flogo%2Frules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/project-flogo","download_url":"https://codeload.github.com/project-flogo/rules/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/project-flogo%2Frules/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263457183,"owners_count":23469290,"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":["edge","edge-computing","event-driven","event-processing","events","golang","golang-library","rete","rules-engine","rules-processor","ruleset"],"created_at":"2024-11-08T21:11:40.854Z","updated_at":"2025-07-04T06:07:17.656Z","avatar_url":"https://github.com/project-flogo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src =\"https://raw.githubusercontent.com/TIBCOSoftware/flogo/master/images/flogo-ecosystem_Rules.png\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" \u003e\n  \u003cb\u003eRules is a lightweight library written in Golang to simplify the building of contextually aware, declaritive rules.\u003c/b\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://travis-ci.org/TIBCOSoftware/flogo.svg\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/dependencies-up%20to%20date-green.svg\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-BSD%20style-blue.svg\"/\u003e\n  \u003ca href=\"https://gitter.im/project-flogo/Lobby?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link\"\u003e\u003cimg src=\"https://badges.gitter.im/Join%20Chat.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\n### Prerequisites\nTo get started with the Flogo Rules you'll need to have a few things\n* The Go programming language version 1.8 or later should be [installed](https://golang.org/doc/install).\n* The **GOPATH** environment variable on your system must be set properly\n\n### Install\n```\n$ go get -u github.com/project-flogo/rules/...\n```\n_Note that the -u parameter automatically updates rules if it exists_\n\n## Getting Started\nGetting started should be fairly easy. Lets start off with some definitions around various types used.\n\n### Definitions\nA `Tuple` represents an event or a business object and provides runtime data to the rules. It is always of a certain type.\n\nA `TupleTypeDescriptor` defines the type or structure of a `Tuple`. It defines a tuple's properties and data types, and primary keys. It also defines the time to live for the tuple\n\nA `TupleType` is a name or an alias for a `TupleTypeDescriptor` \n\nA `Rule` constitutes of multiple Conditions and the rule triggers when all its conditions pass\n\nA `Condition` is an expression involving one or more tuple types. When the expression evaluates to true, the condition passes. In order to optimize a Rule's evaluation, the Rule network needs to know of the TupleTypes and the properties of the TupleType which participate in the `Condition` evaluation. These are provided when constructing the condition and adding it to the rule.\n\nA `Action` is a function that is invoked each time that a matching combination of tuples are found that result in a `true` evaluation of all its conditions. Those matching tuples are passed to the action function.\n\nA `RuleSession` is a handle to interact with the rules API. You can create and register multiple rule sessions. Rule sessions are silos for the data that they hold, they are similar to namespaces. Sharing objects/state across rule sessions is not supported.\n \nEach rule creates its own evaluation plan or a network. Multiple rules collectively form the rule network\n\nTuples can be created using `NewTuple` and then setting its properties. The tuple is then `Assert`-ed into the rule session and this triggers rule evaluations.\nA tuple can be `Retract`ed from the rule session to take it out of play for rules evaluations.\n\n### Usage\nNow lets see some code in action. Below code snippet demonstrates usage of the Rules API,\n\nFirst we start off with loading the `TupleDescriptor`. It accepts a JSON string defining all the tuple descriptors.\n\n\tfmt.Printf(\"Loaded tuple descriptor: \\n%s\\n\", tupleDescriptor)\n\t//First register the tuple descriptors\n\terr := model.RegisterTupleDescriptors(tupleDescriptor)\n\tif err != nil {\n\t\tfmt.Printf(\"Error [%s]\\n\", err)\n\t\treturn\n\t}\n\nNext create a `RuleSession` and add all the `Rule`s with their `Condition`s and `Actions`s.\n\n\t//Create a RuleSession\n\trs, _ := ruleapi.GetOrCreateRuleSession(\"asession\")\n\n\t//// check for name \"Bob\" in n1\n\trule := ruleapi.NewRule(\"n1.name == Bob\")\n\trule.AddCondition(\"c1\", []string{\"n1\"}, checkForBob, nil)\n\trule.SetAction(checkForBobAction)\n\trule.SetContext(\"This is a test of context\")\n\trs.AddRule(rule)\n\tfmt.Printf(\"Rule added: [%s]\\n\", rule.GetName())\n\n\t// check for name \"Bob\" in n1, match the \"name\" field in n2,\n\t// in effect, fire the rule when name field in both tuples is \"Bob\"\n\trule2 := ruleapi.NewRule(\"n1.name == Bob \u0026\u0026 n1.name == n2.name\")\n\trule2.AddCondition(\"c1\", []string{\"n1\"}, checkForBob, nil)\n\trule2.AddCondition(\"c2\", []string{\"n1\", \"n2\"}, checkSameNamesCondition, nil)\n\trule2.SetAction(checkSameNamesAction)\n\trs.AddRule(rule2)\n\tfmt.Printf(\"Rule added: [%s]\\n\", rule2.GetName())\n\t\n\t//Finally, start the rule session before asserting tuples\n\t//Your startup function, if registered will be invoked here\n\trs.Start(nil)\n\nHere we create and assert the actual `Tuple's` which will be evaluated against the `Rule's` `Condition's` defined above.\n\n\t//Now assert a \"n1\" tuple\n\tfmt.Println(\"Asserting n1 tuple with name=Tom\")\n\tt1, _ := model.NewTupleWithKeyValues(\"n1\", \"Tom\")\n\tt1.SetString(context.TODO(), \"name\", \"Tom\")\n\trs.Assert(context.TODO(), t1)\n\n\t//Now assert a \"n1\" tuple\n\tfmt.Println(\"Asserting n1 tuple with name=Bob\")\n\tt2, _ := model.NewTupleWithKeyValues(\"n1\", \"Bob\")\n\tt2.SetString(context.TODO(), \"name\", \"Bob\")\n\trs.Assert(context.TODO(), t2)\n\n\t//Now assert a \"n2\" tuple\n\tfmt.Println(\"Asserting n2 tuple with name=Bob\")\n\tt3, _ := model.NewTupleWithKeyValues(\"n2\", \"Bob\")\n\tt3.SetString(nil, \"name\", \"Bob\")\n\trs.Assert(context.TODO(), t3)\n\nFinally, once all `Rule` `Condition's` are evaluated and `Action's` are executed, we can `Retract` all the `Tuple's` from the `RuleSession` and unregister the RuleSession.\n\n\t//Retract tuples\n\trs.Retract(context.TODO(), t1)\n\trs.Retract(context.TODO(), t2)\n\trs.Retract(context.TODO(), t3)\n\n\t//delete the rule\n\trs.DeleteRule(rule.GetName())\n\n\t//unregister the session, i.e; cleanup\n\trs.Unregister()\n\n### Try out this example\n\n```\n$ go get github.com/project-flogo/rules/examples/rulesapp\n```\nEither manually run from source\n```\n$ cd $GOPATH/src/github.com/project-flogo/rules/examples/rulesapp\n$ go run main.go\n```\nor install and run\n\n```\n$ cd $GOPATH/src/github.com/project-flogo/rules/examples/rulesapp\n$ go install\n$ ./$GOPATH/bin/rulesapp\n\n```\n## Running Rules in a Flogo App\nTo use the Rules action in your Flogo App, refer to `examples/flogo/simple/README`\n\n## Connect with us\n\nIf you have any questions, feel free to post an issue and tag it as a question, email flogo-oss@tibco.com or chat with the team and community:\n\n* The [project-flogo/Lobby](https://gitter.im/project-flogo/Lobby?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link) Gitter channel should be used for general discussions, start here for all things Flogo/Flogo Rules,etc!\n* The [project-flogo/developers](https://gitter.im/project-flogo/developers?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link) Gitter channel should be used for developer/contributor focused conversations.\n\n## License \nFlogo Rules source code in [this](https://github.com/project-flogo/rules) repository is under a BSD-style license, refer to [LICENSE](https://github.com/project-flogo/rules/blob/master/LICENSE) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproject-flogo%2Frules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproject-flogo%2Frules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproject-flogo%2Frules/lists"}