# Plan 004: Point mobile at `@dudata/shared` and delete domain fork

> **Drift check**:
> `git diff --stat 74051ba..HEAD -- apps/mobile/src/lib/domain.ts apps/mobile/src/features/delivery packages/shared/src/domain.ts apps/mobile/package.json`

## Status

- **Priority**: P1
- **Effort**: L
- **Risk**: MED
- **Depends on**: none (parallel to 001)
- **Category**: tech-debt
- **Planned at**: commit `74051ba`, 2026-07-09

## Why this matters

Mobile ships a **fork** of domain (`apps/mobile/src/lib/domain.ts`) that self-
describes as a simplified prototype port. Web and backend use `@dudata/shared`.
Documented drift includes pipeline order, `manualMoveTargets`, `pipelineStages`,
status labels, `fmtIso` timezone, capacity filter, missing
`firstPublishedAt`/`lastPublishedAt`. Parallel machine in
`delivery-workflow.ts` diverges from shared `deliveryActions`.

## Current state

- Mobile package.json: no `@dudata/shared` dependency.
- ~30 files import `@/lib/domain`.
- Web pattern to copy: `apps/web/src/lib/domain.ts` re-exports shared.
- Workflow reimplementation: `apps/mobile/src/features/delivery/delivery-workflow.ts`.
- Dead demo seed: `apps/mobile/src/lib/mock-data.ts` (unimported) — delete in same effort if still unused.

## Commands

| Purpose | Command | Expected |
|---------|---------|----------|
| Mobile tests | `cd apps/mobile && bun run test` | pass |
| Mobile read-models | include in default vitest (TEST-03) | pass |
| Typecheck mobile | package typecheck if present | exit 0 |

## Steps

### 1. Depend on shared

Add `"@dudata/shared": "workspace:*"` to `apps/mobile/package.json`. `bun install`.

### 2. Re-export / thin adapter

Replace `apps/mobile/src/lib/domain.ts` with re-export of shared + **only**
RN presentation adapters (badge token names, icon maps). Rename types if needed
(`Member` vs `User`) via type aliases — do not fork logic.

### 3. Drive workflow from shared

Map `delivery-workflow.ts` onto `deliveryActions` / `nextStatusFor` /
`manualMoveTargets` / `canRequestRework` / `canApprove`. Keep UI labels/variants
in the app layer.

### 4. Fix tests and fixtures

Update mobile domain tests to assert shared behavior (or move pure tests to
shared and keep mobile adapter tests thin). Ensure timezone-sensitive UI uses
shared `fmtIso` (America/Sao_Paulo).

### 5. Delete dead code

Remove `mock-data.ts` if still unreferenced. Grep for old helpers.

## Out of scope

- Full visual redesign of mobile pipeline
- Server authz (001)
- Splitting shared god-file (DEBT-05) — optional follow-up

## STOP conditions

- If Expo/metro cannot resolve workspace package — stop and fix bundler config
  rather than vendoring a copy.
- If a mobile-only product rule intentionally differs from web — document in
  CONTEXT.md / ADR before keeping a fork of that single function.

## Done criteria

- [ ] No duplicate state machine logic in mobile.
- [ ] `@dudata/shared` is the dependency; mobile domain file is re-export/adapter.
- [ ] Mobile vitest green; delivery workflow tests still pass with shared rules.
- [ ] Labels for shared statuses match product (or intentional adapter map only).

## Maintenance

Domain changes land in shared first; mobile only updates presentation adapters.
