API ReferenceREST /api/v1Sign in

Production deployment — 153.92.5.189

The stack runs as Docker containers behind Caddy, which terminates TLS and obtains certificates from Let's Encrypt automatically.

| Host | Service | Container port | | --- | --- | --- | | hpanel.codefusion.com.lk | portal (customer panel) | 3002 | | admin.hpanel.codefusion.com.lk | admin (staff console) | 3000 | | api.hpanel.codefusion.com.lk | api (NestJS) | 3001 | | www.hpanel.codefusion.com.lk | www (marketing) | 3003 |

worker and scheduler run without ingress. Postgres and Redis publish no ports and are reachable only on the compose network.

One image, many services

infra/docker/Dockerfile builds the entire workspace once into kiwi-hosting:latest. Every service runs that same image and differs only by its command, so the monorepo is installed and built a single time instead of once per app.

### Why tsx in production

node dist/main.js does not work in this repo. The workspace packages expose TypeScript source through their exports field ("./src/index.ts"), so a compiled apps/api/dist still imports .ts files that Node cannot load. The container therefore runs the Node services through tsx (pnpm --filter @hosting/api start:prod). Type checking still happens in CI.

The cleaner long-term fix is to have each package build to dist and point its exports at the built output, which would let the services run on plain Node. That is a change across all twelve packages and was out of scope here.

First deployment

1. **Authorize the deploy key** (once, from your laptop):

``bash ssh-copy-id -i ~/.ssh/kiwi-deploy.pub root@153.92.5.189 ``

2. **Create the DNS records.** codefusion.com.lk is on Cloudflare. Add four A records to 153.92.5.189, or one wildcard:

| Name | Value | | --- | --- | | hpanel | 153.92.5.189 | | admin.hpanel | 153.92.5.189 | | api.hpanel | 153.92.5.189 | | www.hpanel | 153.92.5.189 |

Set them to **DNS only (grey cloud)**, not proxied. Caddy validates certificates over HTTP-01, which fails behind Cloudflare's proxy. You can switch the proxy on afterwards, but then Cloudflare must be set to Full (strict) and the origin needs its own certificate.

3. **Install Docker on the host** if it is not there:

``bash ssh -i ~/.ssh/kiwi-deploy root@153.92.5.189 \ 'curl -fsSL https://get.docker.com | sh' ``

4. **Write the environment file.** Copy the template, then fill in every CHANGE_ME:

``bash scp -i ~/.ssh/kiwi-deploy .env.production.example \ root@153.92.5.189:/opt/kiwi-hosting/.env.production ssh -i ~/.ssh/kiwi-deploy root@153.92.5.189 \ 'nano /opt/kiwi-hosting/.env.production' ``

Generate the three passwords and two secrets with openssl rand -hex 32. The same app-database password must appear in both APP_DB_PASSWORD and inside DATABASE_URL; the same Postgres password in both POSTGRES_PASSWORD and DATABASE_URL_MIGRATE.

5. **Deploy:**

``bash ./infra/deploy.sh ``

The script refuses to run if .env.production is missing on the host.

Routine deployment

``bash ./infra/deploy.sh # sync, rebuild, migrate, restart ./infra/deploy.sh --logs # and then tail the logs ``

Migrations run as a one-shot migrate service before any app container starts, using DATABASE_URL_MIGRATE (the postgres role). The app containers connect as hosting_app, which cannot create or own tables — the privilege separation from infra/docker/postgres/init.sql carries into production via init-prod.sh.

Operations

```bash cd /opt/kiwi-hosting C="docker compose -f docker-compose.prod.yml --env-file .env.production"

$C ps # status $C logs -f api # follow one service $C restart api # restart one service $C exec postgres psql -U postgres -d hosting # database shell ```

### Backups

Nothing automated yet. A Postgres dump is:

``bash docker compose -f docker-compose.prod.yml --env-file .env.production \ exec -T postgres pg_dump -U postgres hosting | gzip > hosting-$(date +%F).sql.gz ``

Set this up on a schedule before taking real customer data.

Notes and limits

- The database password is only read when the Postgres volume is first created. Changing APP_DB_PASSWORD later needs an ALTER USER by hand. - .env.production is gitignored and lives only on the server. The image bakes the four NEXT_PUBLIC_* origins at build time, so changing a public URL requires a rebuild, not just a restart. - The image is ~2.9 GB because dev dependencies are kept for tsx. Fixing the package exports (above) would allow a much smaller runtime image. - Caddy will not issue certificates until the DNS records resolve to this host and ports 80/443 are reachable. Both were closed when this was written.

Markdown source
# Production deployment — 153.92.5.189

The stack runs as Docker containers behind Caddy, which terminates TLS and
obtains certificates from Let's Encrypt automatically.

