CollabTable Server
A collaborative table management server built with Node.js, Express, TypeScript, and PostgreSQL.
Features
- RESTful API for managing lists, fields, items, and values
- Real-time synchronization via WebSocket (primary) with HTTP fallback
- PostgreSQL (pg) database backend
- Single-admin-account web dashboard login (session cookie, bcrypt-hashed password) plus a long-lived API token for sync clients/devices, generated from the dashboard
- Dockerized deployment (bring your own PostgreSQL instance)
- TypeScript for type safety
Prerequisites
- Docker and a PostgreSQL instance (bring your own - this app does not run Postgres for you)
- Or Node.js 20+ and a PostgreSQL instance (for local development)
Quick Start with Docker
-
Clone the repository
-
Navigate to the server directory:
cd CollabTableServer -
Build the image:
docker build -t collabtable-server . -
Run it, pointing at your own Postgres instance:
docker run -d --name collabtable-server --restart unless-stopped \ -p 3000:3000 \ -e DATABASE_URL=postgres://user:password@host:5432/collabtable \ -e COOKIE_SECURE=false \ collabtable-server
The server will be available at http://localhost:3000. Open it in a browser to create the
admin account, then generate an API token from the dashboard for your sync clients/devices.
Local Development
-
Install dependencies:
npm install -
Create a
.envfile:cp .env.example .env -
Point it at a PostgreSQL instance in
.env:DATABASE_URL=postgres://user:password@localhost:5432/collabtable # Set to "true" once served over HTTPS COOKIE_SECURE=false -
Start the development server:
npm run dev
API Endpoints
Lists
GET /api/lists- Get all listsGET /api/lists/:id- Get a specific listPOST /api/lists- Create a new listPUT /api/lists/:id- Update a listDELETE /api/lists/:id- Delete a list (soft delete)
Fields
GET /api/fields/list/:listId- Get all fields for a listPOST /api/fields- Create a new fieldPUT /api/fields/:id- Update a fieldDELETE /api/fields/:id- Delete a field (soft delete)
Items
GET /api/items/list/:listId- Get all items for a listGET /api/items/:itemId/values- Get all values for an itemPOST /api/items- Create a new itemPOST /api/items/values- Create/update an item valuePUT /api/items/:id- Update an itemDELETE /api/items/:id- Delete an item (soft delete)
Sync
POST /api/sync- Synchronize data between client and server
WebSocket
GET /api/ws- WebSocket endpoint. Send JSON messages:{"type":"ping"}→{"type":"pong"}{"type":"sync", "id":"<uuid>", "payload": { ...SyncRequest }}→{"type":"syncResponse", "id":"<uuid>", "payload": { ...SyncResponse }}
Authentication: include header Authorization: Bearer <api-token> on sync/collaboration API requests, using the API token generated from the web dashboard's Settings page (see "Authentication" below).
Health Check
GET /health- Check server health
Data Models
List
{
id: string;
name: string;
createdAt: number;
updatedAt: number;
isDeleted: boolean;
}
Field
{
id: string;
listId: string;
name: string;
order: number;
createdAt: number;
updatedAt: number;
isDeleted: boolean;
}
Item
{
id: string;
listId: string;
createdAt: number;
updatedAt: number;
isDeleted: boolean;
}
ItemValue
{
id: string;
itemId: string;
fieldId: string;
value: string;
updatedAt: number;
}
Sync Protocol
The sync endpoint accepts a POST request with the following structure:
{
"lastSyncTimestamp": 1234567890,
"lists": [...],
"fields": [...],
"items": [...],
"itemValues": [...]
}
The server responds with:
{
"lists": [...],
"fields": [...],
"items": [...],
"itemValues": [...],
"serverTimestamp": 1234567890
}
The sync process:
- Client sends all local changes since the last sync
- Server saves the client's changes
- Server returns all changes made on the server since the client's last sync
- Client applies the server's changes locally
Building for Production
Build the TypeScript code:
npm run build
Start the production server:
npm start
Docker Commands
Stop the container:
docker stop collabtable-server
View logs:
docker logs -f collabtable-server
Rebuild and restart:
docker build -t collabtable-server . && docker restart collabtable-server
Environment Variables
PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)COOKIE_SECURE- Set totrueto mark the admin session cookieSecure(requires HTTPS); defaultfalseDATABASE_URL- PostgreSQL connection URL (required; bring your own Postgres instance)DB_INIT_RETRY_INTERVAL_MS- Delay between DB init retries in ms (default:5000)DB_INIT_RETRY_MAX_ATTEMPTS- Max DB init retries;0retries forever (default:0)SYNC_MAX_FUTURE_SKEW_MS- Allowed future timestamp skew from clients during sync (default:0)
Authentication
There is a single admin account for the web dashboard (username + password, bcrypt-hashed, session cookie - no accounts beyond the one admin). The first time you open the dashboard you're walked through creating it; there is no default/seeded account.
Sync clients and devices (the mobile app, or anything hitting the /api/lists /
/api/fields / /api/items / /api/sync / /api/notifications endpoints) authenticate
with a separate long-lived API token instead - generate or regenerate it from the
dashboard's Settings page, then set Authorization: Bearer <token> on those requests. This
replaces the old optional SERVER_PASSWORD scheme, which silently disabled auth entirely
when left unset.
Data Persistence
Use your normal PostgreSQL backup/restore procedures (e.g., pg_dump, pg_restore) against
your own Postgres instance - this app does not manage Postgres storage itself.
License
MIT