Sunset Grist by making Reorderly the operational system.
The clean build is a shared Reorderly platform with Selva-specific source adapters and production/material planning. Grist stays read-only during migration, then becomes an archive.
DB and RAW_ARCHIVE bindings. The actual production database, applied migrations, and row counts still need an owner-authorized read check.Target operating flow
Source systems remain the places where accounting and warehouse data originate. Reorderly becomes the durable interpretation, planning, audit, and staff-workflow layer.
Source systems
Xero SG
Zoho MY / TH / PH
Warehouse files
Track-POD
n8n edge layer
OAuth, schedules, pagination, form intake, raw archive upload, retries, error routing.
Reorderly ingest core
Validated envelopes, stable identities, normalization, reconciliation, DQ gates, replay ledger.
Storage and projections
R2 immutable evidence. D1 canonical facts, workflow records, policies, and materialized read models.
Reorderly UI
Overview, reorder queue, inventory, customers, sales, notifications, data quality.
Migration bridge
Grist is read through a bounded adapter, imported into canonical D1, reconciled, and then frozen read-only.
Action boundary
Reorderly owns staff actions and notification state. Source writes remain behind explicit connector workflows until each one is safely migrated.
What should be shared with Derwent
Share business semantics and small UI primitives, not Selva’s current screen-shaped snapshot or Derwent’s current database driver.
| Shared platform | Selva module | Derwent module |
|---|---|---|
| Organization and tenancy, source connections, ingestion runs, raw-artifact lineage, source links, data-quality issues. | Zoho/Xero country mapping, Grist migration, material and finished-product relationships. | MYOB source mapping, supplier purchasing, acknowledgement and receipt lifecycle. |
| Products, product identifiers, locations/countries, inventory positions, supply events, demand snapshots, planning policies. | 3M/6M burn, cartons/kg, shared SG & MY market group, spoilage and cold-chain status. | MOQ, order multiples, supplier lead times, committed stock and purchase baskets. |
| Zod contracts, pure planning engine, source-health state, status pills, table chrome, empty states, coverage/reorder cells. | Read-only multi-country/material planning UI. | Editable distributor purchasing UI. |
@reorderly/core package for canonical contracts and pure planning semantics. Keep D1, R2, and local persistence behind repository ports. Add distribution and production capabilities rather than creating separate client forks.D1 target shape
The current five-table bootstrap is useful scaffolding, but it cannot support a safe Grist sunset by itself.
| Layer | Required D1 responsibility | Why it matters |
|---|---|---|
| Identity | organizations, memberships, source connections, countries/locations. | Tenant isolation and correct SG/MY/TH source boundaries. |
| Evidence | ingestion_runs, source_artifacts, source_records, entity-source links. | Replay, audit, freshness, and proof that a sync was complete. |
| Canonical facts | Products and identifiers, customers, sales documents/lines, inventory snapshots, supply events, product components, suppliers. | Replaces Grist’s mixed raw/helper/formula tables without copying its accidental schema. |
| Planning | Demand snapshots, planning policies, replenishment runs/lines, policy version, input checksums, explanations. | Makes 3M/6M decisions reproducible and reviewable. |
| Workflow | Notification rules, notifications, order decisions, completion events, notes, audit history, DQ issues. | Replaces the editable Grist operational controls. |
| Projections | Customer monthly sales, customer-product prices, inventory runway, reorder queue, DQ summary. | Keeps dashboard reads fast without making projections the source of truth. |
Connector decision
source | account_id | invoice_number | source_line_id.Build and sunset sequence
Prove the hosted foundation
Read-only check of Sites bindings, actual D1 ID, applied migrations, schema, row counts, snapshot timestamp, R2 objects, and private access.
- Exit: database and environment are evidenced, not just documented.
Stabilise source ingestion
Fix the Grist 429/backlog path, separate post-write SKU resolution from the daily success signal, and add exponential backoff plus a durable ingest-run ledger.
- Exit: recent Xero/Zoho runs are complete, replayable, and independently auditable.
Build canonical D1
Add relational facts and references. Store raw evidence in immutable R2. Keep the compressed snapshot only as a temporary compatibility cache.
- Exit: every dashboard field can trace to facts, source records, and a calculation policy.
Run parallel reconciliation
Import all required Grist history, run live connectors, and compare counts, sums, quantities, customers, SKUs, countries, currencies, stock, adjustments, and DQ states.
- Exit: all differences are explained, accepted, or fixed.
Move staff workflows
Enable Reorderly’s reorder decisions, notification rules, completion actions, customer views, and data-quality queue. Keep source writes controlled.
- Exit: Selva staff complete a real operating cycle in Reorderly.
Freeze and sunset Grist
Freeze Grist edits, take a final export and backup, switch Reorderly to canonical D1, monitor freshness and reconciliation, then retain Grist as read-only archive.
- Exit: no operational dependency remains on Grist.
Immediate build slice
- Capture the real hosted D1 state and create a repeatable migration/status command.
- Define the first canonical schema migration: source connections, runs, artifacts, products, identifiers, customers, sales lines, inventory snapshots, supply events, and DQ issues.
- Build a Grist-to-canonical importer with bounded batches, stable source identities, checksums, and reconciliation output.
- Change the dashboard read path from the snapshot blob to projections, while retaining the blob only as a temporary cache.
- Connect n8n to the ingest envelope and stop treating “workflow executed” as equivalent to “data is complete”.
- Extract the shared contracts and pure planning package, then make Derwent consume them behind its own storage adapter.