Skip to main content
This guide walks you through creating a simple offline-first application using the sync package. You’ll learn how to set up a client, create collections, and use reactive primitives.

Prerequisites

  • Go 1.22 or later
  • Basic understanding of Go

Step 1: Create Your Project

Step 2: Define Your Data Type

Create main.go:

Step 3: Create and Configure the Client

Step 4: Start the Client

Step 5: Create a Collection

Step 6: Use the Collection

Step 7: Add Reactivity

Complete Example

Running the Example

If you have a sync server running:
Output:

What Just Happened?

Key points:
  • Changes are immediate locally
  • Sync happens in the background
  • Works offline - mutations queue until connected
  • Reactive - effects run automatically when data changes

Understanding the Parts

Client

The client manages:
  • Connection to sync server
  • Mutation queue (for offline support)
  • Pulling changes from server
  • Online/offline state

Collection

A collection is a reactive set of entities:
  • Type-safe with generics
  • Syncs with server automatically
  • Supports CRUD operations
  • Reactive (triggers effects)

Entity

An entity is a single record:
  • Has a unique ID
  • Reactive Get/Set
  • Can be deleted
  • Tracks existence

Reactive Primitives

  • Signal: A value that notifies when changed
  • Computed: A derived value that auto-updates
  • Effect: A function that runs when dependencies change

Next Steps