# Services

Source: https://docs.apphaven.eu/services

Each entry under `services` in [your manifest](https://docs.apphaven.eu/manifest.md) is one service of
your app, keyed by a name you choose. A service's `type` selects what it is:

| `type`      | What it runs                                                          |                                     |
| ----------- | --------------------------------------------------------------------- | ----------------------------------- |
| `container` | Your code: a prebuilt image, or an image built from your repository.  | [Container services](https://docs.apphaven.eu/services/container.md) |
| `postgres`  | A managed database (PostgreSQL), provisioned and operated by AppHaven. | [Database](https://docs.apphaven.eu/services/postgres.md)   |

A small app is often just the two:

```yaml
services:
  web:
    type: container
    build:
      dockerfile: Dockerfile
    ports:
      - 3000
    env:
      DATABASE_URL: ${service.db.url}
    depends_on:
      - service: db
        condition: healthy

  db:
    type: postgres
```

## Networking

Services in the same deployment share a private internal network and reach
each other by service name: a service named `api` listening on `8080` is
reachable from another service as `http://api:8080`, and a database named `db`
as `db:5432`. Declared `ports` are how AppHaven serves your app: each
service and port is an [entry point](https://docs.apphaven.eu/manifest.md#ports-and-addresses) with its
own address over HTTPS and its own [access setting](https://docs.apphaven.eu/access.md). Nothing else is
reachable from the internet.

## Start order (`depends_on`)

Any service can declare that it should start after another:

```yaml
    depends_on:
      - service: db          # another service in this manifest
        condition: healthy   # "started" or "healthy"; default "started"
```

- `condition: started`: wait until the other service's container has started.
- `condition: healthy`: wait until it reports healthy. The target must define
  a [healthcheck](https://docs.apphaven.eu/services/container.md#healthchecks); managed databases come
  with one built in.
- References must point at a service in the same manifest, and the dependency
  graph must have no cycles.

`depends_on` controls start ordering only: it doesn't affect networking, and
AppHaven also restarts services automatically if they crash, so it isn't your
app's only safety net.

## Where to go next

- [Container services](https://docs.apphaven.eu/services/container.md): images, builds from source, healthchecks.
- [Database](https://docs.apphaven.eu/services/postgres.md): the managed database.
- [Volumes](https://docs.apphaven.eu/volumes.md): give a service durable storage.
- [Environment variables](https://docs.apphaven.eu/environment-variables.md): configuration and secrets.
