# alexnguyen244/vestilio-app architecture

> Architecture diagram of the GitHub repository alexnguyen244/vestilio-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexnguyen244/vestilio-app
- Repository: https://github.com/alexnguyen244/vestilio-app

## Overview

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: [`server/routers/chat.py`](https://github.com/alexnguyen244/vestilio-app/blob/main/server/routers/chat.py) (Route layer), [`phone-client/src/screens/HomeScreen.tsx`](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/screens/HomeScreen.tsx) (User screens), [`server/services/upload_processor.py`](https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/upload_processor.py) (Upload pipeline), [`server/models.py`](https://github.com/alexnguyen244/vestilio-app/blob/main/server/models.py) (Postgres data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile app"]
  node_app_entry["App shell<br/>Expo entry<br/>[App.tsx]"]
  node_mobile_screens["User screens<br/>React Native screens<br/>[HomeScreen.tsx]"]
  node_mobile_contexts["App state<br/>React contexts<br/>[AuthContext.tsx]"]
  node_mobile_cache[("Local cache<br/>SQLite/cache layer<br/>[localDb.ts]")]
  node_mobile_apis["API clients<br/>Client services<br/>[chatApi.ts]"]
  node_voice_native["Voice runtime<br/>WebRTC/audio bridge<br/>[webrtcVoice.ts]"]
end

subgraph group_backend["Backend API"]
  node_api_entry["API server<br/>FastAPI app<br/>[main.py]"]
  node_api_routers["Route layer<br/>HTTP/WebSocket routers<br/>[chat.py]"]
  node_ai_orchestration["AI services<br/>Orchestration services<br/>[openai_service.py]"]
  node_upload_pipeline["Upload pipeline<br/>Async job pipeline"]
  node_avatar_tryon["Avatar & try-on<br/>External job chain<br/>[fashn_service.py]"]
  node_preference_loop["Feedback loop<br/>Preference service"]
end

subgraph group_data["Supabase"]
  node_supabase_db[("Postgres data<br/>Supabase schema<br/>[models.py]")]
  node_supabase_storage[("Object storage<br/>Storage buckets")]
  node_edge_enqueue["Enqueue function<br/>Supabase Edge Function<br/>[index.ts]"]
end

subgraph group_infra["Supporting infra"]
  node_migrations["Migrations<br/>Alembic schema"]
  node_docs_pipeline["Docs<br/>[upload-pipeline.md]"]
  node_scripts_tools["Ops scripts<br/>Maintenance scripts<br/>[set_version.py]"]
end

node_app_entry -->|"renders"| node_mobile_screens
node_mobile_screens -->|"shares state"| node_mobile_contexts
node_mobile_screens -->|"reads cache"| node_mobile_cache
node_mobile_screens -->|"calls backend"| node_mobile_apis
node_mobile_screens -->|"voice chat"| node_voice_native
node_mobile_cache -.->|"refreshes"| node_mobile_apis
node_mobile_apis -->|"requests"| node_api_routers
node_voice_native -->|"webrtc"| node_api_routers
node_api_entry -->|"mounts"| node_api_routers
node_api_routers -->|"orchestrates"| node_ai_orchestration
node_api_routers -->|"starts jobs"| node_upload_pipeline
node_api_routers -->|"creates jobs"| node_avatar_tryon
node_api_routers -->|"records feedback"| node_preference_loop
node_upload_pipeline -->|"updates rows"| node_supabase_db
node_upload_pipeline -->|"stores assets"| node_supabase_storage
node_avatar_tryon -->|"stores state"| node_supabase_db
node_avatar_tryon -->|"stores media"| node_supabase_storage
node_preference_loop -->|"writes vectors"| node_supabase_db
node_edge_enqueue -.->|"enqueues"| node_upload_pipeline
node_migrations -->|"defines schema"| node_supabase_db
node_docs_pipeline -.->|"documents"| node_upload_pipeline
node_docs_pipeline -.->|"documents"| node_ai_orchestration
node_scripts_tools -.->|"supports"| node_migrations

click node_app_entry "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/App.tsx"
click node_mobile_screens "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/screens/HomeScreen.tsx"
click node_mobile_contexts "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/context/AuthContext.tsx"
click node_mobile_cache "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/localDb.ts"
click node_mobile_apis "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/chatApi.ts"
click node_voice_native "https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/webrtcVoice.ts"
click node_api_entry "https://github.com/alexnguyen244/vestilio-app/blob/main/server/main.py"
click node_api_routers "https://github.com/alexnguyen244/vestilio-app/blob/main/server/routers/chat.py"
click node_ai_orchestration "https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/openai_service.py"
click node_upload_pipeline "https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/upload_processor.py"
click node_avatar_tryon "https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/fashn_service.py"
click node_preference_loop "https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/preference_service.py"
click node_supabase_db "https://github.com/alexnguyen244/vestilio-app/blob/main/server/models.py"
click node_edge_enqueue "https://github.com/alexnguyen244/vestilio-app/blob/main/supabase/functions/enqueue-upload/index.ts"
click node_migrations "https://github.com/alexnguyen244/vestilio-app/blob/main/server/alembic/versions/f60c52e95625_create_profiles_table.py"
click node_docs_pipeline "https://github.com/alexnguyen244/vestilio-app/blob/main/docs/upload-pipeline.md"
click node_scripts_tools "https://github.com/alexnguyen244/vestilio-app/blob/main/scripts/set_version.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_entry,node_mobile_screens,node_mobile_contexts,node_mobile_cache,node_mobile_apis,node_voice_native toneBlue
class node_api_entry,node_api_routers,node_ai_orchestration,node_upload_pipeline,node_avatar_tryon,node_preference_loop toneAmber
class node_supabase_db,node_supabase_storage,node_edge_enqueue toneMint
class node_migrations,node_docs_pipeline,node_scripts_tools toneRose
```

## Components

### Mobile app

React Native/Expo client, UI state, local cache, and device integrations.

- [App shell](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/App.tsx): Expo entry · Bootstraps the mobile app and navigation root. · `phone-client/App.tsx`
- [User screens](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/screens/HomeScreen.tsx): React Native screens · Authenticated flows for onboarding, wardrobe, outfit building, chat, settings, calendar, and voice selection. · `phone-client/src/screens/HomeScreen.tsx`
- [App state](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/context/AuthContext.tsx): React contexts · Shared session, wardrobe, chat, navigation, upload, and animation state. · `phone-client/src/context/AuthContext.tsx`
- [Local cache](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/localDb.ts): SQLite/cache layer · Offline-first wardrobe cache and refresh logic for expiring signed URLs. · `phone-client/src/lib/localDb.ts`
- [API clients](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/chatApi.ts): Client services · Typed request layer for wardrobe, chat, outfit, onboarding, preferences, settings, weather, TTS, and versioning. · `phone-client/src/lib/chatApi.ts`
- [Voice runtime](https://github.com/alexnguyen244/vestilio-app/blob/main/phone-client/src/lib/webrtcVoice.ts): WebRTC/audio bridge · 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](https://github.com/alexnguyen244/vestilio-app/blob/main/server/main.py): FastAPI app · Main backend entrypoint that mounts routers and websocket endpoints. · `server/main.py`
- [Route layer](https://github.com/alexnguyen244/vestilio-app/blob/main/server/routers/chat.py): HTTP/WebSocket routers · Endpoint surface for auth, wardrobe, outfits, chat, preferences, onboarding, avatar, TTS, weather, settings, app versioning, webhooks, and WebRTC. · `server/routers/chat.py`
- [AI services](https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/openai_service.py): Orchestration services · OpenAI intent/context/reasoning, preference scoring, styling context, and TTS provider selection. · `server/services/openai_service.py`
- [Upload pipeline](https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/upload_processor.py): Async job pipeline · Wardrobe image processing, crop/normalize, fal.ai background removal, webhook polling, and storage writes. · `server/services/upload_processor.py`
- [Avatar & try-on](https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/fashn_service.py): External job chain · Onboarding avatar generation and try-on jobs with chained callbacks and normalized outputs. · `server/services/fashn_service.py`
- [Feedback loop](https://github.com/alexnguyen244/vestilio-app/blob/main/server/services/preference_service.py): Preference service · 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](https://github.com/alexnguyen244/vestilio-app/blob/main/server/models.py): Supabase schema · Profiles, wardrobe, outfits, outfit items, chat messages, active outfits, feedback, preferences, and reference vocab tables. · `server/models.py`
- **Object storage**: Storage buckets · Clothing images, processed assets, avatars, screenshots, and try-on artifacts.
- [Enqueue function](https://github.com/alexnguyen244/vestilio-app/blob/main/supabase/functions/enqueue-upload/index.ts): Supabase Edge Function · Serverless helper that enqueues upload processing jobs. · `supabase/functions/enqueue-upload/index.ts`

### Supporting infra

Migrations, scripts, docs, and deployment/support files.

- [Migrations](https://github.com/alexnguyen244/vestilio-app/blob/main/server/alembic/versions/f60c52e95625_create_profiles_table.py): Alembic schema · Versioned schema evolution for core tables, reference vocabularies, and job tables. · `server/alembic/versions/f60c52e95625_create_profiles_table.py`
- [Docs](https://github.com/alexnguyen244/vestilio-app/blob/main/docs/upload-pipeline.md): Architecture docs · Narrative specs for upload, recommendation, and voice flows. · `docs/upload-pipeline.md`
- [Ops scripts](https://github.com/alexnguyen244/vestilio-app/blob/main/scripts/set_version.py): Maintenance scripts · Versioning, catalog management, and user deletion utilities. · `scripts/set_version.py`

## Connections

- 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.
