Selva Reorderly · architecture brief · 20 Aug 2026

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.

Recommendation: deepen the existing D1/Reorderly foundation, keep n8n as the edge connector and scheduler, and replace the current snapshot blob with canonical facts plus projections before attempting Grist sunset.
D1 statusConfigured, not provenThe hosted app has symbolic DB and RAW_ARCHIVE bindings. The actual production database, applied migrations, and row counts still need an owner-authorized read check.
Current dataSnapshot cacheDocs claim 258 reorder rows, 258 inventory rows, 1,453 customers, and 9,625 sales rows. That is not yet a complete relational Grist migration.
HostingGood for previewThe private ChatGPT-hosted site is suitable for the current preview. Do not make the final system dependent on an unverified preview hostname.

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 platformSelva moduleDerwent 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.
Implementation boundary: create a versioned @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.

LayerRequired D1 responsibilityWhy it matters
Identityorganizations, memberships, source connections, countries/locations.Tenant isolation and correct SG/MY/TH source boundaries.
Evidenceingestion_runs, source_artifacts, source_records, entity-source links.Replay, audit, freshness, and proof that a sync was complete.
Canonical factsProducts 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.
PlanningDemand snapshots, planning policies, replenishment runs/lines, policy version, input checksums, explanations.Makes 3M/6M decisions reproducible and reviewable.
WorkflowNotification rules, notifications, order decisions, completion events, notes, audit history, DQ issues.Replaces the editable Grist operational controls.
ProjectionsCustomer monthly sales, customer-product prices, inventory runway, reorder queue, DQ summary.Keeps dashboard reads fast without making projections the source of truth.

Connector decision

Keep n8n for now. It is already the practical home for OAuth credentials, source schedules, form triggers, pagination, raw archival, email notifications, and failure routing. Reorderly should receive a versioned connector envelope and own what happens after ingestion: validation, canonical mapping, reconciliation, DQ, projections, and workflow state.
Do not replace n8n with a generic commerce integrator. Orderly-style bridge products target commerce and fulfillment platforms, not Selva’s Xero, Zoho, Grist, and Track-POD accounting model. They would add another order store without removing the custom adapter work.
Use a common integrator later only if the need appears. A dedicated connector service becomes worthwhile when Selva needs queue semantics, webhook replay, multiple downstream consumers, or stronger transaction governance. Migrate one source in shadow mode first and preserve the stable line key: source | account_id | invoice_number | source_line_id.

Build and sunset sequence

0

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.
1

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.
2

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.
3

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.
4

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.
5

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

  1. Capture the real hosted D1 state and create a repeatable migration/status command.
  2. Define the first canonical schema migration: source connections, runs, artifacts, products, identifiers, customers, sales lines, inventory snapshots, supply events, and DQ issues.
  3. Build a Grist-to-canonical importer with bounded batches, stable source identities, checksums, and reconciliation output.
  4. Change the dashboard read path from the snapshot blob to projections, while retaining the blob only as a temporary cache.
  5. Connect n8n to the ingest envelope and stop treating “workflow executed” as equivalent to “data is complete”.
  6. Extract the shared contracts and pure planning package, then make Derwent consume them behind its own storage adapter.