> For the complete documentation index, see [llms.txt](https://docs.terrakube.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.terrakube.io/2.34.0/how-it-works/design-and-architecture.md).

# Architecture

Terrakube is a small set of services around a relational database, object storage and an identity provider. You can run all of them in one Kubernetes cluster with the [Helm chart](/2.34.0/getting-started/deployment/helm-chart.md), or on a laptop with [Docker Compose](/2.34.0/getting-started/docker-compose.md).

```mermaid
flowchart TB
    clients([Users, CI pipelines and the Terraform CLI])
    clients --> ui[UI]
    clients --> api[API and scheduler]
    clients --> reg[Registry]
    ui --> api
    api -->|dispatch steps| exec[Executor]
    api --> db[(Database)]
    api --> redis[(Redis)]
    api --> store[(Object storage)]
    exec --> store
    reg --> store
```

The API is the single source of truth: it stores metadata in the database, coordinates through Redis, and keeps state, logs and plans in object storage. The executor does the work and reports back to the API. The registry serves modules and providers straight from object storage.

Terrakube also talks to three things outside its own services:

```mermaid
flowchart LR
    ui[UI] -. sign in .-> dex[Dex] --> idp[(Your identity provider)]
    git[Git provider] -->|webhooks| api[API]
    exec[Executor] -->|clone| git
    exec -->|plan and apply| cloud[Cloud providers]
```

### Components

| Component          | What it does                                                                                                                                                                                                                                                                                   |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **API**            | The single source of truth. Exposes JSON:API and GraphQL for organizations, workspaces, jobs, teams, templates, modules and providers, enforces permissions, and runs the scheduler that dispatches jobs.                                                                                      |
| **Executor**       | Runs the steps of a job (`terraform init/plan/apply`, scripts, policy checks) in a fresh working directory, then reports status and output back to the API. It can be a shared pool of pods, or an [ephemeral Kubernetes Job per run](/2.34.0/getting-started/deployment/ephemeral-agents.md). |
| **Registry**       | A private Terraform registry for modules and providers, protected by the same login as the API.                                                                                                                                                                                                |
| **UI**             | The web interface, a client of the API.                                                                                                                                                                                                                                                        |
| **Dex**            | Handles sign-in and federates to your identity provider. See [User Management](/2.34.0/getting-started/user-management.md).                                                                                                                                                                    |
| **Database**       | Any database supported by Liquibase (PostgreSQL, MySQL, SQL Server, H2 for tests).                                                                                                                                                                                                             |
| **Redis**          | Distributed locks for the scheduler and the live log stream. Required when you run more than one API or executor replica.                                                                                                                                                                      |
| **Object storage** | Terraform state, run output, saved plans and registry modules, on AWS S3, Azure Blob, Google Cloud Storage or a local volume. See [Storage backend](/2.34.0/getting-started/deployment/storage-backend.md).                                                                                    |

### Where to read next

* [Run lifecycle](/2.34.0/how-it-works/run-lifecycle.md): what happens between clicking **New Run** and an applied change.
* [Identity and access](/2.34.0/how-it-works/identity-and-access.md): how users, tokens, CI workloads and cloud providers authenticate.
* [Security](/2.34.0/how-it-works/security.md): the security model.

{% hint style="info" %}
The diagrams in this documentation are written in Mermaid. If your viewer shows them as plain code, open the page on GitHub, where they render.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.terrakube.io/2.34.0/how-it-works/design-and-architecture.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
