Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0315387fe8 | ||
|
|
e0aba40321 |
No files matched your search
@@ -1,529 +1,135 @@
|
||||
# CollabTable
|
||||
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://android.com)
|
||||
[](https://go.dev)
|
||||
|
||||
A collaborative list management system with Android app and server for creating and managing shared lists with custom fields and items.
|
||||
|
||||
## Overview
|
||||
|
||||
CollabTable allows multiple users to collaboratively create and manage lists with custom fields. Perfect for:
|
||||
- Shopping lists with price tracking
|
||||
- Product catalogs
|
||||
- Task management with custom attributes
|
||||
- Any structured data collection
|
||||
|
||||
## Features
|
||||
|
||||
### Android App
|
||||
- ✨ **Beautiful Material 3 design** with dynamic colors
|
||||
- 📱 **Native Android app** built with Jetpack Compose
|
||||
- 💾 **Offline-first** with Room database
|
||||
- 🔄 **Synchronization** via transactional HTTP sync and notification polling
|
||||
- 🎨 **Custom fields** (name, link, price, category, etc.)
|
||||
- ✏️ **Inline editing** of items with auto-save
|
||||
- 📤 **Export functionality** (CSV format)
|
||||
- 🗑️ **Soft delete support** for data recovery
|
||||
- ⚙️ **Configurable server** URL and authentication
|
||||
- 📊 **Optimized performance** for large tables with thousands of rows
|
||||
- 🎯 **Column alignment** options (left, center, right)
|
||||
|
||||
### Server
|
||||
- 🚀 **Go REST API** built with `net/http`
|
||||
- 🐳 **Fully containerized** with Docker
|
||||
- 💾 **PostgreSQL** database (bring your own instance)
|
||||
- 🔄 **Advanced sync protocol** for conflict resolution
|
||||
- 🔔 **Notification polling** for background updates
|
||||
- 🔐 **Single-admin-account dashboard login** (session cookie) plus long-lived API tokens for sync clients/devices
|
||||
- 📊 **Complete CRUD operations** for all entities
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Server
|
||||
- **Docker** and a PostgreSQL instance (bring your own - this app does not run Postgres for you)
|
||||
- Or **Go 1.26+** and Node.js 22+ for local development
|
||||
|
||||
### Android App
|
||||
- **Android Studio** Hedgehog or later
|
||||
- **Android SDK 26+** (Android 8.0 or higher)
|
||||
- **JDK 21**
|
||||
- Android emulator or physical device
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Server (Docker)
|
||||
|
||||
1. **From the repository root, copy the environment file (optional):**
|
||||
```bash
|
||||
cp backend/.env.example backend/.env
|
||||
```
|
||||
# CollabTable
|
||||
|
||||
2. **Build and run the server, pointing at your own PostgreSQL instance:**
|
||||
```bash
|
||||
docker build -f docker/Dockerfile -t collabtable-server .
|
||||
docker run -d --name collabtable-server --restart unless-stopped \
|
||||
-p 3000:3000 \
|
||||
-e DATABASE_URL=postgres://user:password@host:5432/collabtable \
|
||||
collabtable-server
|
||||
```
|
||||
|
||||
Server runs on `http://localhost:3000`. Open it in a browser to create the admin account,
|
||||
then generate an API token from the dashboard's Settings page for your sync clients/devices
|
||||
— see `backend/README.md`'s "Authentication" section for details.
|
||||
|
||||
**Database:** PostgreSQL, bring your own instance via `DATABASE_URL`.
|
||||
|
||||
### Android App
|
||||
|
||||
1. **Open project in Android Studio:**
|
||||
- Open `CollabTableAndroid` folder in Android Studio
|
||||
- Wait for Gradle sync to complete
|
||||
|
||||
2. **Run the app:**
|
||||
- Run on emulator or physical device
|
||||
|
||||
3. **Configure server connection:**
|
||||
- Tap the Settings icon (⚙️) in the top bar
|
||||
- Enter your server URL:
|
||||
- **For emulator:** `http://10.0.2.2:3000/api/`
|
||||
- **For physical device:** `http://YOUR_COMPUTER_IP:3000/api/`
|
||||
- Enter the API token generated from the server dashboard's Settings page (the app's
|
||||
"Server Password" field doubles as the API token field — see note below)
|
||||
- Tap "Save"
|
||||
|
||||
**Note:** Make sure to include the trailing `/api/` in the URL.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
CollabTable/
|
||||
├── CollabTableAndroid/ # Android app
|
||||
│ ├── app/
|
||||
│ │ ├── src/main/java/com/collabtable/app/
|
||||
│ │ │ ├── data/ # Database, API, repositories
|
||||
│ │ │ │ ├── api/ # Retrofit interfaces
|
||||
│ │ │ │ ├── dao/ # Room DAOs
|
||||
│ │ │ │ ├── database/ # Room database setup
|
||||
│ │ │ │ ├── model/ # Data models
|
||||
│ │ │ │ └── repository/ # Repository pattern
|
||||
│ │ │ └── ui/ # Compose UI
|
||||
│ │ │ ├── navigation/ # Navigation setup
|
||||
│ │ │ ├── screens/ # UI screens & ViewModels
|
||||
│ │ │ └── theme/ # Material 3 theme
|
||||
│ │ └── build.gradle
|
||||
│ └── README.md
|
||||
│
|
||||
├── backend/ # Go backend
|
||||
│ ├── *.go # HTTP handlers, auth, sync, and database layer
|
||||
│ ├── go.mod # Go dependencies
|
||||
│ └── README.md # Backend documentation
|
||||
├── frontend/ # SvelteKit web dashboard (read-only database viewer)
|
||||
└── docker/ # Container build files
|
||||
└── Dockerfile
|
||||
```
|
||||
|
||||
## Technology Stack
|
||||
|
||||
### Android
|
||||
- **Language:** Kotlin
|
||||
- **UI Framework:** Jetpack Compose with Material 3
|
||||
- **Database:** Room (SQLite)
|
||||
- **Networking:** Retrofit and OkHttp (HTTP)
|
||||
- **Async:** Coroutines & Flow
|
||||
- **Architecture:** MVVM with Repository pattern
|
||||
- **Build System:** Gradle with Kotlin DSL
|
||||
|
||||
### Server
|
||||
- **Runtime:** Go 1.26+
|
||||
- **Framework:** Go `net/http`
|
||||
- **Language:** Go
|
||||
- **Database:** PostgreSQL (pgx)
|
||||
- **Containerization:** Docker
|
||||
- **Updates:** HTTP notification polling
|
||||
|
||||
## API Endpoints
|
||||
|
||||
All endpoints are prefixed with `/api/`. The sync/collaboration endpoints below (Lists,
|
||||
Fields, Items, sync) require an API token generated from the web dashboard's Settings page:
|
||||
```
|
||||
Authorization: Bearer your_api_token_here
|
||||
```
|
||||
The dashboard itself has its own separate single-admin-account login (session cookie, not a
|
||||
bearer token) — see `backend/README.md`'s "Authentication" section.
|
||||
|
||||
### Lists
|
||||
- `GET /api/lists` - Get all lists
|
||||
- `GET /api/lists/:id` - Get a specific list
|
||||
- `POST /api/lists` - Create a new list
|
||||
- `PUT /api/lists/:id` - Update a list
|
||||
- `DELETE /api/lists/:id` - Delete a list (soft delete)
|
||||
|
||||
### Fields
|
||||
- `GET /api/fields/list/:listId` - Get all fields for a list
|
||||
- `POST /api/fields` - Create a new field
|
||||
- `PUT /api/fields/:id` - Update a field (including alignment)
|
||||
- `DELETE /api/fields/:id` - Delete a field (soft delete)
|
||||
|
||||
### Items
|
||||
- `GET /api/items/list/:listId` - Get all items for a list
|
||||
- `GET /api/items/:itemId/values` - Get all values for an item
|
||||
- `POST /api/items` - Create a new item
|
||||
- `POST /api/items/values` - Create/update item values
|
||||
- `PUT /api/items/:id` - Update an item
|
||||
- `DELETE /api/items/:id` - Delete an item (soft delete)
|
||||
|
||||
### Sync
|
||||
- `POST /api/sync` - Synchronize data
|
||||
- `GET /api/notifications/poll?since=<timestamp-ms>` - Poll for remote changes
|
||||
|
||||
### Health
|
||||
- `GET /health` - Server health check
|
||||
|
||||
### Web UI
|
||||
`/`, `/about`, and `/lists/:id` serve an embedded SvelteKit dashboard (a single-page app with client-side routing) for browsing lists/fields/items read-only. The dashboard shell is public; its data endpoints require the admin session.
|
||||
- `GET /web/data` - JSON snapshot of all lists, fields, items, and values, used by the dashboard
|
||||
- `GET /web/info` - JSON tech stack info, shown on the dashboard's About page
|
||||
|
||||
See [Server README](backend/README.md) for detailed API documentation.
|
||||
|
||||
## Development
|
||||
|
||||
### Server Development
|
||||
|
||||
**Local development without Docker:**
|
||||
|
||||
1. Run the Go backend:
|
||||
```bash
|
||||
cd backend
|
||||
go test ./...
|
||||
go run .
|
||||
```
|
||||
|
||||
2. Create `.env` file:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
3. Check and build the dashboard when changing web UI code:
|
||||
```bash
|
||||
cd ../frontend
|
||||
npm ci
|
||||
npm run check
|
||||
npm run build
|
||||
cd ..
|
||||
cp -R frontend/build backend/web
|
||||
go -C backend build -o collabtable-server .
|
||||
```
|
||||
|
||||
**Useful backend commands:**
|
||||
```bash
|
||||
go -C backend test ./... # Run Go tests
|
||||
go -C backend vet ./... # Run static checks
|
||||
```
|
||||
|
||||
### Android Development
|
||||
|
||||
1. Open `CollabTableAndroid` in Android Studio
|
||||
|
||||
2. Build the project:
|
||||
```bash
|
||||
./gradlew build
|
||||
```
|
||||
|
||||
3. Run linters:
|
||||
```bash
|
||||
./gradlew ktlintCheck # Check Kotlin code style
|
||||
./gradlew detekt # Run static analysis
|
||||
```
|
||||
|
||||
4. Format code:
|
||||
```bash
|
||||
./gradlew ktlintFormat
|
||||
```
|
||||
|
||||
## Data Model
|
||||
|
||||
### Database Schema
|
||||
|
||||
#### List
|
||||
Represents a table/list container:
|
||||
```typescript
|
||||
{
|
||||
id: string; // Unique identifier
|
||||
name: string; // List name
|
||||
createdAt: number; // Creation timestamp
|
||||
updatedAt: number; // Last update timestamp
|
||||
isDeleted: boolean; // Soft delete flag
|
||||
}
|
||||
```
|
||||
|
||||
#### Field
|
||||
Defines a column/attribute in a list:
|
||||
```typescript
|
||||
{
|
||||
id: string; // Unique identifier
|
||||
listId: string; // Parent list ID
|
||||
name: string; // Field name (e.g., "Price", "Category")
|
||||
order: number; // Display order
|
||||
alignment: string; // Content alignment: "left", "center", "right"
|
||||
createdAt: number; // Creation timestamp
|
||||
updatedAt: number; // Last update timestamp
|
||||
isDeleted: boolean; // Soft delete flag
|
||||
}
|
||||
```
|
||||
|
||||
#### Item
|
||||
Represents a row in a list:
|
||||
```typescript
|
||||
{
|
||||
id: string; // Unique identifier
|
||||
listId: string; // Parent list ID
|
||||
createdAt: number; // Creation timestamp
|
||||
updatedAt: number; // Last update timestamp
|
||||
isDeleted: boolean; // Soft delete flag
|
||||
}
|
||||
```
|
||||
|
||||
#### ItemValue
|
||||
The actual value for a specific field of an item:
|
||||
```typescript
|
||||
{
|
||||
id: string; // Unique identifier
|
||||
itemId: string; // Parent item ID
|
||||
fieldId: string; // Associated field ID
|
||||
value: string; // The actual value
|
||||
updatedAt: number; // Last update timestamp
|
||||
}
|
||||
```
|
||||
|
||||
### Relationships
|
||||
- One **List** has many **Fields**
|
||||
- One **List** has many **Items**
|
||||
- One **Item** has many **ItemValues** (one per Field)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### Android App
|
||||
|
||||
**Cannot connect to server**
|
||||
- Verify server is running: visit `http://localhost:3000/health` in browser
|
||||
- Check server URL in app settings:
|
||||
- Emulator: Use `http://10.0.2.2:3000/api/`
|
||||
- Physical device: Use your computer's IP address
|
||||
- Ensure trailing `/api/` is included in URL
|
||||
- Verify the API token is correct (generate/regenerate one from the dashboard's Settings page)
|
||||
|
||||
**Gradle sync failed**
|
||||
- Update Android Studio to latest version
|
||||
- Ensure JDK 21 is installed and selected
|
||||
- Try: File → Invalidate Caches → Invalidate and Restart
|
||||
|
||||
**Build errors with Room/Kotlin**
|
||||
- Clean and rebuild: Build → Clean Project → Rebuild Project
|
||||
- Check that you're using compatible versions
|
||||
|
||||
**Large tables are slow**
|
||||
- Performance is optimized for thousands of rows
|
||||
- For tens of thousands of rows, consider server-side filtering
|
||||
- Check that debouncing is enabled (default)
|
||||
|
||||
#### Server
|
||||
|
||||
**Port 3000 already in use**
|
||||
```bash
|
||||
# Find and kill process using port 3000
|
||||
lsof -ti:3000 | xargs kill -9
|
||||
# Or change the port mapping in your `docker run` command or .env
|
||||
```
|
||||
|
||||
**Docker container won't start**
|
||||
```bash
|
||||
# View logs
|
||||
docker logs -f collabtable-server
|
||||
|
||||
# Rebuild container
|
||||
docker stop collabtable-server && docker rm collabtable-server
|
||||
docker build -f docker/Dockerfile -t collabtable-server . && docker run -d --name collabtable-server ...
|
||||
```
|
||||
|
||||
**Database connection error (PostgreSQL)**
|
||||
- Verify your PostgreSQL instance is running and reachable from the container
|
||||
- Check `DATABASE_URL` in `.env`
|
||||
- Ensure the database exists
|
||||
|
||||
### Getting Help
|
||||
|
||||
- Check the [Android README](CollabTableAndroid/README.md) for app-specific details
|
||||
- Check the [Server README](backend/README.md) for server-specific details
|
||||
- Review Docker logs: `docker logs -f collabtable-server`
|
||||
- Open an issue on GitHub with detailed error messages
|
||||
|
||||
## Synchronization
|
||||
|
||||
CollabTable uses a sophisticated sync protocol to keep data consistent across clients:
|
||||
|
||||
### Sync Strategy
|
||||
- **Transport:** HTTP POST (`/api/sync`)
|
||||
- **Background updates:** Notification polling (`/api/notifications/poll`)
|
||||
- **Conflict Resolution:** Latest timestamp wins
|
||||
|
||||
### How It Works
|
||||
1. **Client → Server:** Client sends all local changes since last sync timestamp
|
||||
2. **Server Processing:** Server saves client changes and retrieves server changes
|
||||
3. **Server → Client:** Server returns changes made since client's last sync
|
||||
4. **Client Update:** Client applies server updates locally
|
||||
5. **Timestamp Update:** Client stores new server timestamp for next sync
|
||||
|
||||
### Sync Flow
|
||||
```
|
||||
Client Server
|
||||
| |
|
||||
|-- Sync Request (local changes) ---->|
|
||||
| (lists, fields, items, values) |
|
||||
| |
|
||||
|<-- Sync Response (server changes) --|
|
||||
| (updates + new serverTimestamp) |
|
||||
| |
|
||||
```
|
||||
|
||||
### Features
|
||||
- **Automatic Sync:** Triggered on app start and after local changes
|
||||
- **Soft Deletes:** Deleted items can be recovered on server
|
||||
- **Optimistic Updates:** UI updates immediately, syncs in background
|
||||
- **Performance:** Debounced updates for large table operations
|
||||
|
||||
## Docker & Deployment
|
||||
|
||||
### Data Persistence
|
||||
|
||||
**PostgreSQL**
|
||||
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`) against your own instance -
|
||||
this app does not manage Postgres storage itself
|
||||
|
||||
### Docker Commands
|
||||
|
||||
**Stop the container:**
|
||||
```bash
|
||||
docker stop collabtable-server
|
||||
```
|
||||
|
||||
**View logs:**
|
||||
```bash
|
||||
docker logs -f collabtable-server
|
||||
```
|
||||
|
||||
**Rebuild and restart:**
|
||||
```bash
|
||||
docker build -f docker/Dockerfile -t collabtable-server . && docker restart collabtable-server
|
||||
```
|
||||
|
||||
**Check running containers:**
|
||||
```bash
|
||||
docker ps
|
||||
```
|
||||
|
||||
### Production Deployment
|
||||
|
||||
**Environment Variables**
|
||||
Configure these in `.env` or your `docker run` command:
|
||||
```env
|
||||
PORT=3000 # Server port
|
||||
APP_VERSION=dev # Dashboard version label
|
||||
DATABASE_URL=postgres://user:pass@postgres:5432/collabtable
|
||||
COOKIE_SECURE=true # Requires HTTPS
|
||||
```
|
||||
|
||||
**Security Recommendations**
|
||||
1. Generate the admin account and an API token on first run (see "Authentication" above)
|
||||
2. Use HTTPS with a reverse proxy (nginx, Caddy), and set `COOKIE_SECURE=true`
|
||||
3. Regular database backups
|
||||
4. Keep Docker images updated
|
||||
5. Restrict network access to server ports
|
||||
|
||||
**Reverse Proxy Example (nginx)**
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name example.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Here's how you can help:
|
||||
|
||||
### Getting Started
|
||||
1. Fork the repository
|
||||
2. Create a feature branch: `git checkout -b feature/your-feature-name`
|
||||
3. Make your changes
|
||||
4. Test your changes thoroughly
|
||||
5. Commit with clear messages: `git commit -m "feat: add new feature"`
|
||||
6. Push to your fork: `git push origin feature/your-feature-name`
|
||||
7. Open a Pull Request
|
||||
|
||||
### Development Guidelines
|
||||
|
||||
**Code Style**
|
||||
- **Android:** Follow Kotlin conventions, use ktlint for formatting
|
||||
- **Server:** Follow Go conventions, run `gofmt`, and keep handlers testable
|
||||
- Keep functions small and focused
|
||||
- Write meaningful variable and function names
|
||||
- Add comments for complex logic
|
||||
|
||||
**Testing**
|
||||
- Test your changes on both emulator and physical devices (Android)
|
||||
- Test against a PostgreSQL backend (Server)
|
||||
- Verify sync works correctly with multiple clients
|
||||
- Test with large datasets to ensure performance
|
||||
|
||||
**Commit Messages**
|
||||
Follow conventional commits:
|
||||
- `feat:` for new features
|
||||
- `fix:` for bug fixes
|
||||
- `docs:` for documentation changes
|
||||
- `style:` for formatting changes
|
||||
- `refactor:` for code refactoring
|
||||
- `test:` for adding tests
|
||||
- `chore:` for maintenance tasks
|
||||
|
||||
### Areas for Contribution
|
||||
|
||||
**Features**
|
||||
- Additional export formats (JSON, Excel)
|
||||
- Search and filter functionality
|
||||
- Batch operations
|
||||
- User authentication and permissions
|
||||
- Drag-and-drop row reordering
|
||||
- Rich text field support
|
||||
|
||||
**Improvements**
|
||||
- Performance optimization for very large tables
|
||||
- Better offline support
|
||||
- Enhanced error handling
|
||||
- Accessibility improvements
|
||||
- Internationalization (i18n)
|
||||
|
||||
**Documentation**
|
||||
- API documentation improvements
|
||||
- Tutorial videos or blog posts
|
||||
- Translation to other languages
|
||||
- More code examples
|
||||
|
||||
### Pull Request Guidelines
|
||||
- Keep PRs focused on a single feature or fix
|
||||
- Update documentation if needed
|
||||
- Ensure all tests pass
|
||||
- Add screenshots for UI changes
|
||||
- Reference any related issues
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
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 |
|
||||
+86
-186
@@ -1,170 +1,99 @@
|
||||
# shared packages
|
||||
# shared
|
||||
|
||||
This folder is the single source of truth for reusable web UI across the projects in this workspace.
|
||||
The single source of truth for code reused across every project in this workspace: a Svelte design system and application shell, backend helpers (Postgres access, config, auth/session persistence, an AuthGuard client, log shipping) in four languages, and the Go media-backend/media-webui powering the whole `MEDIA_SERVICE`-family of projects.
|
||||
|
||||
The first packages are:
|
||||
---
|
||||
|
||||
- `@gabriel20xx/design-tokens` — colors, typography, spacing, radii, shadows, and light/dark theme variables.
|
||||
- `@gabriel20xx/web-ui` — Svelte components for the application shell, header/navigation, authentication, dialogs, profile/settings/about windows, buttons, cards, badges, and page headers.
|
||||
- `repos.gfranz.ch/Gabriel20xx/shared/backend` — Go helpers for environment configuration, `pgx` PostgreSQL pools, transactions, common auth persistence/passwords/tokens, and embedded Goose migrations.
|
||||
- `@gabriel20xx/node-backend` — Node.js `pg` pool/configuration, transactions, migrations, and auth/session persistence.
|
||||
- `gabriel20xx-shared-backend` — Python `asyncpg` pool/configuration and auth/session persistence.
|
||||
## Tech Stack
|
||||
|
||||
The components do not import `$app/state`, `$lib` stores, or a project-specific API. Applications provide those things through props and callbacks.
|
||||
| Layer | Technology |
|
||||
|-------|------------|
|
||||
| Web UI | Svelte, TypeScript |
|
||||
| Backend helpers | Go, Node.js, Python, Java |
|
||||
| Database | PostgreSQL (via `pgx`, `pg`, or `asyncpg`) |
|
||||
| Package registry | Gitea npm / Go / PyPI registries |
|
||||
|
||||
## Build and check the packages
|
||||
---
|
||||
|
||||
Run these commands from this directory:
|
||||
## Packages
|
||||
|
||||
| Package | Language | Purpose |
|
||||
|---|---|---|
|
||||
| `@gabriel20xx/design-tokens` | CSS | Colors, typography, spacing, radii, shadows, light/dark theme variables. |
|
||||
| `@gabriel20xx/web-ui` | Svelte | Application shell, header/navigation, auth screens, dialogs, buttons, cards, badges. |
|
||||
| `@gabriel20xx/media-shared-assets` | Browser JS/CSS | Shared client-side assets for the media-backend/`MEDIA_SERVICE` family. |
|
||||
| `repos.gfranz.ch/Gabriel20xx/shared/backend` | Go | Env config, `pgx` pools/transactions, auth persistence, an AuthGuard client (`authclient`), log shipping (`logshipper`), embedded Goose migrations. |
|
||||
| `@gabriel20xx/node-backend` | Node.js | `pg` pool/config/transactions/migrations, auth/session persistence, an AuthGuard client. |
|
||||
| `gabriel20xx-shared-backend` | Python | `asyncpg` pool/config, auth/session persistence, an AuthGuard client. |
|
||||
| `com.gabriel20xx.shared.auth` | Java | An AuthGuard client, mirroring the Go/Node/Python ones. |
|
||||
| `media-backend` / `media-webui` | Go / Svelte | The Go binary and web UI powering the `MEDIA_SERVICE`-family projects (see below). |
|
||||
|
||||
The `web-ui` components don't import `$app/state`, `$lib` stores, or a project-specific API — applications provide those through props and callbacks.
|
||||
|
||||
---
|
||||
|
||||
## How consumers actually use this
|
||||
|
||||
There are two different distribution paths in this workspace, used for different things:
|
||||
|
||||
### Vendored snapshot (the one every project actually uses)
|
||||
|
||||
Every consumer project vendors a full copy of this repo's tracked files into its own `shared/` (or, for the `media-backend` family, `engine/`) directory, committed directly rather than installed from a registry. This exists because none of these projects are meant to resolve a private registry dependency in a fresh CI checkout without extra credentials, and because a git submodule pointing at this (private) repo breaks the same way — see `scripts/sync-consumers.ps1`'s own comments for the full history.
|
||||
|
||||
To pull the latest snapshot into every registered consumer:
|
||||
|
||||
```powershell
|
||||
# from this repo
|
||||
.\scripts\sync-consumers.ps1 -Commit -Push
|
||||
```
|
||||
|
||||
The script copies every tracked file in this repo into each consumer's destination folder, regenerates any `package-lock.json` that depends on a local `file:` package, and commits/pushes only if something actually changed ("Sync shared/engine snapshot from `<short-sha>`"). Consumers are registered in the script's `$consumerProjects` list, each with a destination folder (`shared` by default, `engine` for the media-backend family). A `post-commit` hook (installed via `scripts/install-sync-hook.ps1`) runs this automatically — with `-Commit` only, never `-Push` — after every commit to this repo, so pushing the sync commits it creates to each consumer is still a manual follow-up step.
|
||||
|
||||
### Published registry packages (for standalone/external use)
|
||||
|
||||
The npm, Go, and Python packages are also published to this Gitea instance's package registries, for a project that genuinely wants a version-pinned dependency rather than a vendored snapshot. `.gitea/workflows/publish-*.yml` publish on a `v*` tag push or a matching Gitea release; `PACKAGE_REGISTRY_USERNAME`/`PACKAGE_REGISTRY_TOKEN` must be configured as Actions secrets. See "Publishing" below for the details. No project in this workspace currently consumes a package this way — it exists for future/external use.
|
||||
|
||||
---
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run check
|
||||
npm run build
|
||||
npm run build # builds packages/web-ui/dist (gitignored, not committed)
|
||||
npm run test:node-backend
|
||||
```
|
||||
|
||||
`npm run build` creates the distributable package in `packages/web-ui/dist`. The generated `dist` directory is intentionally ignored by the package configuration and should not be committed.
|
||||
|
||||
Validate the Go backend package from `shared/backend`:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
go test ./...
|
||||
go vet ./...
|
||||
```
|
||||
|
||||
## Publish the individual packages
|
||||
|
||||
The package names use the `@gabriel20xx` npm scope. The `publish-npm.yml` and
|
||||
`publish-python.yml` Gitea workflows publish the packages when a `v*` tag is pushed or a
|
||||
matching Gitea release is published. Configure `PACKAGE_REGISTRY_USERNAME` and
|
||||
`PACKAGE_REGISTRY_TOKEN` as user Actions secrets before publishing.
|
||||
|
||||
The npm workflow publishes `design-tokens` first because `web-ui` depends on it. It also
|
||||
skips an npm version that is already present, so retrying a partially completed release is safe.
|
||||
The Python workflow uses Twine's `--skip-existing` option for the same reason.
|
||||
|
||||
## Install individual packages from a registry
|
||||
|
||||
From a project's frontend directory, install the published UI package from Gitea:
|
||||
|
||||
```bash
|
||||
npm config set @gabriel20xx:registry https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/
|
||||
npm config set //repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken "$PACKAGE_REGISTRY_TOKEN"
|
||||
npm install @gabriel20xx/web-ui@0.1.0
|
||||
cd media-backend
|
||||
go test ./...
|
||||
go vet ./...
|
||||
```
|
||||
|
||||
The design-token package is installed transitively. Install it directly only when an application needs to reference its theme file itself:
|
||||
---
|
||||
|
||||
```bash
|
||||
npm install @gabriel20xx/design-tokens@0.1.0
|
||||
```
|
||||
|
||||
Import the shared stylesheet once from the application's global stylesheet, before project-specific overrides:
|
||||
|
||||
```css
|
||||
@import '@gabriel20xx/web-ui/styles.css';
|
||||
```
|
||||
|
||||
The stylesheet imports the design tokens and uses an `sc-` prefix, so it does not require Tailwind and does not collide with existing project class names. Set `data-theme="light"` or `data-theme="dark"` on the application root to select a theme. Dark is the default.
|
||||
|
||||
## Use the shared Go backend package
|
||||
|
||||
The Go module is published to the private Gitea Go Package Registry. Configure a
|
||||
read-only package token in the consuming workflow as `PACKAGE_REGISTRY_USERNAME`
|
||||
and `PACKAGE_REGISTRY_TOKEN`, then configure Go to use the registry before running
|
||||
`go get`, `go test`, or `go build`:
|
||||
|
||||
```bash
|
||||
export GOPROXY=https://repos.gfranz.ch/api/packages/Gabriel20xx/go,https://proxy.golang.org
|
||||
export GONOSUMDB=repos.gfranz.ch/Gabriel20xx/shared/*
|
||||
```
|
||||
|
||||
From a Go backend directory, add the released module (the module is a subdirectory of the shared repository):
|
||||
|
||||
```bash
|
||||
go get repos.gfranz.ch/Gabriel20xx/shared/backend@v0.1.0
|
||||
```
|
||||
|
||||
Then initialize the pool and shared auth store at startup:
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/postgres"
|
||||
)
|
||||
|
||||
cfg, err := postgres.FromEnv()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pool, err := postgres.Open(context.Background(), cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
if err := auth.EnsureSchema(context.Background(), pool, auth.DefaultSchemaOptions()); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
authStore := auth.NewStore(pool)
|
||||
```
|
||||
|
||||
Use `auth.SchemaOptions{SingleUser: false, APITokens: true}` for a multi-user service that needs API tokens. The shared package owns persistence primitives and password/token utilities; each application still owns authorization rules, cookies, HTTP handlers, roles, and domain tables.
|
||||
|
||||
For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")`. The package does not contain application tables, so migrations remain versioned with the service that owns those tables.
|
||||
|
||||
The Go module lives under `backend`, so its release tag must use the submodule prefix (`backend/v0.1.0`). The consuming `go.mod` uses the normal module version (`v0.1.0`). To publish a release, push a tag such as `backend/v0.1.0`; the Gitea workflow packages the module and uploads it to the private registry. The workflow also listens for Gitea's `release.published` event, so a release can be published from the Gitea Releases page to manually retry a failed upload for an existing tag. Never reuse a package version that was already uploaded successfully.
|
||||
|
||||
For Node services, install the shared package after publishing it:
|
||||
|
||||
```bash
|
||||
npm install @gabriel20xx/node-backend@0.1.0
|
||||
```
|
||||
|
||||
For Python services, configure the Gitea index and install the published wheel:
|
||||
|
||||
```bash
|
||||
python -m pip install \
|
||||
--index-url "https://$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN@repos.gfranz.ch/api/packages/Gabriel20xx/pypi/simple" \
|
||||
gabriel20xx-shared-backend==0.1.0
|
||||
```
|
||||
|
||||
The Node and Python packages intentionally expose the same infrastructure concepts but use their native database drivers. This is the safe way to share behavior across the polyglot services; a Go package cannot be imported by the Python or Node applications.
|
||||
|
||||
## Existing MediaCollection shared package
|
||||
|
||||
`Original/MediaCollection/MediaShared` is an existing, larger media-specific package. It remains in place for media workflows and startup integration, while the MediaCollection WebUI authentication surface and admin-reset code use this shared package. Its remaining generic responsibilities can be migrated independently without introducing another authentication screen.
|
||||
|
||||
## Typical application wiring
|
||||
## Typical `web-ui` wiring
|
||||
|
||||
```svelte
|
||||
<script lang="ts">
|
||||
import {
|
||||
AboutDialog,
|
||||
AppShell,
|
||||
ProfileDialog,
|
||||
SettingsDialog
|
||||
} from '@gabriel20xx/web-ui';
|
||||
import { AboutDialog, AppShell, ProfileDialog, SettingsDialog } from '@gabriel20xx/web-ui';
|
||||
import { page } from '$app/state';
|
||||
|
||||
let aboutOpen = $state(false);
|
||||
let profileOpen = $state(false);
|
||||
let settingsOpen = $state(false);
|
||||
|
||||
const navItems = [
|
||||
{ href: '/', label: 'Dashboard' },
|
||||
{ href: '/about', label: 'About' }
|
||||
];
|
||||
</script>
|
||||
|
||||
<AppShell
|
||||
brand="My application"
|
||||
currentPath={page.url.pathname}
|
||||
navItems={navItems}
|
||||
navItems={[{ href: '/', label: 'Dashboard' }]}
|
||||
onLogout={() => auth.logout()}
|
||||
onProfile={() => (profileOpen = true)}
|
||||
onSettings={() => (settingsOpen = true)}
|
||||
@@ -174,73 +103,44 @@ The Node and Python packages intentionally expose the same infrastructure concep
|
||||
<slot />
|
||||
{/snippet}
|
||||
</AppShell>
|
||||
|
||||
<AboutDialog
|
||||
bind:open={aboutOpen}
|
||||
brand="My application"
|
||||
description="A short description supplied by this project."
|
||||
version="1.0.0"
|
||||
/>
|
||||
|
||||
<SettingsDialog bind:open={settingsOpen}>
|
||||
{#snippet children()}
|
||||
<!-- Project-specific settings controls go here. -->
|
||||
{/snippet}
|
||||
</SettingsDialog>
|
||||
|
||||
<ProfileDialog
|
||||
bind:open={profileOpen}
|
||||
currentEmail={auth.user?.email ?? ''}
|
||||
currentUsername={auth.user?.username ?? ''}
|
||||
onSave={(profile) => auth.updateProfile(profile)}
|
||||
/>
|
||||
```
|
||||
|
||||
The shared profile menu exposes Profile, Settings, About, and Log out. It uses the `About` navigation item's href automatically; pass `aboutHref` or `onAbout` to `AppShell` when a project uses a custom About destination or dialog.
|
||||
Import the stylesheet once, before project-specific overrides: `@import '@gabriel20xx/web-ui/styles.css';`. It uses an `sc-` class prefix, so it doesn't require Tailwind and doesn't collide with existing project classes. Set `data-theme="light"` or `data-theme="dark"` on the application root; dark is the default.
|
||||
|
||||
For authentication, use the same shell with `AuthPage` and connect the callbacks to the application's existing auth service:
|
||||
For authentication, use `AuthPage` and wire its callbacks to the project's auth service — every project in this workspace either talks to AuthGuard directly or proxies through its own backend to AuthGuard. See `Central/AuthGuard/README.md` for the identity service this whole authentication surface is built to work with.
|
||||
|
||||
```svelte
|
||||
<AuthPage
|
||||
brand="My application"
|
||||
faviconHref="/favicon.svg"
|
||||
onLogin={(credentials) => auth.login(credentials.identifier, credentials.password)}
|
||||
onSetup={(credentials) => auth.setup(credentials)}
|
||||
onRequestReset={() => auth.requestAdminReset()}
|
||||
onConfirmReset={(code) => auth.confirmAdminReset(code)}
|
||||
setupRequired={setupRequired}
|
||||
tagline="Your project tagline"
|
||||
/>
|
||||
---
|
||||
|
||||
## Using the Go backend package
|
||||
|
||||
```go
|
||||
import (
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/postgres"
|
||||
)
|
||||
|
||||
pool, _ := postgres.Open(ctx, postgres.FromEnv())
|
||||
authStore := auth.NewStore(pool) // local Postgres-backed accounts
|
||||
client := authclient.New(authGuardURL) // or proxy to AuthGuard instead
|
||||
```
|
||||
|
||||
Applications that support MFA can enable the shared optional authenticator-code field with
|
||||
`showTotp` and forward `credentials.totpToken` to their login endpoint. The base layout and reset
|
||||
controls remain the same as every other shared auth screen.
|
||||
Use `auth.SchemaOptions{SingleUser: false, APITokens: true}` for a multi-user service that needs API tokens. This package owns persistence primitives and password/token utilities; each application still owns authorization rules, cookies, HTTP handlers, roles, and domain tables. For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")` — this package has no application tables of its own, so migrations stay versioned with the service that owns those tables.
|
||||
|
||||
The shared reset controls request a short-lived code printed by the server-side auth package and consume it once after confirmation. The package handles form state, validation attributes, loading state, and error presentation. The application remains responsible for deciding where to navigate after a successful action and how errors are returned.
|
||||
---
|
||||
|
||||
## Local package development
|
||||
|
||||
Before publishing, build the packages and install them from the local workspace in a frontend project:
|
||||
## Publishing
|
||||
|
||||
```bash
|
||||
# From Web/shared
|
||||
npm run build
|
||||
|
||||
# From a project frontend directory; do not commit this file dependency for CI
|
||||
npm install ../../../shared/packages/design-tokens ../../../shared/packages/web-ui
|
||||
npm run changeset # describe the change
|
||||
npm run version-packages # bump versions, commit the changelog
|
||||
npm run release # publishes npm packages in dependency order (design-tokens first)
|
||||
```
|
||||
|
||||
For CI and normal development, use the published version instead of a `file:` dependency. A local file dependency only works when the checkout also contains the sibling `shared` directory.
|
||||
The Go module lives under `backend`, so its release tag uses the submodule prefix (`backend/v0.1.0`); push that tag and the Gitea workflow packages and uploads the module. The npm and Python workflows both skip a version already present in the registry, so retrying a partially completed release is safe.
|
||||
|
||||
## Updating the design system
|
||||
---
|
||||
|
||||
When a component or token changes:
|
||||
## CI/CD
|
||||
|
||||
1. Run `npm run changeset` and describe the change.
|
||||
2. Run `npm run version-packages` and commit the generated version/changelog files.
|
||||
3. Run `npm install`, `npm run check`, `npm run build`, and `npm run test:node-backend`.
|
||||
4. Run `npm run release`; Changesets publishes the npm packages in dependency order.
|
||||
5. Update each project with `npm install @gabriel20xx/web-ui@<new-version>` and commit its lockfile.
|
||||
|
||||
The package boundary is intentional: application-specific screens stay in their project, while repeated visual language and account/layout infrastructure stays here.
|
||||
`lint.yml` and `tests.yml` each run three jobs — Node/Svelte, Go, and Python — plus dedicated `media-backend-lint.yml`/`media-backend-tests.yml` for the `media-backend` Go module. `publish-npm.yml`, `publish-go.yml`, and `publish-python.yml` handle registry publishing as described above.
|
||||
Reference in new issue
Block a user