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

# Component Dependencies

> Component dependencies allow you to create dependencies between components, and model your app as a graph.

## Why Dependencies?

Most applications have either explicit or implicit dependencies between the different components that comprise them.

For example, given an app that comprises a [Helm chart](/guides/helm-chart-components) component and a [Terraform component](./terraform-components):

```toml components/helm.toml theme={null}
# helm
name       = "helm"
type       = "helm_chart"
chart_name = "helm"
dependencies = ["database"]

[connected_repo]
directory = "components/helm"
repo      = "<your-org>/<your-repo>"
branch    = "main"

[values]
database_url = "{{.nuon.components.database.outputs.database_url}}"
```

```toml components/database.toml theme={null}
# terraform
name              = "database"
type              = "terraform_module"
terraform_version = "1.11.3"

[connected_repo]
directory = "components/database"
repo      = "<your-org>/<your-repo>"
branch    = "main"
```

In this example, the `helm` chart requires that the database be provisioned *before* it is deployed. Otherwise, the
database will not exist yet, and the `database_url` output will not be defined.

When deprovisioning the install, the `helm` chart must be deprovisioned *before* the database, to ensure no active
dependencies exist, preventing the database from being shut down.

## Defining Component Dependencies

To support this, you can define one or more dependencies on each component, telling Nuon what other components it relies on.
Nuon will use your configuration to build a dependency graph, to ensure components are provisioned and deprovisioned in the correct order.

<Warning>
  The dependency graph is directed and *acyclic*, which means circular dependencies are not supported.
  Nuon checks for cycles and will error if you attempt to define one.
</Warning>

Dependencies can be explicitly defined using the `dependencies` field in each component's configuration file.
You can specify which components a given component depends on by listing their names in the `dependencies` array.

Taking the example above, you can make the Helm chart depend on the database by adding it to the dependencies list.

With the directory-based approach, you can specify dependencies explicitly in each component file:

```toml components/database.toml theme={null}
# terraform
name              = "database"
type              = "terraform_module"
terraform_version = "1.11.3"

[connected_repo]
directory = "components/database"
repo      = "<your-org>/<your-repo>"
branch    = "main"
```

```toml components/helm.toml theme={null}
# helm
name       = "helm"
type       = "helm_chart"
chart_name = "helm"
dependencies = ["database"]

[connected_repo]
directory = "components/helm"
repo      = "<your-org>/<your-repo>"
branch    = "main"

[values]
database_url = "{{.nuon.components.database.outputs.database_url}}"
```

## Install Provisioning

When an install is provisioned, Nuon will generate a graph of the app based on the defined dependencies.
Nuon will automatically deploy the *latest* build of each component to the install. In the previous example, this means
that the database component would be deployed *before* the Helm chart.

For example, when you create a new install, each component will automatically be deployed.

To check the status of each component on the install:

```sh theme={null}
nuon installs components
```

## Install Deprovisioning

When an install is deprovisioned, Nuon will generate a graph of all the deployed components on the install, and walk
them in reverse, to deprovision them properly. In the previous example, this means the helm component would be
deprovisioned *before* the database.

## Toggleable components

If a component is [toggleable](/guides/toggleable-components), its enabled state has to stay consistent with the
dependency graph: an enabled component cannot depend on a disabled one, and a component cannot be disabled while a
dependent is still enabled. Nuon validates this on every sync. See the
[Toggleable Components guide](/guides/toggleable-components#dependencies) for details.