| Host | Service | Container port |
| --- | --- | --- |
| `hpanel.codefusion.com.lk` | portal (customer panel) | 3002 |
| `admin.hpanel.codefusion.com.lk` | admin (staff console) | 3000 |
| `api.hpanel.codefusion.com.lk` | api (NestJS) | 3001 |
| `www.hpanel.codefusion.com.lk` | www (marketing) | 3003 |

`worker` and `scheduler` run without ingress. Postgres and Redis publish no
ports and are reachable only on the compose network.

## One image, many services

`infra/docker/Dockerfile` builds the entire workspace once into
`kiwi-hosting:latest`. Every service runs that same image and differs only by
its `command`, so the monorepo is installed and built a single time instead of
once per app.

### Why tsx in production

`node dist/main.js` does not work in this repo. The workspace packages expose
TypeScript source through their `exports` field (`"./src/index.ts"`), so a
compiled `apps/api/dist` still imports `.ts` files that Node cannot load. The
container therefore runs the Node services through `tsx` (`pnpm --filter
@hosting/api start:prod`). Type checking still happens in CI.

The cleaner long-term fix is to have each package build to `dist` and point its
`exports` at the built output, which would let the services run on plain Node.
That is a change across all twelve packages and was out of scope here.

## First deployment

1. **Authorize the deploy key** (once, from your laptop):

   ```bash
   ssh-copy-id -i ~/.ssh/kiwi-deploy.pub root@153.92.5.189
   ```

2. **Create the DNS records.** `codefusion.com.lk` is on Cloudflare. Add four
   `A` records to `153.92.5.189`, or one wildcard:

   | Name | Value |
   | --- | --- |
   | `hpanel` | `153.92.5.189` |
   | `admin.hpanel` | `153.92.5.189` |
   | `api.hpanel` | `153.92.5.189` |
   | `www.hpanel` | `153.92.5.189` |

   Set them to **DNS only (grey cloud)**, not proxied. Caddy validates
   certificates over HTTP-01, which fails behind Cloudflare's proxy. You can
   switch the proxy on afterwards, but then Cloudflare must be set to Full
   (strict) and the origin needs its own certificate.

3. **Install Docker on the host** if it is not there:

   ```bash
   ssh -i ~/.ssh/kiwi-deploy root@153.92.5.189 \
     'curl -fsSL https://get.docker.com | sh'
   ```

4. **Write the environment file.** Copy the template, then fill in every
   `CHANGE_ME`:

   ```bash
   scp -i ~/.ssh/kiwi-deploy .env.production.example \
       root@153.92.5.189:/opt/kiwi-hosting/.env.production
   ssh -i ~/.ssh/kiwi-deploy root@153.92.5.189 \
       'nano /opt/kiwi-hosting/.env.production'
   ```

   Generate the three passwords and two secrets with
   `openssl rand -hex 32`. The same app-database password must appear in both
   `APP_DB_PASSWORD` and inside `DATABASE_URL`; the same Postgres password in
   both `POSTGRES_PASSWORD` and `DATABASE_URL_MIGRATE`.

5. **Deploy:**

   ```bash
   ./infra/deploy.sh
   ```

   The script refuses to run if `.env.production` is missing on the host.

## Routine deployment

```bash
./infra/deploy.sh          # sync, rebuild, migrate, restart
./infra/deploy.sh --logs   # and then tail the logs
```

Migrations run as a one-shot `migrate` service before any app container starts,
using `DATABASE_URL_MIGRATE` (the `postgres` role). The app containers connect
as `hosting_app`, which cannot create or own tables — the privilege separation
from `infra/docker/postgres/init.sql` carries into production via
`init-prod.sh`.

## Operations

```bash
cd /opt/kiwi-hosting
C="docker compose -f docker-compose.prod.yml --env-file .env.production"

$C ps                     # status
$C logs -f api            # follow one service
$C restart api            # restart one service
$C exec postgres psql -U postgres -d hosting   # database shell
```

### Backups

Nothing automated yet. A Postgres dump is:

```bash
docker compose -f docker-compose.prod.yml --env-file .env.production \
  exec -T postgres pg_dump -U postgres hosting | gzip > hosting-$(date +%F).sql.gz
```

Set this up on a schedule before taking real customer data.

## Notes and limits

- The database password is only read when the Postgres volume is first
  created. Changing `APP_DB_PASSWORD` later needs an `ALTER USER` by hand.
- `.env.production` is gitignored and lives only on the server. The image bakes
  the four `NEXT_PUBLIC_*` origins at build time, so changing a public URL
  requires a rebuild, not just a restart.
- The image is ~2.9 GB because dev dependencies are kept for `tsx`. Fixing the
  package `exports` (above) would allow a much smaller runtime image.
- Caddy will not issue certificates until the DNS records resolve to this host
  and ports 80/443 are reachable. Both were closed when this was written.