# {{ title }}

Generated by **`empu new`** (Purwa / Empu).

## Quick start

```bash
cargo run
curl -s http://localhost:{{ port }}/health
```
{% if inertia %}

## Inertia + Vite (frontend)

Requires **Node >= 20** (see `frontend/package.json` `engines`).

**One-time:** `cd frontend && npm install`

### Development (two processes)

1. Terminal A — Vite dev server (HMR):

   ```bash
   cd frontend && npm run dev
   ```

2. Terminal B — Rust app with hot scripts pointing at Vite:

   ```bash
   export PURWA_VITE_DEV_ORIGIN=http://127.0.0.1:5173
   cargo run
   ```

Open **http://localhost:{{ port }}/** (the Rust server). The HTML shell loads `@vite/client` and `src/app.js` from the dev origin.

`frontend/vite.config.js` proxies `/health` to `VITE_PURWA_URL` (default `http://127.0.0.1:{{ port }}`) so you can hit the API from the Vite origin when needed.

### Production assets

```bash
empu build
```

This runs `cargo build --release`, then `npm ci && npm run build` in `frontend/`, writes hashed files under `public/`, and updates `[inertia].asset_version` in `purwa.toml` from `public/.vite/manifest.json`.

Then run the release binary; static files are served from `public/` (e.g. `/assets/...`).

### Inertia errors

Map `purwa::PurwaError` with `InertiaRequest::respond_purwa_error` and `INERTIA_ERROR_COMPONENT` (matches `frontend/src/Pages/Error.svelte`). See the Purwa workspace README (Sprint 10).

### Logging

`main` runs **`purwa::init_tracing()`** after loading `.env`. Use **`RUST_LOG`** (e.g. `debug`); set **`PURWA_ENV=production`** for JSON log lines.

### Add the frontend to an existing app

```bash
empu inertia:setup
# or a custom directory:
empu inertia:setup --output frontend
```
{% endif %}

## Tests

- **`tests/no_db_smoke.rs`** — `GET /health` via `purwa_testing` + `router_from_inventory()` (no database).
- **`tests/postgres_optional.rs`** — ignored by default; set **`TEST_DATABASE_URL`** and run  
  `cargo test postgres_env_connects -- --ignored` for a real Postgres check. For migrations, follow **`purwa-orm`** patterns (same as Purwa workspace S4 tests).

## Routes

```bash
empu route:list
empu route:list --json
```

## Cold build baseline

First `cargo build` on a typical dev machine should stay within ~30s; if yours is slower, set a shared `CARGO_TARGET_DIR` on a fast disk or use `mold`/`lld`. Document your CPU/RAM if reporting build times.

## Purwa dependency

This template uses a version or path for `purwa` (see `Cargo.toml`). For hacking on Purwa from a local checkout, use `path = "../purwa/purwa"` or pass `--purwa-path` to `empu new`.

## Deferred CLI commands

Some `empu` subcommands are stubs until later sprints — see `TASK.md` in the Purwa repository.
