docs: document the /api prefix and the Dokploy deployment

Update AGENTS.md and README.md for the same-origin `/api` routing and
the Docker Compose deployment: no hosted CI, how the images and nginx
proxy fit together, and the required env vars.
This commit is contained in:
Jose Selesan
2026-10-16 15:44:31 -03:00
parent f87d46c975
commit fbd6942a6e
2 changed files with 45 additions and 11 deletions

View File

@@ -3,7 +3,8 @@
## Status ## Status
Scaffold is in place and verified: Turborepo monorepo with `apps/api`, `apps/web` and `packages/shared`, Scaffold is in place and verified: Turborepo monorepo with `apps/api`, `apps/web` and `packages/shared`,
CI on GitHub Actions, Biome as the only JS/TS tool and the text Bun lockfile committed. Biome as the only JS/TS tool and the text Bun lockfile committed. It is deployed with Docker Compose on
Dokploy (`docker-compose.yml`); there is no hosted CI.
Not done yet: product features are just starting (sign-up, shopping lists, list items and invitations exist; Not done yet: product features are just starting (sign-up, shopping lists, list items and invitations exist;
there is no Google login and no email verification). The `health` module is the reference example. there is no Google login and no email verification). The `health` module is the reference example.
@@ -46,7 +47,7 @@ Run from the repo root. Verification order is `build`, then `lint` → `typechec
| `bun run build` | `turbo run build` (API bundle + web production build) | | `bun run build` | `turbo run build` (API bundle + web production build) |
| `bun run lint` | `biome check .` per package via turbo — fails on lint, format or import order | | `bun run lint` | `biome check .` per package via turbo — fails on lint, format or import order |
| `bun run lint:fix` | `biome check --write .` across the repo (lint fixes, formatting, imports) | | `bun run lint:fix` | `biome check --write .` across the repo (lint fixes, formatting, imports) |
| `bun run lint:ci` | `biome ci .` — whole repo, exactly what CI runs | | `bun run lint:ci` | `biome ci .` — whole repo, works without a git index |
| `bun run format` | `biome format --write .` (`format:check` to verify only) | | `bun run format` | `biome format --write .` (`format:check` to verify only) |
| `bun run typecheck` | `tsc` per package (`apps/web` regenerates the route tree first) | | `bun run typecheck` | `tsc` per package (`apps/web` regenerates the route tree first) |
| `bun run test` | `bun test` in the API, `vitest` in web and shared | | `bun run test` | `bun test` in the API, `vitest` in web and shared |
@@ -73,12 +74,12 @@ Run from the repo root. Verification order is `build`, then `lint` → `typechec
every task that needs one lists it in `turbo.json`: `db:*` use `env: ["DATABASE_URL"]`, `test` declares the every task that needs one lists it in `turbo.json`: `db:*` use `env: ["DATABASE_URL"]`, `test` declares the
API variables, `dev` uses `passThroughEnv` (they must reach the process but don't change its output). API variables, `dev` uses `passThroughEnv` (they must reach the process but don't change its output).
`VITE_*` is covered by Vite framework inference. **When you introduce a new variable, add it to `turbo.json`** `VITE_*` is covered by Vite framework inference. **When you introduce a new variable, add it to `turbo.json`**
or the task will fail (or worse, hit a stale cache) in CI. or the task will fail (or worse, hit a stale cache).
- Env files: `cp apps/api/.env.example apps/api/.env` and `cp apps/web/.env.example apps/web/.env` (both - Env files: `cp apps/api/.env.example apps/api/.env` and `cp apps/web/.env.example apps/web/.env` (both
gitignored, and `.env.example` at the root documents every variable). Bun loads `.env` automatically; the gitignored, and `.env.example` at the root documents every variable). Bun loads `.env` automatically; the
Prisma CLI does not, which is why `prisma.config.ts` imports `dotenv/config`. Prisma CLI does not, which is why `prisma.config.ts` imports `dotenv/config`.
- Dev ports: API `4100`, web `7153`. They live in the `.env.example` files, `apps/web/vite.config.ts` and - Dev ports: API `4100`, web `7153`. They live in the `.env.example` files and `apps/web/vite.config.ts`
`.github/workflows/ci.yml` — change them together. — change them together.
- **TypeScript 6 specifics:** `baseUrl` no longer exists (aliases are declared with `paths` only), and - **TypeScript 6 specifics:** `baseUrl` no longer exists (aliases are declared with `paths` only), and
`apps/web/tsconfig.app.json` enables `erasableSyntaxOnly` — no enums, namespaces or constructor parameter `apps/web/tsconfig.app.json` enables `erasableSyntaxOnly` — no enums, namespaces or constructor parameter
properties in the web app. Both apps use `@/*` → `src/*` and `verbatimModuleSyntax` (use `import type`). properties in the web app. Both apps use `@/*` → `src/*` and `verbatimModuleSyntax` (use `import type`).
@@ -88,8 +89,13 @@ Run from the repo root. Verification order is `build`, then `lint` → `typechec
PascalCase/camelCase, because BetterAuth and the generated client address models by those names, so a column PascalCase/camelCase, because BetterAuth and the generated client address models by those names, so a column
rename never changes the TypeScript API. Default constraint/index names follow the mapped names, so do not rename never changes the TypeScript API. Default constraint/index names follow the mapped names, so do not
set `map:` unless you have a reason to. set `map:` unless you have a reason to.
- CI (`.github/workflows/ci.yml`) runs on PRs and pushes to `main`: `bun install --frozen-lockfile` → - **Deployment: Docker Compose on Dokploy** (`docker-compose.yml` at the repo root). Two services, `api` and
`db:generate` → `lint:ci` → `typecheck` → `test` → `build`, with Bun 1.4.0 and Node 22 for the Prisma CLI. `web`; the database is external (Dokploy's), and both join the external `dokploy-network` for Traefik. The
`api` image (`apps/api/Dockerfile`) builds the Bun bundle and runs `prisma migrate deploy` before
`bun run start`; the `web` image (`apps/web/Dockerfile`) builds with Vite and serves `dist/` with
`apps/web/nginx.conf`, which also proxies `/api/*` to `http://api:4100`. Required env vars are interpolated
by Compose (`DATABASE_URL`, `BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, `CORS_ORIGIN`, `WEB_APP_URL`); set them
in Dokploy. There is no hosted CI.
- Generated files are gitignored and must never be edited by hand: `apps/web/src/routeTree.gen.ts`, - Generated files are gitignored and must never be edited by hand: `apps/web/src/routeTree.gen.ts`,
`apps/api/src/generated/`. `apps/api/src/generated/`.
- Tests live next to the code as `*.test.ts`. The API uses `bun test` (`src/lib/result-json.test.ts`, - Tests live next to the code as `*.test.ts`. The API uses `bun test` (`src/lib/result-json.test.ts`,
@@ -125,7 +131,10 @@ apps/api/src/modules/alerts/
- **Routes never check `result.ok` by hand**: every route ends with `resultJson(c, result)`, which serializes - **Routes never check `result.ok` by hand**: every route ends with `resultJson(c, result)`, which serializes
`Ok` as JSON (200 by default, override with `{ status: 201 }`, `204` sends an empty body) and maps `Failure` `Ok` as JSON (200 by default, override with `{ status: 201 }`, `204` sends an empty body) and maps `Failure`
to the matching RFC 9457 `application/problem+json` response. to the matching RFC 9457 `application/problem+json` response.
- Wire the module in `createApp()` (`apps/api/src/app.ts`): `app.route('/alerts', alertsModule)`. - Wire the module in `createApp()` (`apps/api/src/app.ts`): `app.route('/api/alerts', alertsModule)`.
**Every API route is mounted under `/api`** (BetterAuth already owns `/api/auth/*`) because nginx proxies
`/api/*` to the API while serving the SPA at the root — an unprefixed path such as `/lists` would be
swallowed by the frontend router.
```ts ```ts
// apps/api/src/modules/alerts/list/route.ts // apps/api/src/modules/alerts/list/route.ts
@@ -246,6 +255,10 @@ apps/web/src/
- `apiFetch` returns parsed JSON, sends `credentials: 'include'` (BetterAuth sessions are cookies) and throws - `apiFetch` returns parsed JSON, sends `credentials: 'include'` (BetterAuth sessions are cookies) and throws
`ApiError` carrying the parsed `ProblemDetails` for non-2xx responses; `204` resolves to `undefined`. Error `ApiError` carrying the parsed `ProblemDetails` for non-2xx responses; `204` resolves to `undefined`. Error
UIs read `error.problem.detail`. UIs read `error.problem.detail`.
- **Same-origin `/api` in every environment.** `apiBaseUrl` is `` `${VITE_API_URL || ''}/api` `` and the SSE
hook (`use-list-events.ts`) reuses it, so the browser calls `/api/*` on the current origin: Vite proxies it
to `:4100` in dev and nginx does in production. `VITE_API_URL` is an optional override for a separate API
origin, and `auth-client.ts` defaults `baseURL` to `window.location.origin` (BetterAuth appends `/api/auth`).
- **Forms: React Hook Form + Zod** (`zodResolver`). Render errors with the shadcn `Field`/`FieldError` - **Forms: React Hook Form + Zod** (`zodResolver`). Render errors with the shadcn `Field`/`FieldError`
components — this registry version ships `field` instead of the older `form` component. components — this registry version ships `field` instead of the older `form` component.
- **shadcn/ui**: components live in `src/components/ui` and are source, not generated output — edit them - **shadcn/ui**: components live in `src/components/ui` and are source, not generated output — edit them

View File

@@ -46,15 +46,36 @@ bun run typecheck # tsc
bun run test # bun test (api) / vitest (web, shared) bun run test # bun test (api) / vitest (web, shared)
``` ```
CI (`.github/workflows/ci.yml`) runs `db:generate` → `lint:ci` → `typecheck` → `test` → `build` on every push There is no hosted CI: run these locally (in that order) before pushing. `bun run lint:ci` runs the exact
to `main` and every pull request. same Biome check as `biome ci` would.
## Deployment (Dokploy)
`docker-compose.yml` at the repo root defines the two runtime services — `api` (Bun + nginx-free Hono server)
and `web` (static build behind nginx, proxying `/api/*` to the API). The database is external (provided by
Dokploy), and both services join the external `dokploy-network` so Traefik can reach them.
- One public domain: nginx serves the SPA and proxies `/api/*` → `http://api:4100`. All API routes are
mounted under `/api` for that reason — never mount a route at the root of the API.
- Env vars are interpolated from the Dokploy service env (`docker-compose.yml` marks `DATABASE_URL`,
`BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, `CORS_ORIGIN` and `WEB_APP_URL` as required). See `.env.example`.
- Point the domain in Dokploy's **Domains** UI at the `web` service, container port `80` (the compose file
publishes no host ports on purpose).
- Migrations run automatically on API startup (`prisma migrate deploy` before `bun run start`).
Local smoke test of the same setup:
```bash
docker network create dokploy-network # once, mimics Dokploy's network
docker compose up --build
```
## Useful scripts ## Useful scripts
| Command | Effect | | Command | Effect |
| --------------------- | ------------------------------------------------------------------- | | --------------------- | ------------------------------------------------------------------- |
| `bun run lint:fix` | Apply Biome fixes: lint, formatting and import sorting (whole repo) | | `bun run lint:fix` | Apply Biome fixes: lint, formatting and import sorting (whole repo) |
| `bun run lint:ci` | `biome ci` — check the whole repo exactly as CI does | | `bun run lint:ci` | `biome ci` — whole-repo check, stricter than `lint` |
| `bun run format` | Format with Biome (`format:check` to verify only) | | `bun run format` | Format with Biome (`format:check` to verify only) |
| `bun run db:generate` | Regenerate the Prisma client into `apps/api/src/generated` | | `bun run db:generate` | Regenerate the Prisma client into `apps/api/src/generated` |
| `bun run db:migrate` | Create and apply a migration (development) | | `bun run db:migrate` | Create and apply a migration (development) |