feat: initialize CollabTableServer with models, sync, and notification handling
- Add go.mod and go.sum for dependency management - Implement models for List, Field, Item, ItemValue, SyncRequest, SyncResponse, and NotificationEvent - Create notification handling functions including enqueueNotification and ignoreNotificationError - Implement sync functionality to handle data synchronization between client and server - Add web data handling and notification polling endpoints - Include tests for timestamp normalization and sync logic - Embed web assets for serving the frontend application
This commit is contained in:
1 parent
e12940fef0
commit
cac2faae2e
41 files changed
+2535
-5502
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://android.com)
|
||||
[](https://nodejs.org)
|
||||
[](https://go.dev)
|
||||
|
||||
A collaborative list management system with Android app and server for creating and managing shared lists with custom fields and items.
|
||||
|
||||
@@ -20,7 +20,7 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
||||
- ✨ **Beautiful Material 3 design** with dynamic colors
|
||||
- 📱 **Native Android app** built with Jetpack Compose
|
||||
- 💾 **Offline-first** with Room database
|
||||
- 🔄 **Real-time synchronization** via WebSocket (with HTTP fallback)
|
||||
- 🔄 **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)
|
||||
@@ -30,11 +30,11 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
||||
- 🎯 **Column alignment** options (left, center, right)
|
||||
|
||||
### Server
|
||||
- 🚀 **Express.js REST API** with TypeScript
|
||||
- 🚀 **Go REST API** built with `net/http`
|
||||
- 🐳 **Fully containerized** with Docker
|
||||
- 💾 **PostgreSQL** database (bring your own instance)
|
||||
- 🔄 **Advanced sync protocol** for conflict resolution
|
||||
- 🔌 **WebSocket support** for real-time updates
|
||||
- 🔔 **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
|
||||
|
||||
@@ -42,7 +42,7 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
||||
|
||||
### Server
|
||||
- **Docker** and a PostgreSQL instance (bring your own - this app does not run Postgres for you)
|
||||
- Or **Node.js 20+** for local development
|
||||
- Or **Go 1.26+** and Node.js 22+ for local development
|
||||
|
||||
### Android App
|
||||
- **Android Studio** Hedgehog or later
|
||||
@@ -119,11 +119,9 @@ CollabTable/
|
||||
│ │ └── build.gradle
|
||||
│ └── README.md
|
||||
│
|
||||
└── CollabTableServer/ # Node.js server
|
||||
├── src/
|
||||
│ ├── models/ # Data models & database logic
|
||||
│ ├── routes/ # API endpoints
|
||||
│ └── index.ts # Server entry point
|
||||
└── CollabTableServer/ # Go server
|
||||
├── *.go # HTTP handlers, auth, sync, and database layer
|
||||
├── go.mod # Go dependencies
|
||||
├── webui/ # SvelteKit web dashboard (read-only database viewer)
|
||||
├── Dockerfile
|
||||
└── README.md
|
||||
@@ -135,18 +133,18 @@ CollabTable/
|
||||
- **Language:** Kotlin
|
||||
- **UI Framework:** Jetpack Compose with Material 3
|
||||
- **Database:** Room (SQLite)
|
||||
- **Networking:** Retrofit (HTTP), OkHttp WebSocket
|
||||
- **Networking:** Retrofit and OkHttp (HTTP)
|
||||
- **Async:** Coroutines & Flow
|
||||
- **Architecture:** MVVM with Repository pattern
|
||||
- **Build System:** Gradle with Kotlin DSL
|
||||
|
||||
### Server
|
||||
- **Runtime:** Node.js 20+
|
||||
- **Framework:** Express.js
|
||||
- **Language:** TypeScript
|
||||
- **Database:** PostgreSQL (pg)
|
||||
- **Runtime:** Go 1.26+
|
||||
- **Framework:** Go `net/http`
|
||||
- **Language:** Go
|
||||
- **Database:** PostgreSQL (pgx)
|
||||
- **Containerization:** Docker
|
||||
- **Real-time:** WebSocket support
|
||||
- **Updates:** HTTP notification polling
|
||||
|
||||
## API Endpoints
|
||||
|
||||
@@ -179,15 +177,15 @@ bearer token) — see `CollabTableServer/README.md`'s "Authentication" section.
|
||||
- `PUT /api/items/:id` - Update an item
|
||||
- `DELETE /api/items/:id` - Delete an item (soft delete)
|
||||
|
||||
### Sync
|
||||
- `POST /api/sync` - Synchronize data (HTTP fallback)
|
||||
- `WebSocket /api/ws` - WebSocket endpoint for real-time sync
|
||||
### 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 a SvelteKit dashboard (a single-page app with client-side routing) for browsing lists/fields/items read-only. It's unauthenticated, same as before this endpoint existed.
|
||||
`/`, `/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
|
||||
|
||||
@@ -199,35 +197,36 @@ See [Server README](CollabTableServer/README.md) for detailed API documentation.
|
||||
|
||||
**Local development without Docker:**
|
||||
|
||||
1. Install dependencies:
|
||||
```bash
|
||||
cd CollabTableServer
|
||||
npm install
|
||||
```
|
||||
1. Run the Go backend:
|
||||
```bash
|
||||
cd CollabTableServer
|
||||
go test ./...
|
||||
go run .
|
||||
```
|
||||
|
||||
2. Create `.env` file:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
3. Start development server with hot reload:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
4. Build for production:
|
||||
```bash
|
||||
npm run build
|
||||
npm start
|
||||
```
|
||||
|
||||
**Useful commands:**
|
||||
```bash
|
||||
npm run lint # Check code style
|
||||
npm run format # Auto-format code
|
||||
```
|
||||
|
||||
### Android Development
|
||||
3. Check and build the dashboard when changing web UI code:
|
||||
```bash
|
||||
cd webui
|
||||
npm ci
|
||||
npm run check
|
||||
npm run build
|
||||
cd ..
|
||||
cp -R webui/build web
|
||||
go build -o collabtable-server .
|
||||
```
|
||||
|
||||
**Useful backend commands:**
|
||||
```bash
|
||||
go test ./... # Run Go tests
|
||||
go vet ./... # Run static checks
|
||||
```
|
||||
|
||||
### Android Development
|
||||
|
||||
1. Open `CollabTableAndroid` in Android Studio
|
||||
|
||||
@@ -370,10 +369,10 @@ docker build -t collabtable-server . && docker run -d --name collabtable-server
|
||||
|
||||
CollabTable uses a sophisticated sync protocol to keep data consistent across clients:
|
||||
|
||||
### Sync Strategy
|
||||
- **Primary:** WebSocket (`/api/ws`) for real-time, low-latency sync
|
||||
- **Fallback:** HTTP POST (`/api/sync`) when WebSocket fails
|
||||
- **Conflict Resolution:** Latest timestamp wins
|
||||
### 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
|
||||
@@ -394,38 +393,7 @@ Client Server
|
||||
| |
|
||||
```
|
||||
|
||||
### WebSocket Protocol
|
||||
Send JSON messages to `/api/ws`:
|
||||
```json
|
||||
{
|
||||
"type": "sync",
|
||||
"id": "unique-request-id",
|
||||
"payload": {
|
||||
"lastSyncTimestamp": 1234567890,
|
||||
"lists": [...],
|
||||
"fields": [...],
|
||||
"items": [...],
|
||||
"itemValues": [...]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"type": "syncResponse",
|
||||
"id": "unique-request-id",
|
||||
"payload": {
|
||||
"lists": [...],
|
||||
"fields": [...],
|
||||
"items": [...],
|
||||
"itemValues": [...],
|
||||
"serverTimestamp": 1234567890
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Features
|
||||
### 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
|
||||
@@ -466,9 +434,9 @@ docker ps
|
||||
**Environment Variables**
|
||||
Configure these in `.env` or your `docker run` command:
|
||||
```env
|
||||
PORT=3000 # Server port
|
||||
NODE_ENV=production # Environment
|
||||
DATABASE_URL=postgres://user:pass@postgres:5432/collabtable
|
||||
PORT=3000 # Server port
|
||||
APP_VERSION=dev # Dashboard version label
|
||||
DATABASE_URL=postgres://user:pass@postgres:5432/collabtable
|
||||
COOKIE_SECURE=true # Requires HTTPS
|
||||
```
|
||||
|
||||
@@ -487,11 +455,7 @@ server {
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -513,7 +477,7 @@ Contributions are welcome! Here's how you can help:
|
||||
|
||||
**Code Style**
|
||||
- **Android:** Follow Kotlin conventions, use ktlint for formatting
|
||||
- **Server:** Follow TypeScript/JavaScript conventions, use Prettier
|
||||
- **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
|
||||
|
||||
Reference in new issue
Block a user