# ShelfScout

Phone-first book identification and buyback lookup app. It runs as a static, installable web app; no build step or paid hosting is required. Supabase and Gemini free-tier accounts are needed for cloud sync and photo identification. Manual ISBN entry, browser-local saving, copy, and CSV export work without those services.

## Start the app

For local use, run `python3 -m http.server 8000` in this folder, then open `http://localhost:8000`. Browser camera/file access and the service worker work best when served over HTTPS (or localhost). To host at no cost, publish the folder as a static site on a free personal-project host such as GitHub Pages. The app uses Supabase JS from a pinned ESM CDN URL, so an internet connection is required.

## Set up Supabase

1. Create a Supabase project on the Free plan.
2. In **SQL Editor**, run all of [`supabase/schema.sql`](supabase/schema.sql). This creates the inventory and quote tables with owner-only row-level security.
3. In **Authentication → Providers**, enable Email. For email confirmation, verify your address before signing in.
4. The project URL and publishable key for this ShelfScout project are preconfigured in `supabase-config.js`. The app Settings form can override them if needed. Never put a secret or service-role key in the browser.
5. In **Edge Functions**, deploy the two functions from `supabase/functions/identify-books/index.ts` and `supabase/functions/lookup-offers/index.ts` using the Dashboard editor or the Supabase CLI. The Dashboard editor is under **Edge Functions → Deploy a new function → Via Editor**; paste each function file into its matching function and deploy. Add secrets under **Edge Function Secrets**:
   - `GEMINI_API_KEY`: create a Gemini API key in Google AI Studio. Use a project with billing disabled to keep requests within the free tier; if the free quota is exhausted, photo identification pauses until it resets.
   - `BOOKSRUN_API_KEY` (optional): only add this if BooksRun gives you an API key at no charge. If absent, direct quote lookup remains disabled and ISBN exports/vendor links still work.
6. Refresh ShelfScout, create an account, and sign in. Existing browser-local books are copied into your cloud inventory on first sync.

### Optional: enable Google sign-in

The sign-in window already includes **Continue with Google**. To activate it, create a **Web application** OAuth client in Google Cloud, add your app origin (for local use, `http://localhost:8000`) as an authorized JavaScript origin, and add the callback URL shown on Supabase's Google provider setup page as an authorized redirect URI. Then enter the Google client ID and secret in **Supabase → Authentication → Providers → Google**. In Supabase **Authentication → URL Configuration**, allow the app URL you use (local and deployed) as a redirect URL. The app will send users back to the same page after Google sign-in.

The Supabase Free plan has storage and request quotas and may pause after inactivity. Gemini’s free tier may use submitted content to improve Google products. Photos are resized in the browser and sent to Gemini through the Edge Function; ShelfScout does not save them in the inventory. Do not enable paid billing if you need a strict $0 ceiling.

## Use it

- Upload up to five photos per batch. A photo can show a shelf, pile, or a single cover. Keep spine text readable; add a close-up photo when a title is unclear.
- When your list has books, each photo batch asks whether to replace it (the default) or keep it and add the new matches. Replacing clears the saved books and their quote history only after at least one book is identified; if the whole batch fails, your previous list is restored.
- HEIC/HEIF phone photos are converted to JPEG in your browser before identification. The converter is loaded on demand; the original photo is not sent to the converter service.
- Review every match. ISBN editions are searched in Google Books and Open Library, with the top catalog match prefilled for review; you can choose another edition or type one manually. Saved books without ISBNs have a Find ISBN action. Invalid ISBN check digits are rejected.
- Confirmed ISBNs can be copied as a newline-separated list or exported to CSV. The CSV includes buyer links; the app does not automate checkout or scrape sites that do not provide a supported free integration.
- BooksRun quotes are optional and only appear after a user-provided, no-cost API key is configured. The displayed values are buyback quotes, not guaranteed final payments.

## Free-tier design

No paid plan or billing fallback is enabled by this project. Google AI free-tier and Supabase quotas are controlled by their providers and can change. For a hard no-spend setup, keep billing disabled in Google Cloud, do not add paid vendor keys, and use manual ISBN entry/export when a free quota is unavailable.
