How sinsinpurin/osanpo-story works
Purpose and deployment shape
おさんぽストーリー is an Expo React Native iOS/Android walking app. A user selects a map destination or desired distance; the system generates a detour/round-trip pedestrian course with location-triggered checkpoint trivia. The repository has two deployable boundaries: mobile client in app/ and Supabase database plus Edge Function in supabase/.
Mobile entry and navigation
The application starts at app/index.ts, with provider composition and navigation rooted in app/App.tsx. A stack flow in app/src/navigation/RootNavigator.tsx drives Start → destination input → route preview → active walk → completion. Navigation contracts are centralized in app/src/navigation/types.ts.
Course request and preview
app/src/screens/DestinationInputScreen.tsx collects a pinned destination or distance-based walk request, obtains current location, and invokes the backend through app/src/services/api.ts. app/src/screens/RoutePreviewScreen.tsx renders the returned route/checkpoints before the user commits to walking. Shared course payload definitions reside in app/src/types/course.ts.
Active-walk state machine
app/src/screens/WalkScreen.tsx is the runtime walking experience: it starts location/geofence observation, tracks checkpoint arrivals, and displays trivia. app/src/services/location.ts owns GPS permissions, current-position acquisition, and checkpoint proximity monitoring. This separates device/location lifecycle concerns from screen presentation. Geographic calculations used client-side are in app/src/utils/geo.ts.
Local persistence and progression
The app persists generated courses, visited checkpoints, aggregate user progress, and individual walk sessions in local SQLite via app/src/services/storage.ts. Completion is handled by app/src/screens/WalkCompleteScreen.tsx, which calculates and presents earned XP/levels using app/src/utils/xp.ts. Thus walking can update durable local progression independently of backend course-generation availability.
Edge Function generation pipeline
supabase/functions/generate-course/index.ts is the server entry point and orchestrator. It resolves request mode, computes a walking route, finds route-adjacent places, enriches them, caches results, and returns a course. Route geometry utilities and suitability checks live in supabase/functions/generate-course/geo.ts; destination-name reverse geocoding is isolated in supabase/functions/generate-course/nominatim.ts.
External enrichment and persistence
The Edge Function calls OpenRouteService through supabase/functions/generate-course/ors.ts for point-to-point detours or round_trip routes, then Overpass through supabase/functions/generate-course/overpass.ts for checkpoint candidates. It generates/cache trivia with Anthropic Claude through supabase/functions/generate-course/trivia.ts. Images prefer tagged Wikipedia metadata/search in supabase/functions/generate-course/wikipedia.ts, with Google Places Text Search/photo resources in supabase/functions/generate-course/places.ts as an optional higher-fidelity fallback. Supabase Postgres caches courses and OSM-ID-scoped trivia, initialized in supabase/migrations/0001_init.sql and extended for checkpoint image/photo metadata in supabase/migrations/0002_add_checkpoint_image.sql and supabase/migrations/0005_add_place_photo_name.sql.
Runtime and service boundaries
Client runtime is Expo/React Native with SQLite and device location/geofencing; production background detection requires a development/EAS-style native build rather than Expo Go. Backend runtime is a Supabase Edge Function using auto-provided Supabase URL/service credentials. Required secrets are ORS, Anthropic, and a policy-compliant Nominatim User-Agent; Google Places is optional. The client uses public Supabase URL and publishable key to invoke the Edge Function.
Main entry points: index.ts Generate course · WalkScreen.tsx Active walk · api.ts Course API client · DestinationInputScreen.tsx Destination input
Components 19
Expo mobile client
React Native walking experience.
- App entry
app/index.ts - Providers & app shell
app/App.tsx - Walk flow navigator · Start through completion flow and route contracts.
app/src/navigation/RootNavigator.tsx - Destination input · Collects destination or distance requests.
app/src/screens/DestinationInputScreen.tsx - Route preview · Shows generated route and checkpoints before commitment.
app/src/screens/RoutePreviewScreen.tsx - Active walk · Tracks arrivals and presents checkpoint trivia.
app/src/screens/WalkScreen.tsx - Walk completion · Calculates and presents earned XP and levels.
app/src/screens/WalkCompleteScreen.tsx - Location lifecycle · Owns permissions, positioning, and checkpoint monitoring.
app/src/services/location.ts - Course API client
app/src/services/api.ts - Local walk store · Persists courses, visits, progress, and sessions.
app/src/services/storage.ts
Supabase backend
Course-generation boundary.
- Generate course · Orchestrates routing, place enrichment, trivia, and caching.
supabase/functions/generate-course/index.ts - Route geometry · Applies route suitability and geographic calculations.
supabase/functions/generate-course/geo.ts - Course & trivia cache · Caches courses, OSM-scoped trivia, and checkpoint image metadata.
supabase/migrations/0001_init.sql
External services
- OpenRouteService · Provides detour and round-trip route geometry.
supabase/functions/generate-course/ors.ts - Overpass · Finds route-adjacent checkpoint candidates.
supabase/functions/generate-course/overpass.ts - Claude trivia generation · Generates checkpoint trivia for caching.
supabase/functions/generate-course/trivia.ts - Wikipedia images · Preferred tagged image source.
supabase/functions/generate-course/wikipedia.ts - Google Places fallback · Optional higher-fidelity image and place fallback.
supabase/functions/generate-course/places.ts - Nominatim · Resolves destination names.
supabase/functions/generate-course/nominatim.ts
Connections 21
- App entry → Providers & app shell: boots
- Providers & app shell → Walk flow navigator: hosts
- Walk flow navigator → Destination input: starts request
- Destination input → Location lifecycle: gets current position
- Destination input → Course API client: requests course
- Course API client → Generate course: invokes
- Generate course → Course & trivia cache: reads/writes cache
- Generate course → Route geometry: evaluates route
- Generate course → OpenRouteService: requests walking route
- Generate course → Overpass: finds checkpoint candidates
- Generate course → Nominatim: reverse geocodes destination
- Generate course → Claude trivia generation: generates trivia
- Generate course → Wikipedia images: enriches images
- Generate course → Google Places fallback: optional fallback
- Generate course → Course API client: returns course
- Course API client → Route preview: supplies course
- Route preview → Active walk: commits walk
- Active walk → Location lifecycle: starts monitoring
- Active walk → Local walk store: persists visits/session
- Active walk → Walk completion: finishes walk
- Walk completion → Local walk store: updates progression