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

# Config as code (stackshift.yaml)

> Describe an application in one file in your repository. Every push applies it, every pull request shows a plan, and risky changes wait for you.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Keep services, databases, buckets, domains, jobs, network rules and deploy settings in your repository, and have each push apply them safely.

## Prerequisites

* An application with at least one service connected to a GitHub repository.
* The StackShift CLI if you want to validate and plan from your machine.
* Secrets you reference by name already saved in StackShift. The file never holds secret values.

## Workflow

**Step 1**

Create the file with `stackshift init --name APP`, or download one from a running app with Export stackshift.yaml.

**Step 2**

Add the schema line at the top of the file so your editor checks it as you type.

**Step 3**

Run `stackshift validate --local` to check the file without contacting StackShift.

**Step 4**

Run `stackshift plan` to see each change and its class.

**Step 5**

Commit the file to your project root, or the repository root. Turn on Apply stackshift.yaml on push if it is not already on.

**Step 6**

Push. Automatic changes apply at once, approval changes and the release wait for you in the dashboard, and blocked changes fail the release with the file and line.

## What the file does

One `stackshift.yaml` describes the whole application: its services, databases, buckets, domains, scheduled jobs, network rules and how it deploys. StackShift reads it on every push, plans the changes, applies the safe ones and holds the rest for you.

The file keeps the same format as before: `apiVersion: stackshift.com/v1`, `kind: Application`. Files you already have keep working. Unknown fields are rejected, so an older CLI fails clearly on a newer file.

## Where the file lives

* StackShift looks in the service project root first, then the repository root.
* The name can be `stackshift.yaml` or `stackshift.yml`.
* With no file, pushes behave exactly as they did before.

## Editor checks and local validation

Put this line first in the file. Editors that support the YAML language server then suggest fields and flag mistakes.

The CLI uses the same schema offline.

```yaml theme={null}
# yaml-language-server: $schema=https://stackshift.cloud/schema/stackshift.json
```

```bash theme={null}
stackshift validate --local
```

## Full example

This file runs a Next.js app on your own server with a database, a bucket, two domains, two scheduled jobs and a staging environment. IDs and names are placeholders.

```yaml stackshift.yaml theme={null}
# yaml-language-server: $schema=https://stackshift.cloud/schema/stackshift.json
apiVersion: stackshift.com/v1
kind: Application
metadata:
  name: pulse
spec:
  teamId: 00000000-0000-4000-8000-000000000001
  services:
    web:
      type: web
      deploymentMode: connected_node
      targetNodeId: 00000000-0000-4000-8000-000000000002
      repository: https://github.com/example-org/pulse-web
      branch: main
      framework: nextjs
      port: 3000
      memoryMB: 1792
      cpuMillicores: 2000
      ephemeralVolumes: [/app/.next/cache]
      deploy:
        strategy: auto
        health:
          path: /api/install/status
          startupGrace: 120s
        release:
          - pnpm db:migrate --all --yes
      bindings:
        - database: main
          env: MONGODB_URI
      env:
        NEXT_PUBLIC_APP_URL: https://example.com
        AUTH_URL: https://example.com
        AUTH_SECRET:
          secretRef: AUTH_SECRET
        PAYMENTS_SECRET_KEY:
          secretRef: PAYMENTS_SECRET_KEY
      secrets:
        required: [AUTH_SECRET, CRON_SECRET, PAYMENTS_SECRET_KEY]
      network:
        redirects:
          www.example.com:
            to: https://example.com
            status: 308
        headers:
          hsts: true
          frame: SAMEORIGIN
          nosniff: true
        rateLimits:
          - name: auth
            paths: [/api/auth/*]
            methods: [POST]
            limit: 20/1m
            key: ip
      alerts:
        - metric: memory
          above: 90
          for: 5m
          cooldown: 30m
          channels: [email, inbox]
  databases:
    main:
      engine: mongodb
      version: "8.0"
      sizeGB: 5
      backups:
        schedule: "0 2 * * *"
        keep: 14d
  buckets:
    media:
      name: pulse-media
  domains:
    - service: web
      name: example.com
    - service: web
      name: www.example.com
  jobDefaults:
    retries: 2
    timeout: 60s
  jobs:
    messaging-outbox:
      http:
        service: web
        path: /api/cron/messaging-outbox
        headers:
          Authorization: "Bearer ${{ secrets.CRON_SECRET }}"
      schedule: "* * * * *"
    finance:
      http:
        service: web
        path: /api/cron/finance
        headers:
          Authorization: "Bearer ${{ secrets.CRON_SECRET }}"
      schedule: "0 3 * * *"
      timezone: Africa/Lagos
  environments:
    production:
      branchPattern: main
    staging:
      inheritFrom: production
      branchPattern: staging
      services:
        web:
          memoryMB: 1024
          env:
            NEXT_PUBLIC_APP_URL: https://staging.example.com
    preview:
      services:
        web:
          env:
            LOG_LEVEL: debug
```

