Files
CollabTable/README.md
T

135 lines
6.8 KiB
Markdown
Raw Normal View History

# CollabTable
CollabTable is a collaborative list/table system: a Go server holding lists with custom-typed, ordered columns (fields) and rows (items), a SvelteKit web dashboard for browsing that data, and a native Android app (Jetpack Compose, offline-first with Room) that syncs against the server's HTTP API. It's built for things like shopping lists with price tracking, product catalogs, or any structured data collection that several people and devices need to keep in sync.
---
## Tech Stack
| Layer | Technology |
|-------|------------|
| Database | PostgreSQL |
| Backend | Go (`net/http`) |
| Web dashboard | SvelteKit (static SPA, embedded in the Go binary) |
| Android app | Kotlin, Jetpack Compose, Room, Retrofit/OkHttp |
| Container | Docker (single image, no Compose) |
---
## Repository Layout
```
backend/ Go backend: lists/fields/items/sync/notifications, auth, embedded dashboard
frontend/ SvelteKit dashboard (static SPA, read-only viewer, embedded by the backend build)
CollabTableAndroid/ Native Android client (Kotlin, Jetpack Compose, Room, Retrofit)
docker/ Single multi-stage Dockerfile
shared/ Design system and backend helpers shared with sibling projects
```
---
## Configuration
CollabTable's browser dashboard authenticates through AuthGuard, a centralized identity service shared across projects (`AUTHGUARD_URL`): create a username, email, and password on first launch, then sign in with the username or email. AuthGuard hashes passwords and issues the `auth_session` cookie the browser holds; CollabTable itself stores no account credentials, only a small local flag recording that its one-time setup screen has run. Unlike the single-admin-tool projects in this workspace, CollabTable is a genuinely multi-user app that already supported full admin user management (list/create/edit/delete accounts, assign roles) before this integration — that maps directly onto AuthGuard's own `/api/admin/users` endpoints, which CollabTable proxies to rather than re-implementing the same authorization rules locally.
`AUTHGUARD_URL` is optional: leaving it unset does not fall back to any local account store — it disables authentication entirely, treating every request as authenticated with nothing gated. Only run without it for local development or a deployment you are certain does not need access control. Because AuthGuard doesn't know "this is CollabTable's initial account" and can't answer "have any accounts been registered yet" (it's a shared identity store other projects and other CollabTable instances may already use), the one-time setup screen is instead gated by a small local flag in Postgres, independent of AuthGuard's own state.
The device-sync API token (generated from the dashboard's Settings page, used by the Android app's `Authorization: Bearer` header for `/api/lists`, `/api/fields`, `/api/items`, `/api/sync`, and notification polling) is unrelated to AuthGuard and unaffected by whether it's configured: it's a long-lived per-account credential for a user's own devices, not a browser session, and stays entirely local to CollabTable's own Postgres.
| Variable | Required | Default | Description |
|----------|----------|---------|--------------|
| `DATABASE_URL` | Yes | — | PostgreSQL connection string (bring your own instance) |
| `AUTHGUARD_URL` | No | unset (auth disabled) | Base URL of the AuthGuard identity service. Leaving it unset disables authentication entirely rather than falling back to local auth. |
| `PORT` | No | `3000` | HTTP listen port |
| `APP_VERSION` | No | `dev` | Version label shown on the dashboard's About page |
| `COOKIE_SECURE` | No | `false` | Set `true` once served over HTTPS, to mark cookies `Secure` |
| `DB_INIT_RETRY_INTERVAL_MS` | No | `5000` | Delay between database-connection retry attempts at startup |
| `DB_INIT_RETRY_MAX_ATTEMPTS` | No | `0` (retry forever) | Max database-connection retry attempts at startup |
| `SYNC_MAX_FUTURE_SKEW_MS` | No | `0` | Client clock skew tolerated in sync timestamps, to avoid re-sending future-dated rows in hot loops |
| `NOTIF_RETENTION_MS` | No | `604800000` (7 days) | How long sync notifications are retained before cleanup |
---
## Quick Start
Requires an existing PostgreSQL instance reachable from the container.
```bash
docker build -t collabtable:local -f docker/Dockerfile .
docker run -d \
--name collabtable \
--restart unless-stopped \
-p 3000:3000 \
-e DATABASE_URL="postgresql://user:password@host:5432/collabtable" \
-e AUTHGUARD_URL="https://auth.example.com" \
collabtable:local
```
Open **http://\<host\>:3000**, complete setup (this registers the first account against AuthGuard), then generate a device-sync API token from the dashboard's Settings page for the Android app.
---
## Development
**Prerequisites:** Go 1.26+, Node.js 22+, a local PostgreSQL instance. For Android development: Android Studio, Android SDK 26+, JDK 21.
### Backend
```bash
cd backend
DATABASE_URL="postgresql://user:password@localhost:5432/collabtable" go run .
# Add AUTHGUARD_URL="http://localhost:8081" to authenticate against a local
# AuthGuard instance instead of running with authentication disabled.
```
### Frontend
The shared `@gabriel20xx/web-ui` package must be built once before the dashboard can resolve it (it's a `file:` dependency resolved from its built `dist/` output, which is intentionally not committed — see `shared/README.md`):
```bash
cd shared
npm install
cd ../frontend
npm install
npm run dev # Vite dev server on :5173
```
Other frontend scripts: `npm run build`, `npm run format`.
### Android
Open `CollabTableAndroid` in Android Studio, let Gradle sync, and run on an emulator or device. In the app's Settings, point it at the backend (`http://10.0.2.2:3000/api/` for an emulator) with the API token generated from the dashboard.
---
## Testing
```bash
cd backend
go test ./...
cd ../frontend
npm run check
npm run lint
```
Android: `./gradlew build`, `./gradlew ktlintCheck`, `./gradlew detekt` from `CollabTableAndroid`.
---
## CI/CD
Every push runs three GitHub Actions workflows against the backend and frontend (the Android app has no CI in this repo):
- **`docker.yml`** — builds a multi-arch image (`linux/amd64` + `linux/arm64` on `main`, `linux/amd64` otherwise) from `docker/Dockerfile` and pushes `${DOCKERHUB_USERNAME}/collabtableserver` to Docker Hub on pushes to `main`, tagged by branch name, `sha-<short-sha>`, and `latest`.
- **`lint.yml`** — runs `npm run lint` (ESLint) against `frontend`.
- **`tests.yml`** — runs `go test ./...` against `backend` and `npm run check` against `frontend`.
**Required secrets / variables in your GitHub repository settings:**
| Type | Name | Value |
|------|------|-------|
| Variable | `DOCKERHUB_USERNAME` | Your Docker Hub username |
| Secret | `DOCKERHUB_TOKEN` | Docker Hub access token |