docs: add /docs living documentation per AGENT.MD

- docs/README.md: navigation hub
- docs/architecture.md: system overview, tech stack, data flows, ports
- docs/backend/: supabase-core, schema, rpcs, rls, seed, docker
- docs/frontend/: app-structure, screens, api-client
- docs/next-steps.md: Phase 2/3/4 plan + open decisions
- Fix README demo-account emails to match the actual seed
This commit is contained in:
Lago committed 2026-08-22 17:10:50 +02:00
1 parent 37684ba116
commit 4abdc7691b
16 files changed
+1494 -7

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
# Docker
Docker is the backbone. Two pieces:
1. **The Supabase core** — a set of containers managed by the **Supabase CLI**
(not by a compose file in this repo). See [supabase-core.md](./supabase-core.md).
2. **The app sidecar** — a single container built from
[`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile) and orchestrated by
the root [`docker-compose.yml`](../../docker-compose.yml).
The app container **joins the network the CLI created** for the core and proxies
the Supabase same-origin paths to the Kong container.
## How the pieces fit
```mermaid
flowchart LR
subgraph Host
CLI["supabase start<br/>(Supabase CLI)"]
end
subgraph Net["supabase_network_Convivo (external)"]
K["supabase_kong_Convivo<br/>:8000 (internal)"]
APP["convivo-app<br/>nginx :3000"]
end
CLI -.creates.-> Net
APP -->|"proxy /auth /rest /realtime /storage"| K
APP -->|"host port 3000"| U["Browser"]
```
## The app image (`apps/convivo/Dockerfile`)
Multi-stage build:
- **Stage 1 — `build`** (`node:20-alpine`): `npm ci` (reproducible via
`package-lock.json`), then `npm run build` (tsc + vite). The anon key is baked
in at build time via `ARG VITE_SUPABASE_ANON_KEY` (it's not a secret — it's the
standard local anon key).
- **Stage 2 — `serve`** (`nginx:1.27-alpine`): copies the built `dist/` and an
nginx config **template**. The entrypoint
([`docker-entrypoint.sh`](../../apps/convivo/docker-entrypoint.sh)) injects the
proxy target at container start, then runs nginx.
### nginx config
[`nginx.conf.template`](../../apps/convivo/nginx.conf.template) serves the SPA
(`try_files ... /index.html` for client-side routing) and proxies the Supabase
same-origin paths to the core:
| Location | Proxied to | Notes |
|---|---|---|
| `/auth/` | `__SUPABASE_PROXY_TARGET__` | GoTrue |
| `/rest/` | `__SUPABASE_PROXY_TARGET__` | PostgREST (tables + RPCs) |
| `/realtime/` | `__SUPABASE_PROXY_TARGET__` | WebSocket — `Upgrade`/`Connection` headers + long timeouts |
| `/storage/` | `__SUPABASE_PROXY_TARGET__` | Storage (unused in v1) |
`__SUPABASE_PROXY_TARGET__` is replaced at start with the value of the
`SUPABASE_PROXY_TARGET` env var (default `supabase_kong_Convivo:8000`).
> **Why `:8000` and not `:54321`?** Kong listens on **8000 inside** the container;
> the `54321→8000` mapping is host-only. From inside the shared network you must
> target the internal port. See [supabase-core.md#ports](./supabase-core.md#ports).
## Root `docker-compose.yml`
Runs **only the app** (the core is CLI-managed). Key settings:
| Setting | Value | Why |
|---|---|---|
| `build.context` | `./apps/convivo` | Builds the app image |
| `ports` | `3000:3000` | The app on the host |
| `environment.SUPABASE_PROXY_TARGET` | `supabase_kong_Convivo:8000` (default) | Where nginx proxies |
| `networks.supabase` | **external**, name `supabase_network_Convivo` | Joins the CLI-created network |
| `healthcheck` | `wget http://127.0.0.1:3000/` | Container reports healthy |
> If you change `project_id` in `supabase/config.toml`, update the external
> network name (`supabase_network_<project_id>`) and the default proxy target
> (`supabase_kong_<project_id>:8000`) to match.
## Running
```bash
# 1. Start the Supabase core (creates containers + supabase_network_Convivo)
npm run db:start
# 2. (Optional) reset to clean seed data
npm run db:reset
# 3. Build + run the app sidecar on :3000
docker compose up --build
```
Open **http://localhost:3000**.
### Alternative: dev server (no app container)
For faster iteration you can skip the app container and use the Vite dev server,
which proxies the same paths to `127.0.0.1:54321` (host port):
```bash
npm run db:start
npm run app:dev # Vite on :3000
```
## Verified behavior
- `docker compose build` → `npm ci` + `tsc` + `vite build` all pass in-container.
- `GET /` → HTTP 200 (SPA served by nginx).
- `GET /auth/v1/health` through the proxy → GoTrue health JSON (proxy works).
- Full login (QR + email) works through the Docker-served app.