# Pulse — AI Food Calorie Scanner

> Track your food. Know your body.

A React Native (Expo) app that photographs a meal, sends it to Claude's vision
API, and returns per-food calorie and macro estimates you can correct and log.

## Run it

```bash
npm install
npx expo start
```

Open the QR code with **Expo Go** on your phone, or press `a` / `i` for an
emulator. The camera needs a real device.

## Enable real AI analysis

Open **Profile → AI engine** and paste an Anthropic API key (`sk-ant-...`).
Without a key the app runs in **demo mode** with sample results so you can walk
the whole flow.

The key is stored in this device's AsyncStorage and is sent only to
`api.anthropic.com`. For a production release, proxy the call through your own
backend instead of shipping user-held keys.

## How the AI call works

`src/ai.js` posts to the Anthropic Messages API over `fetch` (the Node SDK is
not React Native friendly):

- **Model:** `claude-opus-5` — $5 / MTok input, $25 / MTok output.
- **Vision:** the photo goes in as a base64 `image` content block.
- **Structured outputs:** `output_config.format` pins the response to a JSON
  schema with per-food name, grams, portion text, calories (plus a low/high
  range), protein, carbs, fat, fiber, and a confidence score.
- **Clarifying questions:** when a detail materially changes the numbers
  (grilled vs fried, portion size), the model returns a question with options.
  Answering it re-runs the analysis with that hint.
- `effort: 'medium'` and `max_tokens: 8000` leave room for thinking tokens,
  which are on by default on Opus 5.

## Screens

| Route | What it does |
|---|---|
| `app/(tabs)/index.js` | Home — daily ring, macro bars, big **SCAN FOOD** button |
| `app/(tabs)/scan.js` | Scan launcher — camera / gallery + how it works |
| `app/(tabs)/history.js` | History grouped by day, then by Breakfast / Lunch / Dinner / Snack |
| `app/(tabs)/progress.js` | 7-day calorie bars, averages, streak, today vs goal |
| `app/(tabs)/profile.js` | Goals, API key, data controls |
| `app/camera.js` | Full-screen scan UI with framing corners, flash, camera flip |
| `app/analyze.js` | AI scan animation → staged results → edit → pick meal → save |
| `app/entry/[id].js` | Reopen a logged meal, edit its foods, move it to another meal |

## Editing

Tap any food card to open the edit sheet: rename it, change the weight (macros
rescale proportionally), override any individual number, or remove it. You can
also add foods manually. Edited items are marked as manual and drop their AI
confidence badge.

## Accuracy

Every number is a visual estimate. The UI shows a confidence percentage per
food, a calorie range where the model is unsure, and makes manual correction one
tap away. Pulse is a wellness tracker, not a medical device.

## Data

Meals, goals, and the API key live in AsyncStorage on the device only. There is
no account and no server. **Profile → Clear all history** wipes the log.
