How alexnguyen244/vestilio-app works
1. This repo is a three-part product: a React Native/Expo mobile app, a FastAPI backend, and a Supabase-managed PostgreSQL/Storage layer. The mobile app is the primary user interface; the backend owns business logic, AI orchestration, and webhook handling; Supabase provides auth, data persistence, and object storage.
2. The mobile client lives in phone-client/ and is organized around authenticated user flows: onboarding, wardrobe browsing, outfit building/chat, settings, calendar, and voice selection. It uses React context heavily to share session state, wardrobe cache, chat state, and UI animation/navigation state across screens and components.
3. The backend in server/ is the system’s control plane. main.py exposes REST endpoints and WebSockets through routers for auth, wardrobe, outfits, chat, preferences, onboarding/avatar, TTS, weather, settings, app versioning, and provider callbacks. The app depends on the backend for all authoritative operations; the client mostly renders cached state and forwards user actions.
4. Data is centered on Supabase tables. Core user-owned entities are profiles, wardrobe, outfits, outfit_items, chat_messages, and preference tables; reference tables define controlled vocabularies for categories, colors, materials, fit, seasons, occasions, closures, and more. Storage buckets hold original and processed clothing images, avatars, feedback screenshots, and try-on assets.
5. The wardrobe pipeline is asynchronous and webhook-driven. When the user uploads a clothing photo, the server creates a wardrobe_upload_jobs row, analyzes the image with OpenAI vision, submits background removal to fal.ai, receives a callback, crops/norms the image, uploads processed assets to Supabase Storage, generates a CLIP embedding, and finally updates the wardrobe row plus its junction tables.
6. Outfit recommendation is the main AI orchestration path. A chat message goes through intent classification, context inference, outfit slot planning, item selection, and optional reasoning generation. The server prefers the client’s cached wardrobe payload to avoid a DB round-trip, and it injects learned style preferences when available.
7. The chat subsystem is stateful but intentionally bounded. The backend keeps only the most recent 10 messages per user and also maintains a chat_active_outfits record for the current outfit being edited. The mobile UI uses MiniChat to present text chat, outfit cards, option lists, and action buttons for like/dislike/save/today.
8. Voice chat is a separate real-time boundary. The app can open a WebRTC session to /webrtc/voice, send transcripts or chat events over a data channel, and receive streamed TTS audio back as PCM frames. The server handles audio generation through tts_service.py, supporting OpenAI TTS and ElevenLabs, while the client configures device audio session behavior in native code.
9. Avatar generation and virtual try-on share the same external job pattern. Onboarding uploads a full-body photo, the backend detects gender, submits a FASHN job, and chains callbacks until a normalized avatar is stored and the profile is marked ready. Try-on uses the same job table and webhook pattern, chaining garments in a defined category order to produce a composite result.
10. Outfit feedback is a separate learning loop. When the user likes/dislikes or saves an outfit, the client posts the outfit slots and context to /preferences/feedback. The backend builds a 1536-dimensional preference vector from text plus image embeddings, stores it in outfit_preferences, and updates a rolling user style profile used to bias future recommendations.
11. Local caching is a first-class architectural decision on the mobile side. Wardrobe data is cached in SQLite via localDb.ts, and signed URLs are refreshed periodically because Supabase signed links expire. This keeps the app responsive while still treating the server as the source of truth.
12. The repo also contains supporting infrastructure code: Alembic migrations for schema evolution, a Supabase Edge Function for upload enqueueing, test suites on both client and server, and deployment config for Render and Expo/Xcode builds. The overall architecture is eventful and AI-heavy, but the boundaries are clear: mobile UI and local cache on one side, FastAPI orchestration in the middle, and Supabase plus third-party AI services on the other.
Main entry points: chat.py Route layer · HomeScreen.tsx User screens · upload_processor.py Upload pipeline · models.py Postgres data
Components 18
Mobile app
React Native/Expo client, UI state, local cache, and device integrations.
- App shell · Bootstraps the mobile app and navigation root.
phone-client/App.tsx - User screens · Authenticated flows for onboarding, wardrobe, outfit building, chat, settings, calendar, and voice selection.
phone-client/src/screens/HomeScreen.tsx - App state · Shared session, wardrobe, chat, navigation, upload, and animation state.
phone-client/src/context/AuthContext.tsx - Local cache · Offline-first wardrobe cache and refresh logic for expiring signed URLs.
phone-client/src/lib/localDb.ts - API clients · Typed request layer for wardrobe, chat, outfit, onboarding, preferences, settings, weather, TTS, and versioning.
phone-client/src/lib/chatApi.ts - Voice runtime · Device audio session and realtime voice transport between mobile and backend.
phone-client/src/lib/webrtcVoice.ts
Backend API
FastAPI control plane for auth, wardrobe, chat, AI orchestration, and webhooks.
- API server · Main backend entrypoint that mounts routers and websocket endpoints.
server/main.py - Route layer · Endpoint surface for auth, wardrobe, outfits, chat, preferences, onboarding, avatar, TTS, weather, settings, app versioning, webhooks, and WebRTC.
server/routers/chat.py - AI services · OpenAI intent/context/reasoning, preference scoring, styling context, and TTS provider selection.
server/services/openai_service.py - Upload pipeline · Wardrobe image processing, crop/normalize, fal.ai background removal, webhook polling, and storage writes.
server/services/upload_processor.py - Avatar & try-on · Onboarding avatar generation and try-on jobs with chained callbacks and normalized outputs.
server/services/fashn_service.py - Feedback loop · Stores outfit feedback vectors and updates rolling style preference signals.
server/services/preference_service.py
Supabase
PostgreSQL data model, storage buckets, and edge functions.
- Postgres data · Profiles, wardrobe, outfits, outfit items, chat messages, active outfits, feedback, preferences, and reference vocab tables.
server/models.py - Object storage · Clothing images, processed assets, avatars, screenshots, and try-on artifacts.
- Enqueue function · Serverless helper that enqueues upload processing jobs.
supabase/functions/enqueue-upload/index.ts
Supporting infra
Migrations, scripts, docs, and deployment/support files.
- Migrations · Versioned schema evolution for core tables, reference vocabularies, and job tables.
server/alembic/versions/f60c52e95625_create_profiles_table.py - Docs · Narrative specs for upload, recommendation, and voice flows.
docs/upload-pipeline.md - Ops scripts · Versioning, catalog management, and user deletion utilities.
scripts/set_version.py
Connections 23
- App shell → User screens: renders · App shell mounts the main authenticated UI flows.
- User screens → App state: shares state · Screens depend on contexts for auth, wardrobe, chat, and navigation state.
- User screens → Local cache: reads cache · Wardrobe and outfit views use local cached data for responsiveness.
- User screens → API clients: calls backend · User actions are forwarded through the API client layer.
- User screens → Voice runtime: voice chat · Voice selection and realtime chat use the native audio/WebRTC bridge.
- Local cache → API clients: refreshes · Cached wardrobe data is synced and signed URLs are renewed through API calls.
- API clients → Route layer: requests · Client requests are handled by backend routers and websocket endpoints.
- Voice runtime → Route layer: webrtc · Realtime voice sessions connect to the backend voice endpoint.
- API server → Route layer: mounts · Main app registers the route surface.
- Route layer → AI services: orchestrates · Chat, outfit, TTS, weather, and preference endpoints invoke AI and domain services.
- Route layer → Upload pipeline: starts jobs · Wardrobe upload and image processing flow enters the async pipeline.
- Route layer → Avatar & try-on: creates jobs · Onboarding avatar and try-on endpoints submit external jobs and handle callbacks.
- Route layer → Feedback loop: records feedback · Like/dislike/save actions update outfit preference signals.
- Upload pipeline → Postgres data: updates rows · Pipeline writes wardrobe upload jobs, wardrobe records, and junction tables.
- Upload pipeline → Object storage: stores assets · Processed clothing images and derived assets are uploaded to storage.
- Avatar & try-on → Postgres data: stores state · Avatar and try-on jobs persist status and final profile data.
- Avatar & try-on → Object storage: stores media · Generated avatars and composite outputs land in object storage.
- Feedback loop → Postgres data: writes vectors · Preference feedback is persisted to outfit preference tables and user style state.
- Enqueue function → Upload pipeline: enqueues · Edge function kicks off server-side upload processing.
- Migrations → Postgres data: defines schema · Alembic migrations evolve the backend-owned PostgreSQL schema.
- Docs → Upload pipeline: documents · Pipeline docs explain the async wardrobe flow.
- Docs → AI services: documents · Docs describe recommendation and voice orchestration behavior.
- Ops scripts → Migrations: supports · Operational scripts sit alongside schema and release management.