# Sync Architecture

Server is the source of truth.

## Online sync

- Backend records every important business event in `sync_events`.
- Socket.IO broadcasts event types like `ticket.assigned`, `ticket.completed`, `payment.received`, `stock.updated`.
- Web and Android subscribe to the same event stream.

## Offline sync

- Android stores offline actions in local queue.
- App sends actions to `/api/sync/push` when internet returns.
- Server writes audit and sync events.
- Client calls `/api/sync/pull?since=<sequence>` for missing events.

## Conflict rule

- Financial posting is not silently overwritten.
- Ticket notes and photos are append-only.
- Stock changes become movements, not direct destructive overwrites.
- Every sync action keeps actor user ID, client action ID, created time and server sequence.