## Deploy settings

These sit under `services.<name>.deploy`. Durations are written like `30s` or `2m`.

* `strategy`: `rolling` starts the new copy, checks it, then stops the old one. It is the default. `recreate` stops the old copy first, so there is a short pause, and it fits small servers. `auto` uses rolling when the server has room and recreate when it does not.
* `health`: `path`, `interval`, `timeout`, `startupGrace` and `failureThreshold`. With only a path, the usual defaults apply for the rest.
* `release`: a list of commands that run once per release, before traffic moves to the new copy. They run in a one-off container from the new image, with the service variables and bindings. Database migrations belong here. If one fails, the release stops and the old copy keeps serving.

## Capacity check

The plan checks whether the server can run the new copy next to the old one before anything builds. Under `rolling`, a deploy that does not fit is blocked. Under `auto`, the plan says it will use `recreate`, with the memory it needs and the memory the server has, and no approval is needed. Choosing `recreate` in the file is your consent to the short pause.

## Environment variables and secrets

Each entry under `env` is one of these:

* A plain string. It is a public value.
* `{ value, public: true }`. The same, written out.
* `{ secretRef: NAME }`. A secret stored in StackShift, by name. The value never appears in the file.
* `{ fromEnv: NAME, secret: true }`. A value read from your env file or shell when you run `stackshift apply`. Without `secret: true`, it stays public.
* `scope`: `build`, `runtime` or `both`. The default is `runtime`, and `both` for browser-public names such as `NEXT_PUBLIC_*`.
* `secrets.required`: a list of secret names. The deploy waits until each one exists.

## References in values

Plain values and job headers can point at other things with `${{ ... }}`, for example `${{ secrets.CRON_SECRET }}`, `${{ services.web.url }}` or `${{ databases.main.host }}`. References resolve at every deploy. A reference that cannot resolve is an error in the plan, never a literal string.

Use `bindings` to connect a service to a database or another service. A binding also handles private networking, the certificate and pooling.

## Network rules

These sit under `services.<name>.network` for web services.

* `redirects`: a host to `{ to, status }`.
* `headers`: `hsts`, `frame` (`DENY` or `SAMEORIGIN`), `nosniff` and `robots`.
* `rateLimits`: a list of `{ name, paths, methods, limit, key }`. A limit looks like `20/1m`, and `key` is `ip`.
* `cache.purgeOnDeploy`: clear the edge cache when a release goes live.
* If a server cannot serve a rule, the plan blocks the change for that server. It is never skipped quietly.

## Alerts

Each entry under `services.<name>.alerts` watches one number for that service and tells you when it stays too high. Stackie On Call checks it, so an alert shows up with your other on-call findings.

* `metric`: `cpu`, `memory`, `disk` or `5xx` are percentages. `disk` is the server's disk, and `5xx` is the share of requests that end in a server error. `restarts` counts how many times the service restarted.
* `above`: the alert fires when every reading stays above this number. For `restarts`, it fires when the count goes over it.
* `for`: how long the value must stay high, as a duration like `5m`. The default is `2m`.
* `cooldown`: after an alert clears, how long to stay quiet before it can fire again, like `30m`. The default is no wait.
* `channels`: where to send it: `inbox`, `email` or `slack`, using the channels you already set up for on-call. The default is `inbox`.
* When the value drops back down, you get one more message saying it recovered.
* Alerts are part of the service, so changing them is an automatic change. Remove an alert from the file to stop it.

## Databases and buckets

Name a database or bucket in the file and StackShift creates it if it is missing. Use `name` to adopt one that already exists. A plain reference by name or ID, as in earlier files, still works.

* Databases: `engine`, `version`, `sizeGB`, `tier`, `backups` (`schedule`, `keep`), `standby`, `pooler`, `public` and `name`. The `engine` and `version` cannot change after creation.
* Buckets: `name`, `public`, `cors` and `lifecycle`.
* Sizes use units, such as `512mb` and `2gb`. `memoryMB` and `cpuMillicores` still work.

## Scheduled jobs

Each job under `jobs` is either `http` or `command`. An `http` job calls a path on one of your services, or a full URL, with optional headers that can use `${{ secrets.NAME }}`. A `command` job runs a command in a service image.

A job can set `schedule`, `timezone`, `timeout`, `retries`, `backoff`, `overlap` and `enabled`. `overlap` is `skip`, `queue` or `allow`, and defaults to `skip`. Put shared settings under `jobDefaults` so you write them once.

Jobs wait while their service is deploying or has no healthy copy, so a deploy never makes them fail. If a job fails for 30 minutes, on-call switches it off.

If an HTTP cron job with the same name already exists, the file adopts it instead of creating a second one. The older `cronJobs` key still works and reads as command jobs.

## Environments and previews

