///Execution

Implementation plan — 18 tasks, test-first, reviewed

Each task below is fully specified in the working plan: the failing test to write first, the code that makes it pass, the exact commands, and the commit. The full 11,000-line document is available at the bottom. Before it was accepted, an adversarial review pass checked every task against every other — it found 15 defects (interface drift, a broken deploy step, missing test coverage) which were fixed and re-verified.

/// Foundation — Tasks 1–3

A running skeleton with database, logging, and secrets before any product code.

Task 1

Repo scaffold

Next.js 14 + TypeScript strict + Tailwind + vitest, hand-configured. Deliberate break from the checkout site: secrets are never baked into build artifacts.

Task 2

Database schema

Postgres via Prisma: 9 synced mirror tables (orders, line items, cases, invoices, payments…) + portal-native tables (users, sessions, service requests, sync state, audit log). Local dev database in Docker.

Task 3

Runtime foundation

Structured logging, database client, and getSecret() — environment first, AWS Secrets Manager fallback, so credentials rotate without redeploys.

/// Salesforce boundary — Tasks 4–6

The security core: what may cross from Salesforce to AWS is defined in code and enforced by tests.

Task 4

Field allowlist + injection-safe queries

Per-object allowlists of the exact Salesforce fields the portal may read, a denylist of every vendor/margin/card field, and a leak test asserting they never intersect — including object-level exclusions. All queries built through an escaping template; no string concatenation.

Task 5

Salesforce client

OAuth client-credentials auth (separate connected app from checkout), REST query/create with paging, and a full mock mode so the entire suite runs without touching Salesforce.

Task 6

Status translation

Raw internal picklists ("Vendor Queue", "Ready for Procurement") map to customer-safe statuses in one tested module. Internals can never render.

/// Sync engine — Tasks 7–9

Salesforce data lands in the portal database within 2 minutes of changing.

Task 7

Row mappers

One tested mapper per object turning Salesforce records into portal rows — including the subtlety that "Additional Tonnage" line items are charges, not phantom dumpsters.

Task 8

Incremental sync

Polls each object for changes since its high-water mark, upserts in batches, survives one object failing without blocking the rest, and locks against overlapping runs. Runs as a Lambda every 2 minutes.

Task 9

History backfill

Resumable batched seed of the existing 250k orders / 1M line items, built on the same engine.

/// Sign-in — Tasks 10–11

The part the old portal failed hardest at, rebuilt without passwords.

Task 10

Magic links

Email in, single-use link out — only for addresses that exist as contacts on customer accounts. Rate-limited, tokens hashed at rest, 15-minute expiry, no account enumeration.

Task 11

Sessions + login screens

30-day rolling sessions, account picker when one email serves several companies, security headers, audit log of every login.

/// The product — Tasks 12–16

Every query scoped to the signed-in account — enforced in one place, tested with cross-account negatives.

Task 12

Orders & dashboard data

Sites grouped by store name/number (how national accounts actually think), unit lifecycles, open balances, activity feed.

Task 13

Portal shell + order screens

Navigation, account switcher, data-freshness banner, dashboard, sites list, order detail with delivery timeline.

Task 14

Billing

Payment history, open invoices from the NetSuite-synced records, cards on file (display only).

Task 15

Support tickets

The account's real cases, with the ~130k/yr of internal automation noise filtered out.

Task 16

Service requests

The one write path: request → saved on our side → pushed to Salesforce as a case with retry and backoff → confirmation email → status visible in the portal. A request can never be silently lost.

/// Ship — Tasks 17–18

Prove it end-to-end, then the exact AWS runbook.

Task 17

End-to-end suite

Seeded browser tests: sign in, read the dashboard, open an order, submit a request, and — critically — verify another company's order URL returns 404.

Task 18

Deploy artifacts + runbook

Amplify build config, Lambda bundling, and a step-by-step AWS + Salesforce-admin runbook: RDS, Secrets Manager, EventBridge schedules, SES, DNS, alarms, backfill procedure.

Read the full plan

The complete task-by-task document with all test code, implementation code, and commands (11,063 lines, markdown):

Download implementation-plan.md