Skip to content

Architecture [Needs Review]: Sortable ULID identifiers & multi-device hierarchy (main/core/ids.ts) #286

Not planned

Description

@khaira777

Important

Status: Needs Architectural Review
This issue outlines a proposed core architectural change. It requires technical review and approval before deciding whether to implement or adopt.

Extracted from fork richanonymous22/FloCafe (branch: claude/plemmo-epos-audit-fro8v9):

Overview

Replace auto-increment integers and random UUID v4 strings with Universally Unique Lexicographically Sortable Identifiers (ULID) and establish a formal multi-terminal device model (Organization -> Location -> Register -> Device).

Key Features & Technical Details

  1. ULID Identifiers:
    • Crockford Base32 128-bit ULIDs combining 48-bit UNIX timestamps with 80 bits of random data (01ARZ3NDEKTSV4RRFFQ69G5FAV).
    • Time-ordered to preserve SQLite B-Tree index performance as databases grow.
  2. Entity Type Prefixes:
    • Explicit prefixes for entity clarity (ord_, prd_, usr_, tx_, org_, loc_, reg_, dev_).
  3. Collision-Free Multi-Terminal Support:
    • Allows multiple offline terminals/registers to generate IDs independently without collision.
  4. Reference Implementation:
    • main/core/ids.ts & tests/plemmo-identifiers.test.ts.

Acceptance criteria

  • main/core/ids.ts ULID generation with entity type prefixes.
  • Multi-terminal Organization → Location → Register → Device hierarchy.
  • Collision-free offline ID generation + tests.

Activity

  1. khaira777 commented on Aug 16, 2026

    @khaira777
    ContributorAuthor

    Verdict: NOT APPLICABLE TO FLOCAFE as proposed — needs maintainer decision only if offline multi-terminal sync becomes a goal

    Findings:

    • IDs are mixed today (INTEGER AUTOINCREMENT for orders main/db.ts:4156, print_logs :2306; TEXT ids for held_orders/users/tables/customers). A ULID migration would touch every table, route, and fixture — a massive refactor with no stated problem in FloCafe.
    • The Organization → Location → Register → Device hierarchy conflicts with the architecture: FloCafe is a single local install. Companion devices pair via mDNS flo.local (main/index.ts startMdns), KDS pairing tokens, and FloAdmin store registration (ensureCloudIdentity, setCachedPairingCode in main/db.ts:635-665). Order numbers come from sequences (timezone-aware, feat: configure invoice numbering #297), giving sortable, human-readable IDs already.

    No code change is warranted without a product goal (e.g., true multi-terminal offline sync) — the issue should be closed or held as an architectural note, not backlog work.

  2. added
    question
    area:backend
    on Aug 16, 2026
  3. itsbkm commented on Sep 1, 2026

    @itsbkm
    Contributor

    Maintainer decision: not applicable to FloCafe's architecture

    FloCafe's supported multi-terminal model is centralized:

    POS terminals / waiter devices / KDS / kiosks
                        ↓ LAN HTTP/WebSocket
              One authoritative local FloCafe server
                        ↓
                  One SQLite database
    

    Terminals are clients of the local server. They do not maintain independently writable transaction databases and do not later merge sales. Consequently, the collision scenario this proposal is designed to solve does not exist within the supported architecture.

    Decision

    • Keep SQLite integer primary keys for local transactional tables.
    • Keep human-facing order and invoice numbers separate from internal database identity.
    • Do not introduce ULIDs, distributed transaction IDs, or the proposed Organization → Location → Register → Device hierarchy.
    • Do not adopt the referenced fork implementation. In addition to being unnecessary, its migration numbers 68–70 now conflict with migrations already present in the repository, and its plain 26-character ULIDs do not match this issue's prefixed-ID acceptance criterion.

    A lightweight local terminal/counter identity may be introduced later if an approved feature needs workstation attribution, counter-specific printers/cash drawers, or the create-at-one-counter/pay-at-another workflow. That is a local configuration concern, not database synchronization.

    Relevant improvements under the centralized model

    These should be evaluated independently rather than used to justify distributed identifiers:

    1. Server availability: launch-at-login/start-at-boot support, dedicated-server deployment guidance, UPS/wired-LAN recommendations, and clear terminal connection-loss recovery.
    2. LAN security: the current HTTP/WS trusted-LAN boundary should be documented explicitly or optional HTTPS/WSS should be designed.
    3. Multi-client correctness: add focused concurrent-client tests for duplicate payment, simultaneous order edits, table selection, split checks, cancellation/payment races, and last-stock sales.
    4. Terminal attribution and peripheral routing: add only when product workflows require knowing which counter created/paid an order or which printer/cash drawer belongs to it.
    5. Cross-terminal freshness: retain backend-authoritative validation and improve typed real-time updates/conflict refresh where polling can temporarily display stale state.
    6. Data protection: unattended rotating local/NAS backups, backup-age warnings, and restore verification alongside the optional Google Drive backup.
    7. Continue the existing security-hardening work tracked in Security: Move JWT secret to Electron safeStorage, restrict IPC maintenance, & sandbox renderer #277.

    Architectural invariant going forward:

    A FloCafe location has exactly one authoritative local server and database. POS terminals, KDS displays, waiter devices, kiosks, and customer displays are clients of that server and do not maintain independently writable transaction databases.

    Closing as not planned. If independently writable offline terminals ever become an approved product requirement, synchronization semantics and conflict resolution must be designed first; identifier selection would follow that design.

  4. reopened this on Sep 1, 2026
  5. itsbkm commented on Sep 1, 2026

    @itsbkm
    Contributor

    Reopening at maintainer request.

    The ULID and multi-database synchronization proposal is still not approved: FloCafe retains one authoritative local server and database. This issue will remain open temporarily while the centralized multi-terminal gaps identified above are reviewed and either:

    • explicitly accepted as deployment constraints, or
    • moved into focused implementation issues for server availability, LAN transport security, concurrent-client coverage, terminal/counter attribution, real-time freshness, peripheral routing, and unattended backups.

    No implementation of main/core/ids.ts, ULID migrations, or the proposed organization hierarchy should begin from this issue without a separate architectural decision.

  6. khaira777 commented on Nov 28, 2026

    @khaira777
    ContributorAuthor

    Closing as not_planned per the earlier maintainer decision rejecting ULID migrations and distributed multi-database sync. FloCafe retains one authoritative local SQLite server with integer transactional primary keys. Most of the centralized multi-terminal improvements noted when this issue was temporarily reopened have since shipped on main: automatic in-process LAN HTTPS (#1624), counter entities (#1411, main/routes/counters.ts), per-station local WebUSB printing (#1616), unattended local backups (main/routes/database-tools.ts), and #277 security hardening. Any remaining operational docs (launch-at-login or UPS guidance) should be tracked as small focused tasks rather than under a rejected ULID proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendquestion

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions