# aerostack add

> Add a new service or shared library to your Aerostack project with one command. Scaffolds the correct structure and wires up dependencies.

Add a new service or shared library to your project.

## Add a service

```bash
aerostack add function <name>
```

Creates a new Worker service at `services/<name>/index.ts` and registers it in `aerostack.toml`. Each service is an independent entry point that can be deployed separately.

```bash
aerostack add function payments-api
aerostack add function email-worker
aerostack add function auth-webhook
```

**Generated file:** `services/payments-api/index.ts`

```ts

  async fetch(request: Request, env: Env): Promise {
    const sdk = new Aerostack({ env })

    // Your payments-api logic here
    return new Response('Hello from payments-api')
  }
}
```

---

## Add a shared library

```bash
aerostack add lib <name>
```

Creates a shared module at `shared/<name>.ts`, importable from any service as `@shared/<name>`.

```bash
aerostack add lib auth
aerostack add lib utils
aerostack add lib validators
```

**Usage in any service:**

```ts

```

---

## aerostack resources create

Provision Cloudflare resources (D1, KV, R2, Queues) defined in your `aerostack.toml` in your Cloudflare account.

```bash
aerostack resources create [flags]
```

| Flag | Default | Description |
|------|---------|-------------|
| `-e, --env` | `staging` | Target environment |

```bash
# Create all resources for staging
aerostack resources create

# Create for production
aerostack resources create --env production
```

When using `aerostack deploy --cloudflare`, resource creation runs automatically if resources haven't been provisioned yet. You can also run it manually before deploying.
