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:
29
AGENTS.md
29
AGENTS.md
@@ -3,7 +3,8 @@
|
||||
## Status
|
||||
|
||||
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;
|
||||
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 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: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 typecheck` | `tsc` per package (`apps/web` regenerates the route tree first) |
|
||||
| `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
|
||||
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`**
|
||||
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
|
||||
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`.
|
||||
- Dev ports: API `4100`, web `7153`. They live in the `.env.example` files, `apps/web/vite.config.ts` and
|
||||
`.github/workflows/ci.yml` — change them together.
|
||||
- Dev ports: API `4100`, web `7153`. They live in the `.env.example` files and `apps/web/vite.config.ts`
|
||||
— change them together.
|
||||
- **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
|
||||
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
|
||||
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.
|
||||
- CI (`.github/workflows/ci.yml`) runs on PRs and pushes to `main`: `bun install --frozen-lockfile` →
|
||||
`db:generate` → `lint:ci` → `typecheck` → `test` → `build`, with Bun 1.4.0 and Node 22 for the Prisma CLI.
|
||||
- **Deployment: Docker Compose on Dokploy** (`docker-compose.yml` at the repo root). Two services, `api` and
|
||||
`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`,
|
||||
`apps/api/src/generated/`.
|
||||
- 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
|
||||
`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.
|
||||
- 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
|
||||
// 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
|
||||
`ApiError` carrying the parsed `ProblemDetails` for non-2xx responses; `204` resolves to `undefined`. Error
|
||||
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`
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user