# Services

> A project is made of services, as many as it needs of every kind: several sites, APIs, workers, databases, cron jobs and containers. Each runs in its own microVM with its own logs, variables and limits, and has its address reserved.

## The six kinds

| service | what it runs | address and default |
| --- | --- | --- |
| `site` | A static or server rendered website | my-site.00b5e2.app, or docs.my-site.00b5e2.app for a second site; open |
| `api` | An HTTP service on a port | api.my-site.00b5e2.app; open |
| `worker` | A background process, like a queue reader or a bot | reminders.my-site.00b5e2.app; closed, nothing to open without a port |
| `database` | Postgres. MySQL and Valkey coming next | db.my-site.00b5e2.app; closed, opens on its own port |
| `cron job` | A command on a schedule, in UTC | reserved; nothing to open, it calls the others by name |
| `container` | Any container with a port | search.my-site.00b5e2.app; closed |

## Addresses, open or closed

Every service has its address reserved: the main site at my-site.00b5e2.app, every other service at <name>.my-site.00b5e2.app, so one project holds several sites, APIs and containers. Development and previews use the same names on 00b5e2.dev. Only what needs to be open is open by default: sites and APIs. Databases, caches, workers, cron jobs and containers are closed, reachable only by the services of the project, and any service that listens on a port can be opened.

addresses of my-site:

```
my-site.00b5e2.app                    web, open
docs.my-site.00b5e2.app               docs, open
api.my-site.00b5e2.app                api, open
api.my-site-git-fix-login.00b5e2.dev  api, preview of the fix-login branch
db.my-site.00b5e2.app                 db, closed
reminders.my-site.00b5e2.app          worker, nothing to open
```

> HTTPS is automatic: every project gets one certificate for *.my-site.00b5e2.app, so a new address works the moment the service is live.

## Add a service

init proposes services from what it finds in the repo. Add more at any time; open or close them whenever you need:

```sh
$ 00b5e2 services add api --dir ./api
■ added api  https://api.my-site.00b5e2.dev, open
$ 00b5e2 services add site --name docs --dir ./docs
■ added docs  https://docs.my-site.00b5e2.dev, open
$ 00b5e2 services add database --engine postgres --name db
■ added db  postgres 17, closed, db:5432 inside my-site
$ 00b5e2 services open db --allow 203.0.113.0/24
■ open at postgres://db_user:•••@db.my-site.00b5e2.app:31842/db?sslmode=require
$ 00b5e2 services close db
■ closed  db:5432 inside my-site only
```

## List them

```sh
$ 00b5e2 services ls --json
[ { "name": "web", "kind": "site", "address": "my-site.00b5e2.app", "open": true },
  { "name": "api", "kind": "api", "address": "api.my-site.00b5e2.app", "open": true },
  { "name": "db", "kind": "database", "address": "db.my-site.00b5e2.app", "open": false } ]
```

## How services talk

Services of the same project reach each other by name on a private network: api reaches the database at db:5432 and the worker reads its queue at cache:6379. Connecting services explains the network, the variables each database adds, opening a database to the outside and letting two projects talk.

> Nothing outside the project can reach a private service, not even another project of yours, until you allow it. That wall is the point of 00b5e2.

## From an agent

| tool | what it does |
| --- | --- |
| `list_services` | Services of a project, with kind, status, address and open or closed |
| `add_service` | Add a site, API, worker, database, cron job or container (optional address name) |
| `remove_service` | Remove a service and its development data |
| `open_service` | Open a service at its address (a database on its own port, with TLS and defences) |
| `close_service` | Close a service again |
| `link_service` | Give a service the variables of another |

Previous: [First project](https://docs.00b5e2.com/first-project.md)
Next: [Connecting services](https://docs.00b5e2.com/connecting-services.md)
