Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ vite.config.ts.timestamp-*

# Turborepo
.turbo

# Local EXIF test images (downloaded, not part of the repo)
/test-assets/
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^1.21.0",
"offline-geocode-city": "^1.0.2",
"react": "^19.2.7",
"react-dom": "^19.2.7",
"react-dropzone": "^15.0.0",
Expand Down
33 changes: 33 additions & 0 deletions apps/web/src/lib/geocode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export interface PlaceName {
city: string
country: string
countryIso2: string
}

// The cities dataset (~1.7 MB) is lazy-loaded on first use so it never bloats
// the initial bundle. Everything runs locally — coordinates never leave the
// device (see docs/decisions/0001-offline-reverse-geocoding.md).
let loader: Promise<typeof import('offline-geocode-city')> | null = null

function loadGeocoder() {
loader ??= import('offline-geocode-city')
return loader
}

export async function reverseGeocode(
latitude: number,
longitude: number,
): Promise<PlaceName | null> {
try {
const { getNearestCity } = await loadGeocoder()
const result = await getNearestCity(latitude, longitude)
if (!result?.cityName) return null
return {
city: result.cityName,
country: result.countryName,
countryIso2: result.countryIso2,
}
} catch {
return null
}
}
33 changes: 33 additions & 0 deletions docs/decisions/0001-offline-reverse-geocoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ADR 0001 — Offline reverse-geocoding for EXIF captions

**Status:** Accepted (2026-06-28)

## Context

Polaroid captions auto-fill the city from a photo's EXIF GPS (#4). Resolving
GPS → city name can be done two ways:

- **Online API** (Nominatim, Google, etc.) — accurate, but sends every photo's
coordinates to a third party.
- **Offline dataset** — bundled cities, nearest-neighbour lookup, fully local.

The app's core promise is _"private, client-side, never uploaded"_. Sending
coordinates to a geocoding API silently breaks that promise.

## Decision

**Offline-first.** Use
[`offline-geocode-city`](https://www.npmjs.com/package/offline-geocode-city) — a
bundled cities dataset (~1.7 MB) exposing `getNearestCity(lat, lon)` →
`{ cityName, countryName, countryIso2 }`. It runs entirely in the browser;
coordinates never leave the device.

To keep the initial bundle small, the dataset is **lazy-loaded** (dynamic
`import()`) only when the first GPS-tagged photo needs geocoding.

## Consequences

- City accuracy is "nearest sizable city", not street-level — fine for captions.
- No network, no API keys, no rate limits, no privacy leak.
- If higher accuracy is ever wanted, an **opt-in** online lookup (off by
default, clearly disclosed) can be added later — never silent.
Loading
Loading