{"id":18402519,"url":"https://github.com/wingkwong/pyramid","last_synced_at":"2025-04-07T07:32:13.641Z","repository":{"id":65481451,"uuid":"162801668","full_name":"wingkwong/pyramid","owner":"wingkwong","description":"JSON-based Business Rules Engine","archived":false,"fork":false,"pushed_at":"2023-12-15T02:37:20.000Z","size":22,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T14:34:50.777Z","etag":null,"topics":["bre","business-rules-engine","json","json-based-rules-engine","nodejs","pyramid","rule-engine","rules","rules-engine"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pyramid-rules-engine","language":"JavaScript","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/wingkwong.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},"funding":{"github":"wingkwong","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2018-12-22T10:20:09.000Z","updated_at":"2023-10-12T04:05:53.000Z","dependencies_parsed_at":"2023-12-15T03:50:31.720Z","dependency_job_id":null,"html_url":"https://github.com/wingkwong/pyramid","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"213b2783679bbffdca4e0f6b58d2fb0c841e5911"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wingkwong%2Fpyramid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wingkwong%2Fpyramid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wingkwong%2Fpyramid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wingkwong%2Fpyramid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wingkwong","download_url":"https://codeload.github.com/wingkwong/pyramid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247612342,"owners_count":20966724,"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-rules-engine","json","json-based-rules-engine","nodejs","pyramid","rule-engine","rules","rules-engine"],"created_at":"2024-11-06T02:42:41.410Z","updated_at":"2025-04-07T07:32:13.358Z","avatar_url":"https://github.com/wingkwong.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wingkwong"],"categories":[],"sub_categories":[],"readme":"# pyramid\nJSON-based Business Rules Engine\n\n## Installing\n````\nnpm install pyramid-rules-engine\n````\n\n## Modules\npyramid contains serveral modules - ``loader``, `validator`, `stores`, `loggers`, `operators`, `rules`. \n\n### Loader\nLoader is responsible for loading data files such as data objects and input json file. If data is not found, the rule engine would stop immediately and throw related errors.\n\n### Validator \nValidator is responsible for validating the input source loaded by Loader. The scope includes rule properties, rule id and rule conditions.\n\n### Rule Properties\nProperties such as ``id``, ``name``, ``when`` are mandatory.\n\n### Rule ID\nRule ID must be unqiue.\n\n### Rule Conditions\nRule conditions are objects defined in ``when``. Each object can contain other nested objects.\n\n#### $AND and $OR\nIf you want to define a condition with a logical operators such as AND and OR. You have to use an array with the attribute `$and` and `or`. Each array could only contain two objects. Nested objects are also supported.\n\n#### Condition\nA condition is an an object with three attributes - ``fact``, ``operator`` and ``value``\n\n``fact``: The target attribute which is being used to evalute. It has to be started with a data object, such as ``$$bankruptcy.amountOwed``. Another example for a data object is inside another object would be ``$$applicant.$$applicantAddress.zipcode``.\n\n``operator`: Please refer to Operators below.\n\n``value``: The value is used to compare with the one in input file.\n\nA condition will be evaluted and return a boolean indicating if the condition is met with the defined criteria.\n\n\n### Stores\nStores is responsible for centralizing stores such as ``DATA_OBJECTS_STORE``, ``RULES_STORE``, ``INPUT_FILE_STORE`` and ``RESULT_STORE``\n\n### Loggers\nLoggers is responsible for logging. Two loggers are available. \n\nNormal Logger: \n````\nlogger('Normal Logger');\n````\n\nError Logger: \n````\nerrorLogger('Error Logger');\n````\n\n### Operators \nOperators is responsible for performing mathematical operations. Six operators are available which are ``==``, ``\u003e=``, ``\u003c=``, ``\u003e``, ``\u003c`` and ``!=``. \n\n### Rules\nRules is responsible for initializing the rule engine, process and evalute the defined rules based on the input file and return the result.\n\n## Configuration\n\n- Create a file named pyramid.cfg \n- Define the paths for `DATA_OBJ_DIR`, `RULES_DIR` and `INPUT_FILE`\n- Example:\n````\n{\n    \"DATA_OBJ_DIR\": \"../example/loan-application/data_objects/\",\n    \"RULES_DIR\": \"../example/loan-application/rules/\",\n    \"INPUT_FILE\": \"../example/loan-application/input.json\"\n}\n````\n\n## Define data object\n- Create a file with an extension .data under `DATA_OBJ_DIR`\n- A data object has to be started with `$$`\n- Example:\n````\n{\n    \"$$applicant\": {\n        \"type\": \"object\",\n        \"value\": {\n            \"age\": \"number\",\n            \"applicantAddress\": \"$$applicantAddress\"\n        }\n    }\n}\n````\n\n## Define rule \n- Create a file with an extension .rule under `RULES_DIR`\n- Example: Sample Rule\n````\n{\n    \"id\": 1,\n    \"name\": \"checkApplicantAge\",\n    \"description\": \"Check applicant age \",\n    \"when\": [\n        {\n            \"fact\": \"$$applicant.age\",\n            \"operator\": \"\u003e=\",\n            \"value\": 25\n        }\n    ]\n}\n````\n- Example 2: Complex Rule\n````\n{\n    \"id\": 0,\n    \"name\": \"Loan Application\",\n    \"description\": \"Check if loan application is approved or rejected \",\n    \"when\": [\n        {\n            \"$and\": [\n                {\n                    \"fact\": \"$$applicant.age\",\n                    \"operator\": \"\u003c=\",\n                    \"value\": 25\n                },\n                {\n                    \"$or\": [\n                         {\n                            \"fact\": \"$$bankruptcy.amountOwed\",\n                            \"operator\": \"==\",\n                            \"value\": 100000\n                        },\n                        {\n                            \"fact\": \"$$incomeSource.amount\",\n                            \"operator\": \"\u003e=\",\n                            \"value\": 30000\n                        }\n                    ]\n                }\n            ]\n        },\n        {\n            \"fact\": \"$$applicant.$$applicantAddress.zipcode\",\n            \"operator\": \"==\",\n            \"value\": \"5223\"\n        },\n        {\n            \"fact\": \"$$coApplicant.name\",\n            \"operator\": \"==\",\n            \"value\": \"Milena Sears\"\n        }\n    ]\n}\n````\n\n## Define input file \n- Create a file with an extension .json as `INPUT_FILE`\n- Example:\n````\n{\n    \"applicant\": {\n        \"name\": \"Zayna Wainwright\",\n        \"age\": 24,\n        \"occupation\": \"N/A\",\n        \"applicantAddress\": {\n            \"address\": \"2752  Star Route\",\n            \"zipcode\": \"60634\"\n        }\n    }, \n    \"bankruptcy\": {\n        \"amountOwed\": 3000\n    },\n    \"incomeSource\": {\n        \"amount\": 35000\n    },\n    \"coApplicant\": [\n        {\n            \"name\": \"Milena Sears\",\n            \"applicantReferralCode\": \"CA1234\"\n        },\n        {\n            \"name\": \"Clement Simpson\",\n            \"applicantReferralCode\": \"CA2345\"\n        }\n    ]\n}\n````\n\n## Run\n````\nnode pyramid.js \u003cPYRAMID_CFG_PATH\u003e\n````\n\n## Example\nThe example can be found in folder [example](https://github.com/wingkwong/pyramid/tree/master/example)\n\n## Example Result\n````\n------------------------------------------------------------------------\n[INFO] Load Initialization\n------------------------------------------------------------------------\n[INFO] Loading Configuration file\n[INFO] Loading Data Objects: ../example/loan-application/data_objects/\n[INFO] Loading data object ../example/loan-application/data_objects/applicant.data\n[INFO] Loading data object ../example/loan-application/data_objects/applicantAddress.data\n[INFO] Loading data object ../example/loan-application/data_objects/bankruptcy.data\n[INFO] Loading data object ../example/loan-application/data_objects/coApplicant.data\n[INFO] Loading data object ../example/loan-application/data_objects/coApplicantObject.data\n[INFO] Loading data object ../example/loan-application/data_objects/incomeSource.data\n[INFO] Loading Rules ../example/loan-application/rules/\n[INFO] Loading rule file ../example/loan-application/rules/checkApplicantAge.rule\n[INFO] Loading rule file ../example/loan-application/rules/loanApplication.rule\n[INFO] Loading Input File ../example/loan-application/input.json\n------------------------------------------------------------------------\n[INFO] Validator Initialization\n------------------------------------------------------------------------\n[INFO] Validation Finished. No errors found\n------------------------------------------------------------------------\n[INFO] Rule Engine Initialization\n------------------------------------------------------------------------\n[INFO] Processing Rule 1 - Check Applicant Age\n[INFO] Processing Rule 0 - Loan Application\n------------------------------------------------------------------------\n[INFO] Rule Engine Result Summary\n------------------------------------------------------------------------\n[INFO] Rule 1 (Check Applicant Age) : SUCCESS\n[INFO] Rule 0 (Loan Application) : FAILURE\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwingkwong%2Fpyramid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwingkwong%2Fpyramid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwingkwong%2Fpyramid/lists"}