* `environments.<name>.branchPattern` picks the branch an environment follows.
* `inheritFrom` starts an environment from another one. The chain must lead back to `production`.
* `services.<name>` under an environment can override any service field. Lists replace the base list rather than merge with it.
* `environments.preview` applies to pull request previews. It can only override `build`, `deploy` and `env`, and a preview never creates databases, buckets or domains.

## Apply on push

On a push to a branch an environment follows, StackShift reads the file at that commit, checks it, plans the changes and sorts them into three classes. Automatic changes apply. Approval changes are held for the owner. Blocked changes fail the release, and each error names the file and line.

Apply stackshift.yaml on push is on by default for apps created from a file. For other apps it is a switch in the application settings. With the switch off, or no file in the repository, pushes behave as they did before.

## Change classes

Every change in a plan has one class.

* Automatic: build and start commands, port, non-secret variables, health, strategy, release commands, job updates, network rules, scaling within your plan, and memory or CPU increases that fit your plan and the server.
* Approval: creating a service, database, bucket, domain or job; lowering memory or CPU; changing region, server or team; making a database public; adding a custom domain.
* Blocked: changing a database `engine` or `version`, changing a bucket region, shrinking a database or volume, and a rolling deploy that does not fit the server.
* Not in stackshift.yaml: a resource you removed from the file. It is never changed or deleted by a push.

## Approvals

When a push has approval changes, its automatic changes apply at once. The approval changes, anything that depends on them (such as a binding to a database that is waiting to be created), and the release wait for the owner as one request in the dashboard.

Approving applies the held changes and runs the release. If the app changed since the plan, StackShift plans again first. Rejecting cancels the held changes and the release, and the automatic changes stay applied. A request that nobody decides on is cancelled the same way after 24 hours.

Only the owner can approve, in the dashboard. Connected agents and Stackie read waiting requests with `application_manifest_push_inspect` (Stackie: `inspect_manifest_push`). It returns each plan, when it expires and `review_url`, the dashboard page where the owner decides. The agent gives the owner that link, then reads the request again with its `run_id` until `settled` is true.

## Resources are never deleted by the file

Taking a database, bucket, domain, job or service out of the file does not delete it. The plan lists it under Not in stackshift.yaml. To delete it, use `stackshift apply --prune` or delete it in the dashboard. Only the owner can do either.

## Pull request plans

For each pull request that changes the file or the code, StackShift posts the plan as a GitHub check. It shows the changes by class, the monthly cost difference, the capacity result and any resources the file does not list. Nothing is applied until the change reaches a followed branch.

## In the dashboard

* A field set in the file is read-only and shows a Managed by stackshift.yaml badge. Fields the file does not set stay editable.
* The Drift view lists dashboard values that differ from the file.
* Export stackshift.yaml downloads a file from a running app. Secret values are left out.

## Expected result

> [!TIP]
>
> The application matches the file. Changes that cost money, open public access or shrink a resource wait for your approval, and nothing is ever deleted because it left the file.

## Common failures

> [!WARNING]
>
> * A release is waiting. It has an approval change. Approve or reject it in the dashboard. The automatic changes are already applied. A held release is cancelled after 24 hours.
> * The release fails with a blocked change, such as a new database `engine` or `version`, or a smaller database or volume. Change the file back, or make the change in the dashboard where it is allowed.
> * The release fails with a missing secret. Save each secret listed under `secrets.required` before pushing.
> * A `NEXT_PUBLIC_*` value is marked as a secret. Browser-public values cannot be secret. Remove `secretRef` and `secret`, or rename the variable.
> * A rolling deploy needs more memory than the server has. Use `strategy: recreate` or `strategy: auto`, or choose a larger server.
> * A field in the dashboard will not edit. The file controls it. Change it in the file.
> * The push did nothing. Check that Apply stackshift.yaml on push is on for the application and that the file is at the project root or the repository root.

## Related guides

> [card] [Application manifest schema](https://docs.stackshift.cloud/cli/application-manifest.md)
>
> Define one application, its services, environments, bindings, attached resources, cron jobs, and domains.

> [card] [Initialize, validate, plan, apply, and export](https://docs.stackshift.cloud/cli/plan-and-apply.md)
>
> Use the application manifest lifecycle with stale-plan protection, explicit pruning, and optional deployment.

> [card] [Build a multi-service application](https://docs.stackshift.cloud/applications/build-a-multi-service-application.md)
>
> Create an application, add public and private services from one repo or many, and let each service deploy independently while sharing one private network.

> [card] [Scheduled jobs (cron)](https://docs.stackshift.cloud/projects/scheduled-jobs.md)
>
> Run a command from your deployed image on a recurring standard-cron schedule, with run history and exit-code tracking.

> [card] [Application previews and promotion](https://docs.stackshift.cloud/ai-features/application-previews.md)
>
> Review pinned code in a dedicated Application with fresh PostgreSQL data, then approve cleanup or a separate parent release.


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