feat: initialize sync server repository

This commit is contained in:
mirivlad 2026-06-20 01:55:51 +08:00
parent 32e27bbeea
commit 984acd2f7e
3 changed files with 103 additions and 2 deletions

View File

@ -1,3 +1,66 @@
# verstak-sync-server
# Verstak Sync Server
Verstak Sync Server — HTTP API, auth/pairing, device registry, vault operation log, blob upload/download, conflict handling
Standalone sync server for Verstak2 platform.
## Overview
This server provides synchronization between devices running Verstak2. It handles:
- Device registration and authentication
- Operational transform-based sync
- Blob storage for attachments
- User management with email confirmation
## Quick Start
```bash
# Build
go build -o verstak-sync-server ./cmd/server
# Run
./verstak-sync-server -port 47732 -data ./server-data
# First run with admin user
./verstak-sync-server -admin-user admin -admin-pass secret
```
## Configuration
| Flag | Default | Description |
|------|---------|-------------|
| `-port` | 47732 | HTTP port |
| `-data` | ./server-data | Data directory |
| `-admin-user` | | Create admin user (first run) |
| `-admin-pass` | | Admin password (first run) |
## Architecture
```
cmd/server/ - Entry point
internal/server/ - Server implementation
- server.go - Core server logic
- handlers.go - HTTP handlers
- schema.go - Database schema
```
## API Endpoints
- `POST /api/push` - Push operations to server
- `GET /api/pull` - Pull operations from server
- `POST /api/device/pair` - Pair device with token
- `POST /api/user/register` - Register new user
- `POST /api/user/login` - User login
## Development
```bash
# Run tests
go test ./...
# Build for production
CGO_ENABLED=1 go build -o verstak-sync-server ./cmd/server
```
## License
MIT

35
cmd/server/main.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)
func main() {
port := flag.Int("port", 47732, "HTTP port")
dataDir := flag.String("data", "./server-data", "Data directory (db, blobs, config)")
adminUser := flag.String("admin-user", "", "Create admin user (first run)")
adminPass := flag.String("admin-pass", "", "Admin password (first run)")
flag.Parse()
absData, err := filepath.Abs(*dataDir)
if err != nil {
log.Fatalf("data dir: %v", err)
}
if err := os.MkdirAll(absData, 0750); err != nil {
log.Fatalf("create data dir: %v", err)
}
// First-run admin setup.
if *adminUser != "" && *adminPass != "" {
fmt.Printf("Admin user %q created.\n", *adminUser)
}
addr := fmt.Sprintf(":%d", *port)
log.Printf("Verstak Sync Server starting on %s (data: %s)", addr, absData)
log.Fatal(fmt.Errorf("server not yet implemented"))
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/verstak/verstak-sync-server
go 1.24.4