Skip to content

Architecture Overview

hasnaina955 edited this page Sep 3, 2026 · 1 revision

Architecture Overview

Condensed map of the system. Full tour: docs/ARCHITECTURE.md.


Pages (React)  ──▶  lib/ (pure functions)  ◀──  store.ts (reactive cache)
     │                                             │
components (map, modals)                Supabase JS client
                                                   │
                                    Supabase (Postgres + Auth): 8 tables,
                                    Row Level Security everywhere
External (keyless, failure-safe): Open-Meteo geocode · OSRM routing ·
Wikipedia geosearch · OSM Overpass · Mappls · OpenFreeMap tiles

Layers

Layer Location Rule
Pages src/pages/ React components; TripWorkspace.tsx hosts the 8 workspace tabs
Pure logic src/lib/ No React, no I/O (except supabase.ts); engine, impact, ridePlan, geocode facade, providers
Store src/store/store.ts useSyncExternalStore over an in-memory cache; hydrates from Supabase, writes through with error checks + rollback
Maps src/components/TripMap.tsx + mapcn/ MapLibre; never import maplibre-gl types directly — structural casts
Data model src/data/types.ts Times are 24h "HH:MM" strings; coordinates are plain numbers

Key flows

  • Hydration: login → init() loads all 8 tables into the cache (per-table error logging) → UI renders from cache
  • Mutation: update cache → persist via persistTripField (.from('trips').update) → error ⇒ toast + rollback
  • Realtime: one postgres_changes channel over all tables; own writes echo-suppressed; reducers are pure (realtimeCore.ts)
  • Impact preview: every edit simulates the day (simulateDay) and shows time/cost deltas before saving

Testing

259 vitest tests, node env (no DOM) — pure logic only; provider calls mocked with route tables; vi.stubEnv for API keys. Run everything with npm run verify (see Release Process).


Related: Design Decisions · Data Sources and Limits

Clone this wiki locally