# Quickstart

> Bring up chatwork, the bridge, Chatwork Router and the site on one host with Docker Compose.

URL: https://chatwork.io/en/docs/quickstart
Section: Start here

You need a Linux host with Docker 24+, four DNS records pointing at it (`chatwork.io`, `app.`, `chat.`, `api.` or your own domain) and an OpenAI-compatible LLM endpoint.

## 1. Clone and configure

```bash
git clone <your fork of the platform repository> chatwork && cd chatwork
cp infra/.env.example infra/.env
```

Open `infra/.env` and set at least:

| Variable | Purpose |
|---|---|
| `PLATFORM_DOMAIN` | Your apex domain, e.g. `chatwork.io`. Caddy derives `app.`, `chat.` and `api.` from it. |
| `ACME_EMAIL` | Let's Encrypt contact for automatic TLS. |
| `POSTGRES_PASSWORD`, `REDIS_PASSWORD`, `SECRET_KEY_BASE`, `DOT_DB_PASSWORD` | Database, cache and chatwork secrets (`openssl rand -hex 32`). |
| `DOT_ADMIN_API_KEY`, `CHATWOOT_WEBHOOK_SECRET`, `DOT_WIDGET_SIGNING_KEY`, `DOT_CREDENTIALS_KEY` | Bridge secrets; the first three must be at least 32 characters in production. |
| `DOT_LLM_BASE_URL`, `DOT_LLM_API_KEY`, `DOT_LLM_MODEL` | Your LLM provider (OpenAI-compatible). Optional Chatwork Router embeddings use the same endpoint. |
| `DOT_DATABASE_URL` | `postgresql://dot_bridge:<DOT_DB_PASSWORD>@postgres:5432/dot_bridge` — required for Chatwork Router and the built-in knowledge base. |

Never commit `.env`. The gate script fails if one is tracked.

## 2. Start the stack

```bash
docker compose -f infra/docker-compose.yml up -d --build
```

Caddy obtains certificates, chatwork migrates its database on first boot, and the bridge starts once Postgres and Redis are healthy.

## 3. Apply the bridge migrations and seed the agents

```bash
docker compose -f infra/docker-compose.yml exec bridge python -m storage.migrate
docker compose -f infra/docker-compose.yml exec bridge python -m cloudrag.seed
```

The first command creates the bridge tables, including Chatwork Router's (`012_cloudrag.sql`, `014_knowledge_builtin.sql`). The second upserts the six agents; add `--embed` when `CLOUDRAG_EMBEDDINGS=provider` to embed their routing intents.

## 4. Create the chatwork account and the agent bot

1. Open `https://chat.<domain>` and create the first (super-admin) account.
2. Profile → Access token: put it in `CHATWOOT_ADMIN_API_TOKEN`; note the account id for `CHATWOOT_ACCOUNT_ID`.
3. Settings → Agent Bots → add a bot with the outgoing URL `https://<domain>/webhooks/chatwoot?token=<CHATWOOT_WEBHOOK_SECRET>`; put its token in `CHATWOOT_BOT_TOKEN`.
4. `docker compose -f infra/docker-compose.yml up -d bridge` to pick up the new variables.

## 5. Create the first workspace

The quickest way is the signup page: open `https://app.<domain>/en/signup` (or `/ar/signup`), enter the company, your name, email, a workspace ID and a password. One call creates the tenant, its first owner and a 14-day trial, and signs you in to the operator dashboard. See [Signup and sign-in](/en/docs/signup) for the modes (`open`, `code`, `closed`).

Operators can also onboard a tenant with the admin key:

```bash
curl -sS -X POST https://<domain>/api/v1/tenants/onboard \
  -H "X-Admin-Key: $DOT_ADMIN_API_KEY" -H 'Content-Type: application/json' \
  -d '{"slug":"acme","name_ar":"شركة أكمي","plan":"growth","channels":["web_widget"]}'
```

The response carries the tenant API key once. Embed the widget on any page:

```html
<script src="https://<domain>/widget.js" data-tenant="acme" async></script>
```

## 6. Verify

```bash
curl -fsS https://<domain>/health                 # {"status":"ok","service":...,"version":"<VERSION>"}
curl -fsS https://<domain>/ready                  # {"status":"ready","checks":{"redis":"ok","database":"ok"}}
curl -fsS https://chat.<domain>/api               # chatwork version
curl -s -o /dev/null -w '%{http_code}\n' https://<domain>/api/v1/tenants   # 401 without a key
```

Send a message through the widget; it appears in the chatwork inbox, Dot answers, and the routing decision shows up under `GET /api/v1/tenants/acme/cloudrag/decisions`.
