How coolmanyt/what2wear works
1. Overall shape
- This is a Next.js 16 App Router application with a mix of public marketing/legal pages, authenticated app pages, and server-side API routes.
- The app is deployed serverlessly on Vercel, with Supabase used for persistent user data and NextAuth v5 for login/session handling.
2. Primary user experience layer
- The main UI lives under src/app/* and is split into pages like dashboard, account, settings, preview, login, privacy, terms, and changelog.
- Client-heavy interactive pieces are factored into src/components/* and *Client.tsx files, while page routes stay as server-rendered entry points.
3. Core product flow: location → weather → outfit recommendation
- The central workflow is: the user chooses a location, the app fetches geocoded coordinates and weather, then requests an AI-generated outfit recommendation.
- That flow is exposed through API routes such as api/geocode, api/weather, and api/style, with the dashboard UI orchestrating the sequence.
4. Weather aggregation subsystem
- Weather is not sourced from a single provider; the README says it aggregates OpenWeatherMap, Open-Meteo, and Bureau of Meteorology (Australia).
- The reusable server-side weather logic is in src/lib/weather.ts, which likely consolidates provider responses into a single app-facing model.
- There are also api/demo/weather and api/demo/geocode routes for limited unauthenticated examples of the same pipeline.
5. AI recommendation subsystem
- AI generation is abstracted in src/lib/ai.ts and surfaced through routes like api/style and api/followup.
- The app supports OpenAI GPT-4o and Google Gemini, and also supports a bring-your-own-key mode for Pro users.
- A key architectural boundary is that API keys are handled server-side only and user-provided keys are used for a single request and not stored.
6. User data and personalization
- Persistent user-specific data appears to be stored in Supabase Postgres via src/lib/supabase.ts and the SQL schema in supabase/schema.sql.
- The main personalization areas are:
- closet for wardrobe items,
- settings for preferences and custom behavior,
- account for profile/plan-related state.
- src/lib/sync-user.ts likely keeps auth identity and database user records aligned.
7. Authentication and session boundary
- Authentication is handled by NextAuth through src/auth.ts and src/app/api/auth/[...nextauth]/route.ts.
- The README indicates JWT sessions are used, with a safe adapter fallback around the database integration.
- OAuth providers are GitHub and Google, so the app’s protected routes depend on server-side session verification rather than client trust.
8. Usage limits, credits, and plan enforcement
- The app enforces quota and monetization rules through src/lib/credits.ts and src/lib/daily-usage.ts, plus API routes like api/credits and api/daily-limits.
- This is a major architectural boundary: request handling for AI, follow-ups, closet usage, and source selection depends on the user’s free/pro plan entitlements.
- The account and settings pages are the main surfaces where these plan differences are exposed.
9. Security-sensitive request handling
- src/app/actions.ts and route handlers perform server-side operations so secrets and validation never leave the backend.
- The README calls out SSRF protection for custom weather source URLs, enforcing HTTPS and rejecting private/internal hosts.
- src/proxy.ts likely provides a request interception layer for auth or routing protection at the app edge.
10. Content and legal pages
- Static/public-facing content is split out cleanly into dedicated routes: /privacy, /terms, /changelog, and the landing page.
- changelog.json plus api/changelog suggests release notes are served from a structured source rather than hard-coded in the UI.
11. UI composition
- Reusable UI primitives and product widgets live in src/components, including:
- LocationPicker / DemoLocationPicker for geocoding entry,
- WeatherEffectCard for weather visualization,
- ThemeController for dark mode,
- UpgradePlanModal and AccountUpgradeButton for monetization flows.
- Dashboard.tsx is likely the main composition root for the authenticated experience.
12. Data/control flow boundaries to capture in a diagram
- Browser client components initiate requests to Next.js API routes.
- API routes call external services: weather providers, AI providers, geocoding services, and Supabase.
- Server-side libraries centralize business logic: weather aggregation, AI prompting, credits/limits, and auth/user syncing.
- The result is a clearly layered app: presentation → route handlers/server logic → external APIs + database.
Main entry points: Dashboard.tsx Dashboard UI · ai.ts AI Core · auth.ts Auth Config · route.ts Geocode API
Components 34
Presentation
App routes and client-facing UI composition.
- Landing · Public home page entry point.
src/app/page.tsx - Dashboard · Authenticated product entry point.
src/app/dashboard/page.tsx - Dashboard UI · Main authenticated experience composition.
src/components/Dashboard.tsx - Location Picker · Location selection and geocoding trigger.
src/components/LocationPicker.tsx - Weather Card · Weather display and visual feedback.
src/components/WeatherEffectCard.tsx - Upgrade Modal · Plan upgrade and paywall surface.
src/components/UpgradePlanModal.tsx - Login · Authentication entry page.
src/app/login/page.tsx - Account · Profile and plan management page.
src/app/account/page.tsx - Settings · User preferences and customization page.
src/app/settings/page.tsx - Preview · Preview-oriented app page.
src/app/preview/page.tsx - Privacy · Public privacy policy page.
src/app/privacy/page.tsx - Terms · Public terms page.
src/app/terms/page.tsx - Changelog · Release notes page.
src/app/changelog/page.tsx
Route Handlers
Next.js API routes and server actions that handle requests.
- Auth API · NextAuth handler for login and sessions.
src/app/api/auth/[...nextauth]/route.ts - Geocode API · Converts locations into coordinates.
src/app/api/geocode/route.ts - Weather API · Serves normalized weather data.
src/app/api/weather/route.ts - Style API · Generates outfit recommendations.
src/app/api/style/route.ts - Followup API · Handles iterative AI follow-up requests.
src/app/api/followup/route.ts - Credits API · Exposes quota and credit state.
src/app/api/credits/route.ts - Limits API · Exposes daily usage limits.
src/app/api/daily-limits/route.ts - Closet API · Manages wardrobe data.
src/app/api/closet/route.ts - Settings API · Persists user settings.
src/app/api/settings/route.ts - Demo Geocode · Unauthenticated geocode example.
src/app/api/demo/geocode/route.ts - Demo Weather · Unauthenticated weather example.
src/app/api/demo/weather/route.ts - Server Actions · Backend mutations invoked from the app.
src/app/actions.ts - Edge Proxy · Edge-level request protection and routing.
src/proxy.ts
Core Logic
Shared business rules for weather, AI, auth, and limits.
- Weather Core · Aggregates and normalizes provider data.
src/lib/weather.ts - AI Core · Abstracts model selection and prompt execution.
src/lib/ai.ts - Credits Logic · Enforces plan and usage entitlements.
src/lib/credits.ts - Usage Logic · Tracks daily request usage.
src/lib/daily-usage.ts - Supabase Client · Database access for persisted user data.
src/lib/supabase.ts - User Sync · Keeps auth identity and DB records aligned.
src/lib/sync-user.ts - Auth Config · NextAuth provider and session configuration.
src/auth.ts
Data & Services
Persistent storage and external providers used by the app.
- Weather Providers · OpenWeatherMap, Open-Meteo, and BOM.
Connections 31
- Landing → Login: entry · Public users move from landing to login.
- Dashboard → Dashboard UI: renders · Dashboard route composes the main client shell.
- Dashboard UI → Location Picker: selects · Users choose a location to start the weather flow.
- Dashboard UI → Weather Card: shows · Dashboard presents weather and outfit output.
- Dashboard UI → Upgrade Modal: upsell · Plan limits surface upgrade prompts.
- Location Picker → Geocode API: requests · Location input triggers geocoding.
- Geocode API → Weather Core: uses · Geocode flow feeds weather-oriented location handling.
- Demo Geocode → Geocode API: example · Demo route mirrors the main geocode flow.
- Weather Card → Weather API: requests · Weather UI pulls normalized forecast data.
- Weather API → Weather Core: uses · Weather route delegates aggregation and normalization.
- Weather Core → Weather Providers: fetches · Weather core queries multiple upstream providers.
- Demo Weather → Weather API: example · Demo route mirrors the main weather flow.
- Dashboard UI → Style API: asks · Dashboard requests outfit recommendations.
- Style API → AI Core: uses · Style route delegates to AI orchestration.
- Followup API → AI Core: uses · Follow-up chat style requests reuse the AI core.
- AI Core → Credits Logic: checks · AI usage depends on entitlement rules.
- AI Core → Usage Logic: tracks · AI requests contribute to daily usage accounting.
- Credits API → Credits Logic: exposes · Credits route surfaces entitlement state.
- Limits API → Usage Logic: exposes · Daily limits route surfaces usage totals.
- Closet API → Supabase Client: persists · Closet data is stored in Supabase.
- Settings API → Supabase Client: persists · Settings are stored in Supabase.
- Server Actions → User Sync: mutates · Server actions coordinate authenticated backend changes.
- Auth API → Auth Config: configures · NextAuth route uses the shared auth config.
- Auth Config → User Sync: syncs · Auth lifecycle keeps DB user records aligned.
- Auth Config → Supabase Client: adapts · Auth integrates with the database layer.
- Edge Proxy → Auth API: guards · Edge proxy protects authenticated app areas.
- Account → Credits API: views · Account page exposes plan and credit state.
- Account → Closet API: manages · Account flows can interact with wardrobe data.
- Settings → Settings API: saves · Settings page persists user preferences.
- Changelog → Changelog · Static changelog content is rendered from structured source.
- Privacy → Terms · Legal pages sit alongside each other as public content.