Scan an item, find out which Ottawa bin it goes in, and earn points. Backend: FastAPI + Gemini + Supabase. App: Expo (React Native) in mobile/.
- Sign in: email + password or Google (Supabase Auth), with Remember me and Forgot password. Optional profile photo.
- Home: a plant that grows through 4 levels as you earn points, your points and level, items this week, streak, Ottawa rank, the "Up next" pickup, and Discover weekly (a tricky item with bonus points).
- Scan: photo → item, Ottawa bin, prep tips and points. "I recycled it" awards the points; "Not right?" lets you pick the right item. Drop-off items (electronics, batteries, hazardous) show the nearest drop-off site with Google Maps directions.
- Board: this week / all time leaderboard for Ottawa.
- Wrapped: your month as 5 story cards.
- Me: profile, stats, "What you sort", badges, sign out.
The look follows the mockups in mobile/assets/redesign/ (light theme only).
Note: All art in
mobile/assets/(mockups, plant stages, logo, app icons) is AI-generated placeholder art for the hackathon.
- In the Supabase dashboard, open SQL Editor. Paste each file in
supabase/migrations/and click Run, in order:001_init.sql,002_schedule.sql,003_badges.sql,004_leaderboard_items.sql,005_auth.sql. A missing migration shows up as a "Server error: Could not find the table…" message in the app. - Set up login (email + password and Google) and profile photos: follow docs/AUTH_SETUP.md. Keep Allow anonymous sign-ins on:
scripts/dev_token.pyand the smoke test use it. - Note your keys (Project Settings → API Keys): the project URL, the secret (service_role) key for the backend, and the publishable key for the app.
python -m venv venv
venv\Scripts\activate # Mac/Linux: source venv/bin/activate
pip install -r requirements.txt
copy .env.example .env # Mac/Linux: cp .env.example .envFill in .env (GEMINI_API_KEY, SUPABASE_URL, SUPABASE_SERVICE_KEY), then:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Open http://localhost:8000/docs to try every endpoint. For the 🔒 ones, run python -m scripts.dev_token, click Authorize and paste the token.
cd mobile
npm install
copy .env.example .env # Mac/Linux: cp .env.example .env
npx expo start --clearIn mobile/.env, set EXPO_PUBLIC_SUPABASE_URL and EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY (the publishable key, never the secret one), and set EXPO_PUBLIC_API_URL to one of these:
| Where the app runs | EXPO_PUBLIC_API_URL |
|---|---|
Browser on your laptop (press w) |
http://localhost:8000 |
| Your phone, backend on your laptop | the cloudflared URL (below) |
| Your phone, backend on Render | https://sortify-api.onrender.com (your Render URL) |
Expo reads .env only when it starts, so restart with npx expo start --clear after changing it. Then scan the QR code with the Camera app (iPhone) or Expo Go (Android), or press w for the browser (http://localhost:8081).
The app opens on Sign in: tap Create an account, or use Google. Google sign-in and the emailed links (confirm email, reset password) only work once Supabase and Google are set up (step 1.2, docs/AUTH_SETUP.md). On a wide browser window the app shows as a phone-sized column in the middle.
Your phone can't reach localhost on your laptop, so open a tunnel in a second terminal.
cloudflared is a separate program, not a pip package, so install it once:
winget install --id Cloudflare.cloudflared # Windows
brew install cloudflared # macOSThen open a new terminal (so it picks up the new PATH), check with cloudflared --version, and start the tunnel:
cloudflared tunnel --url http://localhost:8000Copy the https://….trycloudflare.com URL it prints into EXPO_PUBLIC_API_URL and restart Expo. The URL changes every time you restart the tunnel.
render.yaml describes the whole service, so Render sets itself up from it.
- Push to GitHub (
main). - On https://dashboard.render.com: New → Blueprint, connect GitHub, pick the Sortify repo, branch
main. - Render shows the
sortify-apiweb service and asks forGEMINI_API_KEY,SUPABASE_URLandSUPABASE_SERVICE_KEY. Paste them from your.envand click Apply (or Deploy Blueprint). - Wait for the deploy to show Live (about 3 to 5 minutes the first time). Your URL is at the top of the service page, e.g.
https://sortify-api.onrender.com. - Check it:
python -m scripts.smoke_test https://sortify-api.onrender.com.
Every push to main redeploys. The free plan sleeps after 15 idle minutes and takes about a minute to wake, so open /health before you need it. To change a key later: service → Environment → edit → Save Changes (it redeploys).
python -m scripts.seed # 20 fake Ottawa players with a month of scans (safe to rerun)
python -m scripts.seed --remove # delete them again
python -m scripts.dev_seed_month <user id> # a month of scans for YOUR account, so Wrapped has a story
python -m scripts.smoke_test <url> # PASS/FAIL for /health and /classify (one real Gemini call)
python -m scripts.smoke_test <url> --photo can.jpgRerunning seed refreshes the fake players' month up to today, so "This week" always has data. It only touches its own seed-NN@example.com logins, never real players.
The plant art originals are mobile/assets/redesign/Stage-N-transparent.png (4 stages, one per level). After changing them, rebuild the smaller copies the app uses and commit those:
python -m scripts.build_plant_assets # writes mobile/assets/plant/stage-1..4.png
python -m scripts.build_icons # app icons + browser-tab icon from the logo's arrowspytest # backend: Gemini and Supabase are faked (tests/fakes.py), so free and offline
cd mobile && npm test # app screens with the API mocked
cd mobile && npm run typecheck
cd mobile && npm run lintapp/
main.py app, CORS, /health; crashes come back as readable 500s
config.py settings from .env (or Render's environment)
schemas.py request/response shapes (the app's contract)
routers/ endpoints
services/ rules (bins), gemini, images, points, levels, stats, schedule, wrapped, discover, badges
db.py the only code that talks to Supabase
deps.py login token -> user id, or 401
data/ categories, drop-off sites, holiday shifts, Discover weekly (JSON)
mobile/ the Expo app (app/ = screens, components/, lib/api.ts = typed API client, theme.ts = colours and fonts)
docs/ AUTH_SETUP (login setup), ACCURACY_LOOP, BUILD_PLAN, mockups
scripts/
seed.py fake players for the demo
smoke_test.py checks a live backend
dev_token.py login token for /docs
dev_seed_month.py a month of scans for one account
eval_classifier.py Gemini accuracy on real photos (tests/eval_images/)
build_plant_assets.py app copies of the plant art (from assets/redesign/Stage-N-transparent.png)
build_icons.py app icons + browser-tab icon (the logo's recycling arrows)
supabase/migrations/ 001 to 005, run in order
render.yaml Render deploy
tests/ pytest
- The app uploads a photo to
POST /classify(plus optionallat/lon). images.pyshrinks it and strips EXIF, so no GPS location leaves the server.gemini.pyasks Gemini to pick one category id fromdata/categories.json(enforced by a JSON schema). Made-up ids becomeunknown; confidence under 0.70 requires user review before confirmation.rules.pylooks up the bin, points and tips for that id. Gemini doesn't decide the bin for listed items. If nothing in the list fits but Gemini can name the item (e.g. a Pokémon card), a second Gemini call with Google Search looks up the Ottawa rule and must answer with one of the 5 bins. The scan is filed under that bin'sother_*category (that bin's usual points), and the app shows "Checked online" with the sources and a link to the City's Waste Explorer. If the search is unsure or unavailable, the person picks the category as before. "Not right?" also has "Something else", which marks it not recyclable.- For drop-off items (batteries, electronics, hazardous), the result screen asks for the phone's location, gets the nearest site that takes that item from
GET /dropoffs/nearest(sites indata/dropoff_sites.json), and its Directions button opens Google Maps. Without location it offers a Google Maps search instead.
| Endpoint | What it does |
|---|---|
GET /health |
{"status": "ok"} |
GET /categories, GET /categories/{id} |
Every category with its bin, points and tips |
GET /dropoffs/nearest?lat=&lon=&accepts= |
Closest drop-off for electronics, batteries or hazardous |
POST /classify 🔒 |
Photo → item, bin, points, tips, scan_id, nearest drop-off |
POST /scans/{id}/confirm 🔒 |
"I recycled it": awards points |
POST /scans/{id}/correct 🔒 |
"Not right?": body {"category_id": "..."} |
GET /scans/me 🔒 |
Your last 50 scans |
GET /stats/accuracy 🔒 |
Aggregate corrections, common mix-ups, and confidence bands (not ground-truth accuracy) |
GET /leaderboard?range=week|all 🔒 |
Top 20 plus your own row |
GET /me, PATCH /me 🔒 |
Profile, level, stats, breakdown, badges; change name |
POST /me/avatar, DELETE /me/avatar 🔒 |
Set a profile photo (cropped, shrunk, location removed) or go back to the default |
GET /schedule/next, PUT /me/schedule 🔒 |
"Up next" pickup; set your pickup day |
GET /wrapped/{year}/{month} 🔒 |
The 5 Wrapped cards |
GET /discover/current 🔒 |
This week's tricky item and bonus |
🔒 needs Authorization: Bearer <Supabase access token>.
- Points come from
data/categories.json(rarer items are worth more), plus a +15 bonus the first time you sort a new kind of item. - Points are only given on confirm, and each scan can be confirmed once.
- A corrected scan is worth at most 10 points, so relabelling junk as a battery doesn't pay.
- The same photo (even resized) never earns points twice, for anyone. We compare perceptual hashes.
- There's a daily cap (
DAILY_POINT_CAP, default 200), counted in Ottawa time. - The plant's level comes from total points (
app/services/levels.py): Sprout 0, Seedling 50, Sapling 100, Young Tree 200. Kept low so the plant visibly grows during a demo. - The confirm-once rule and the cap run inside the
award_pointsdatabase function in one transaction, so two taps at once can't cheat it. Only the backend can call that function.
GET /stats/accuracy helps monitor recorded model/user disagreements, by predicted
category and confidence bracket. Uncorrected scans are not verified correct.
See docs/ACCURACY_LOOP.md for the confidence-review flow,
manual prompt-hint curation, holdout-photo protocol, and metric caveats.
Put real photos in tests/eval_images/<category_id>/ and run python -m scripts.eval_classifier (uses your real Gemini key). Entries in data/*.json with "verify": true still need checking against ottawa.ca.