# Edit Rules Files

Rules files define how an app gets created by the template.

There are two type of rules files: `template-to-app-rules.json` and `app-to-template-rules.json`. They use the same syntax, but serve different purposes.

- `template-to-app-rules.json` defines the rules that the template follows when creating an app. For example, you can define a rule that specifies that if an org doesn’t use certain objects, the app doesn't use them in dashboards or the dataflow. Another rule can replace a label name in a chart with the name of a field from a Salesforce object selected in a wizard question. Rules also define how variables are handled. For example, if the wizard asks which fields to include in filters for accounts, `template-to-app-rules.json`determines how that choice is reflected in dashboards.
- `app-to-template-rules.json` provides rules for converting an updated source app back to template form. After changing the source app, you update the template object with a PUT call to the CRM Analytics REST API. For example, you can tokenize all asset files every time they are pulled out of the source app. You use app-to-template rules infrequently, because you're unlikely to update the source app often.

The rules file is referenced from `template-info.json`:

```nolang
"rules" : [
    { "type" : "appToTemplate", "file" : "appToTemplateRules.json" },
    { "type" : "templateToApp", "file" : "templateToAppRules.json" }
],
```

The bulk of what follows details the use of `template-to-app-rules.json`.

- **[Rules Files Structure](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-rules-files-structure.md)**

  Rules files can contain three sections: rules, constants, and macros.

- **[Structuring and Organizing Rules](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-rules-structure.md)**

  The rules section of `template-to-app-rules.json` defines the rules followed by the template.

- **[Rules Syntax](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-rules-syntax.md)**

  The rules object may contain any number of rule objects. A rule object is made up of:

- **[Actions in Rules](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-actions-in-rules.md)**

  Actions define what a rule does. Use constants to make it easier to perform any action.

- **[Actions Syntax for Rules](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-actions-syntax-rules.md)**

- **[Use Functions in Rules](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-functions.md)**

  Functions make rules more powerful. For example, use functions to apply rules iteratively to arrays or to make rules conditional on the content of a string or an array. CRM Analytics Templates supports string, array, and json functions as well as static math and sfdc_fma functions.

- **[Macros in Rules](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-macros-in-rules.md)**

  Use a macro when a single rule executes repeatedly on different JSON node paths.

**See Also**

- [rules.json Attributes](/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-rules-json-attributes.md)
