> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nx1cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Business rules

> Overview of NexusOne's Business rules feature used to write, approve, and publish the logic behind a decision.

The NexusOne Business rules feature lets you write the logic behind a decision, such as whether to approve a loan. A rule holds
that logic as a decision table. After someone approves and publishes a rule, every system that uses the rule gets the same answer.

NexusOne organizes business rules into workspaces, rules, and versions. A workspace holds rules, and a rule keeps every change
you make to the rule as a version.

## Key features

The Business rules feature provides the following:

* **Access by workspace**: Group related rules in a workspace and decide who can do what in each one.
* **Consistent answers**: Write the logic for a decision once, and every system that uses it gets the same answer.
* **Full version history**: Save every edit to a rule's logic as a new version, so you can always go back to an earlier one.
* **Pre-publish testing**: Simulate a rule with sample input and see how it reached its result.
* **Review before publishing**: Require a second person to approve a version before anyone can publish it.
* **Use anywhere**: Run a published rule from code, the API, or a SQL query.
* **Visible audit trail**: Record each simulation, evaluation, and change to a version.

## How it works

The following sections explain the core concepts behind Business rules in NexusOne.

### Workspaces

A workspace is a project-like folder that holds related rules, such as all the rules that decide whether to approve a loan.
Each workspace has its own members.

Workspaces provide the following:

* **Admin-only creation**: Restrict creating or deleting a workspace to users with the Business rules administrator role.
* **Per-workspace access**: Give a custom NexusOne role a workspace role in one workspace without giving it access to another.
* **Safe archiving**: Archive a workspace you no longer use, instead of deleting it.

### Rules

A rule is the logic for one decision, saved as a decision table. Each rule lives in one workspace.

Rules provide the following:

* **Pre-publish testing**: Simulate a rule with sample input and see how it reached its result.
* **Published version**: Run only the published version of a rule, so a draft never affects a live decision.
* **Run from SQL**: Use a published rule as a function in Trino or Spark, such as over every row in a table.
* **Run with the API**: Send values to a published rule and get a decision back.
* **Transfer between installations**: Export rules from a workspace as a bundle, and import the bundle into another NexusOne
  installation. The other installation imports everything as drafts, and each version goes through approval again.

### Versions

A version is a saved copy of a rule's logic. You save each change as a new version, and a rule has one published version at a
time.

Versions provide the following:

* **Approval stages**: Move a version through the following stages:
  * **Draft**: A version that its author can still edit.
  * **Submitted**: A version that's waiting for approval. Nobody can edit it.
  * **Approved**: A version that an approver accepted. You can publish the version now.
  * **Published**: The version that runs now.
* **Comparison**: Compare two versions of a rule to see what changed.
* **Rollback**: Publish an earlier approved version to replace the one that runs now.

## Roles and permissions

NexusOne controls access to Business rules with two kinds of roles. The following list describes them:

* **NexusOne roles**: Decide whether you can reach the feature.
  For the `nx1_decisions_admin` and `nx1_decisions_user` roles, see
  [Default roles in NexusOne](https://docs.nx1cloud.com/documentation/govern/overview/iam.md#default-roles-in-nexusone).
* **Workspace roles**: Decide what you can do in one workspace. You give workspace roles to a custom NexusOne role, and everyone with that
  role gets them. The custom role must also map to `nx1_decisions_user`, so its users can open Business rules.

The workspace roles are the following:

* **`viewer`**: Read rules and their audit history.
* **`simulator`**: Everything a viewer can do, plus evaluate and simulate rules.
* **`author`**: Everything a simulator can do, plus the following:
  * Create rules and edit drafts.
  * Import or export bundles.
  * Submit versions for approval.
* **`approver`**: Everything a simulator can do, plus approve, reject, and publish versions. Can't author.
* **`workspace_admin`**: Runs a single workspace. Everything an author can do, plus publish versions and manage who has access. Can't approve.

Approval needs a second person. You can't approve a version you wrote or submitted, unless you have the `nx1_decisions_admin` role.

## Tracking changes and decisions

NexusOne records what happens to your rules in the Business rules stream of the [Audit](https://docs.nx1cloud.com/documentation/govern/overview/audit.md#business-rules)
feature. You can search the stream to see who changed a rule and which rule made a decision.

The Business rules stream provides the following:

* **Change history**: See who submitted, approved, or published a version, and which rule it affected.
* **Run history**: See which version ran, the outcome, and how long it took.
* **Tracing a rule**: Filter on the **Ruleset hash** field to find every run of exactly the same rules.

## Use cases

These examples show how different industries can use NexusOne's Business rules capabilities:

* **Financial services**: Publish one loan approval rule, so a web application and a nightly SQL report get the same answer
  for every applicant.
* **Retail**: Have an approver review a change to a discount rule before it goes live, so a customer never gets a discount
  that nobody checked.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.