Scan a tag. See the true cost. Give the garment another life.
Rethread is a Next.js app that turns a single photo of a clothing label into a complete environmental footprint and a concrete set of next steps: one repair option, one resale option, one donation route — all within walking distance.
- Scan — user snaps a photo of a care label.
- Reason — Gemini computes the garment's fiber-to-landfill footprint from the extracted data.
- Route — the app returns the three nearest places to repair, resell, or donate it.
Three screens. One photo. One decision.
| Layer | Choice |
|---|---|
| Framework | Next.js 15 (App Router, Server Actions) |
| Runtime / package manager | Bun |
| Styling | Tailwind CSS v4 |
| UI | React 19 |
| AI / APIs | Google Cloud Vision, Document AI, Gemini, Maps, Places, BigQuery |
| Hosting | Vercel (edge) + GCP (service account for Google APIs) |
┌─────────────┐ ┌──────────────────────┐ ┌─────────────┐
│ Client │──────▶│ Next.js Server │──────▶│ Google AI │
│ (camera) │◀──────│ Actions / Route │◀──────│ + Maps │
└─────────────┘ │ Handlers │ └─────────────┘
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ BigQuery (brand │
│ sustainability DB) │
└──────────────────────┘
Everything Google-facing runs server-side through a single shared service-account client. The browser never holds a key.
photo ──▶ [1. ingest] ──▶ [2. cost] ──▶ [3. route] ──▶ result
- Cloud Vision API → OCRs the care label. Extracts fiber composition, country of manufacture, care symbols.
- Document AI (optional branch) → if the user uploads a receipt instead of a tag, extracts brand, item name, price, quantity using a custom parser.
- Output: a normalized
Garmentobject:{ fibers, origin, category, brand?, price? }.
- Gemini 2.5 receives the
Garmentobject plus a short system prompt with industry benchmarks (liters/kg for cotton, kg CO₂e for polyester, etc.). - BigQuery is queried in parallel for a brand-level sustainability row (sourced from Good On You + Fashion Transparency Index). If a row exists, it's injected into the Gemini prompt as grounding context.
- Gemini returns structured JSON (enforced via
responseSchema):{ water_liters: number, co2_kg: number, dye_pollution_score: 1..10, confidence: 'high' | 'medium' | 'low', reasoning: string }
- Maps API (Geocoding + Distance Matrix) → user's location → nearest candidates for three categories:
repair(tailors, cobblers, menders)resale(consignment, thrift buyers)donation(shelters, textile recyclers)
- Places API → enriches each with hours, rating, photo, and a quick "accepts this item?" heuristic from place-type + Gemini's category.
- Exactly one result per category is returned. No endless list.
app/scan/page.tsx ← camera + upload UI
│
▼
app/actions/scan.ts ← server action: runs the pipeline
│
├─▶ lib/google/vision.ts (ingest)
├─▶ lib/google/docai.ts (ingest – receipt branch)
├─▶ lib/google/gemini.ts (cost)
├─▶ lib/google/bigquery.ts (cost – grounding)
└─▶ lib/google/places.ts (route)
│
▼
app/result/[id]/page.tsx ← renders footprint + 3 routes
One server action owns the whole pipeline. No client-side API calls. No intermediate endpoints to maintain.
rethread/
├── app/
│ ├── page.tsx # Landing
│ ├── scan/page.tsx # Camera + upload
│ ├── result/[id]/page.tsx # Footprint + 3 routes
│ └── actions/
│ └── scan.ts # Server action — full pipeline
├── lib/
│ └── google/
│ ├── client.ts # Shared auth
│ ├── vision.ts
│ ├── docai.ts
│ ├── gemini.ts
│ ├── bigquery.ts
│ └── places.ts
├── components/ # UI primitives
├── types/garment.ts # Shared types
└── public/
GOOGLE_APPLICATION_CREDENTIALS_FILE= # absolute path to local service-account json
GOOGLE_CLOUD_PROJECT=rethread-tag-ingestion
GOOGLE_APPLICATION_CREDENTIALS_JSON= # optional inline service account json
GEMINI_API_KEY=
GOOGLE_MAPS_API_KEY=
DOCAI_PROCESSOR_ID=
BIGQUERY_DATASET=rethread-tag-ingestion.brand_ratingsbun install
bun devOpens on http://localhost:3000.
- One photo, one answer. No sign-in, no wizards, no multi-step forms.
- Server does the thinking. All Google calls run in a single server action — the client only holds a camera and a result.
- Structured AI output only. Gemini must return schema-validated JSON; anything else is an error.
- Three options, not thirty. The value is the decision, not the search.