# apps/scan_yourself — iOS Face-Scanning Backend

The backend that supports Bigscreen's iOS face-scanning app. Customers scan their face in the iOS app; this service and a handful of AWS Lambda functions preprocess and store the scan; factory staff later trigger toolpath generation in `apps/admin_api` to produce a custom cushion on the CNC.

**Location:** [apps/scan_yourself/](../../apps/scan_yourself).
**Not a yarn workspace** — it's its own package with its own node_modules. See [workspaces.md](../workspaces.md#non-workspace-packages).

## Pipeline

```mermaid
sequenceDiagram
    autonumber
    actor CUST as iOS app
    participant SCAN as apps/scan_yourself
    participant LAM as AWS Lambda
    participant S3 as S3 bucket
    participant ADMIN as apps/admin_api
    participant WT as Worker thread<br/>(Fusion 360)
    participant CNC as CNC machine

    CUST->>SCAN: POST scan<br/>(mesh + metadata)
    SCAN->>LAM: invoke preprocessing<br/>(landmark detect, cleanup)
    LAM->>S3: store processed mesh
    LAM-->>SCAN: summary
    SCAN-->>CUST: 200 accepted

    Note over ADMIN: Later — operator triggers toolpath job in Arda
    ADMIN->>WT: spawn worker (fusion-api auth)
    WT->>LAM: fetch processed mesh
    WT->>WT: generate toolpath via Fusion 360
    WT->>S3: upload toolpath
    WT-->>ADMIN: done

    Note over CNC: Later — CNC machine pulls its next job
    CNC->>ADMIN: GET /cnc/toolpath/:id<br/>(cnc-machine-api auth)
    ADMIN->>S3: fetch toolpath
    ADMIN-->>CNC: toolpath
```

## What Lives Here

The `scan_yourself` folder contains:

- HTTP endpoints that the iOS app calls (upload, status, list of previous scans)
- AWS Lambda handlers (mesh preprocessing, landmark detection, storage orchestration)
- Shared types and utilities used by both the service and lambdas

The heavy lifting — mesh preprocessing, landmark detection — runs in Lambda so the main service isn't blocked on CPU-bound work.

## Auth

The iOS app talks to `apps/scan_yourself` with a bearer key specifically for the scan flow. Once a scan is uploaded, later admin steps use the `admin-api`, `fusion-api`, and `cnc-machine-api` identities on [admin_api.ts](../../apps/admin_api/admin_api.ts) — see [services/admin-api.md](./admin-api.md).

## Tests

Tests live in [tests/scan-yourself/](../../tests/scan-yourself) and cover:

- Auth (`000.AuthTest.ts`)
- Handoff protocol (`001.Handoff.ts`) — the step where a scan transitions from the scan service into the admin-API pipeline.

## Further reading

- Full scan flow end-to-end → [data-flows.md#6-face-scan-submission](../data-flows.md#6-face-scan-submission)
- Factory-side workers that consume the scans → [services/admin-api.md](./admin-api.md)
