# nsk-syam/myig architecture

> Architecture diagram of the GitHub repository nsk-syam/myig, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nsk-syam/myig
- Repository: https://github.com/nsk-syam/myig

## Overview

1. This repo is a split frontend/backend product for an outfit-finding app: a React/Vite web app in `src`, a Supabase backend in `supabase`, and an iOS wrapper under `ios` built with Capacitor. The architecture is centered on image-based search, account/entitlement management, and saved results.

2. The main UI lives in `src/pages` and `src/components`. `Index`, `SearchResults`, `Saved`, `Account`, `AnalyticsPage`, and legal pages form the public-facing and authenticated surfaces. `src/components/app` contains app-specific screens like `HomeScreen`, `PremiumHomePage`, `AccountScreen`, quota UI, and native-bridge abstractions.

3. The app’s state and side effects are pushed into hooks and libs rather than page components. `src/hooks` handles mobile detection, saved products, and search-access state; `src/lib` contains the domain logic for auth, analytics, search access, app access, market/product matching, image handling, and Supabase integration.

4. Authentication and user identity are handled through Supabase, with client setup in `src/integrations/supabase`. The frontend likely signs users in, then uses `auth`, `appAccess`, and `searchAccess` helpers to determine what features are available and whether search quotas apply.

5. Search entitlement is a major backend boundary. The app reads access state through edge functions such as `access-state`, `guest-access-state`, `issue-app-token`, `sync-entitlement`, and `consume-search`. This suggests a server-enforced quota and premium-access model rather than purely client-side gating.

6. The core product pipeline is image-to-results. User images are uploaded through `upload-image`, Instagram-style links are processed via `extract-instagram`, and outfit analysis happens in `analyze-outfit`. The results are then turned into product suggestions by `search-products`, with `proxy-product-image` used to safely fetch or relay external product imagery.

7. Saved items are treated as first-class data. `use-saved-products` and `savedProducts` in the client connect to backend persistence, while migrations like `saved_products_auth` indicate authenticated storage with access controls. This is a separate boundary from search results, which may be transient.

8. Analytics is a dedicated subsystem. The client emits events through `analytics`, and the backend ingests them with `ingest-analytics` and aggregates them with `analytics-summary`. The presence of an `AnalyticsPage` indicates analytics are also surfaced in-app, likely for internal or admin visibility.

9. The backend is Supabase-native and database-driven. Migrations define schema, security hardening, analytics events, signed-in search limits, and guest search access. That means authorization is enforced both in Postgres policies and in edge-function logic, not just in React.

10. There is a native iOS packaging layer, but it appears to reuse the same web app. `capacitor.config.ts` and the Xcode project under `ios/App` indicate the React app is bundled into a Capacitor shell, with Swift `AppDelegate` and storyboard assets only providing the native container and launch/splash behavior.

11. SEO and marketing are part of the delivery surface. `public` includes static landing pages, blog content, redirects, sitemap, robots, and app-manifest files, while `scripts/generate_og_image.py` suggests automated social preview generation. This implies the site serves both acquisition pages and the authenticated app from the same codebase.

12. Tests cover both UI and backend/domain boundaries. There are Vitest tests for auth, analytics, access control, product images, search products, SEO pages, and several component pages, plus Playwright config for browser-level flows. That indicates the repository is organized around validating both the client experience and the Supabase-backed business rules.

Main entry points: [`src/lib`](https://github.com/nsk-syam/myig/tree/main/src/lib) (Domain logic), [`src/pages`](https://github.com/nsk-syam/myig/tree/main/src/pages) (App routes), [`supabase/migrations`](https://github.com/nsk-syam/myig/tree/main/supabase/migrations) (Database schema), [`scripts`](https://github.com/nsk-syam/myig/tree/main/scripts) (Build scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend app"]
  node_web_root["Web shell<br/>Vite app<br/>[main.tsx]"]
  node_app_router["App routes<br/>SPA routes"]
  node_public_pages["Public pages<br/>marketing+legal<br/>[Index.tsx]"]
  node_search_results["Search results<br/>results view<br/>[SearchResults.tsx]"]
  node_account_saved["Account area<br/>authenticated views<br/>[Account.tsx]"]
  node_app_screens["App screens<br/>mobile UI"]
  node_ui_shell["UI chrome<br/>shared components"]
  node_state_hooks["State hooks<br/>client state"]
  node_domain_libs["Domain logic<br/>business rules"]
  node_supabase_client["Supabase client<br/>db client<br/>[client.ts]"]
end

subgraph group_backend["Supabase backend"]
  node_edge_auth["Access APIs<br/>edge functions"]
  node_edge_pipeline["Search pipeline<br/>edge functions<br/>[index.ts]"]
  node_edge_analytics["Analytics API<br/>edge functions<br/>[index.ts]"]
  node_edge_account["Account ops<br/>edge functions<br/>[index.ts]"]
  node_db_migrations[("Database schema<br/>migrations")]
end

subgraph group_native["iOS wrapper"]
  node_native_shell["iOS shell<br/>Capacitor app<br/>[AppDelegate.swift]"]
end

subgraph group_delivery["Delivery surface"]
  node_static_site["Static site<br/>public assets"]
  node_build_scripts["Build scripts<br/>release tooling"]
end

node_web_root -->|"boots"| node_app_router
node_app_router -->|"serves"| node_public_pages
node_app_router -->|"navigates"| node_search_results
node_app_router -->|"navigates"| node_account_saved
node_app_router -->|"uses"| node_app_screens
node_ui_shell -->|"frames"| node_app_router
node_state_hooks -->|"derives from"| node_domain_libs
node_domain_libs -->|"queries"| node_supabase_client
node_domain_libs -->|"calls"| node_edge_auth
node_domain_libs -->|"calls"| node_edge_pipeline
node_domain_libs -->|"emits"| node_edge_analytics
node_domain_libs -->|"calls"| node_edge_account
node_edge_auth -->|"enforced by"| node_db_migrations
node_edge_pipeline -->|"stores via"| node_db_migrations
node_edge_analytics -->|"aggregates from"| node_db_migrations
node_supabase_client -->|"targets"| node_db_migrations
node_native_shell -->|"wraps"| node_web_root
node_static_site -->|"publishes"| node_public_pages
node_build_scripts -->|"packages"| node_native_shell
node_build_scripts -->|"generates"| node_static_site

click node_web_root "https://github.com/nsk-syam/myig/blob/main/src/main.tsx"
click node_app_router "https://github.com/nsk-syam/myig/tree/main/src/pages"
click node_public_pages "https://github.com/nsk-syam/myig/blob/main/src/pages/Index.tsx"
click node_search_results "https://github.com/nsk-syam/myig/blob/main/src/pages/SearchResults.tsx"
click node_account_saved "https://github.com/nsk-syam/myig/blob/main/src/pages/Account.tsx"
click node_app_screens "https://github.com/nsk-syam/myig/tree/main/src/components/app"
click node_ui_shell "https://github.com/nsk-syam/myig/tree/main/src/components"
click node_state_hooks "https://github.com/nsk-syam/myig/tree/main/src/hooks"
click node_domain_libs "https://github.com/nsk-syam/myig/tree/main/src/lib"
click node_supabase_client "https://github.com/nsk-syam/myig/blob/main/src/integrations/supabase/client.ts"
click node_edge_auth "https://github.com/nsk-syam/myig/tree/main/supabase/functions"
click node_edge_pipeline "https://github.com/nsk-syam/myig/blob/main/supabase/functions/analyze-outfit/index.ts"
click node_edge_analytics "https://github.com/nsk-syam/myig/blob/main/supabase/functions/ingest-analytics/index.ts"
click node_edge_account "https://github.com/nsk-syam/myig/blob/main/supabase/functions/delete-account/index.ts"
click node_db_migrations "https://github.com/nsk-syam/myig/tree/main/supabase/migrations"
click node_native_shell "https://github.com/nsk-syam/myig/blob/main/ios/App/App/AppDelegate.swift"
click node_static_site "https://github.com/nsk-syam/myig/tree/main/public"
click node_build_scripts "https://github.com/nsk-syam/myig/tree/main/scripts"

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_web_root,node_app_router,node_public_pages,node_search_results,node_account_saved,node_app_screens,node_ui_shell,node_state_hooks,node_domain_libs,node_supabase_client toneBlue
class node_edge_auth,node_edge_pipeline,node_edge_analytics,node_edge_account,node_db_migrations toneAmber
class node_native_shell toneMint
class node_static_site,node_build_scripts toneRose
```

## Components

### Frontend app

React/Vite UI and client-side domain logic

- [Web shell](https://github.com/nsk-syam/myig/blob/main/src/main.tsx): Vite app · React entrypoint and app bootstrap · `src/main.tsx`
- [App routes](https://github.com/nsk-syam/myig/tree/main/src/pages): SPA routes · Primary public and authenticated screens · `src/pages`
- [Public pages](https://github.com/nsk-syam/myig/blob/main/src/pages/Index.tsx): marketing+legal · Landing, SEO, and policy pages · `src/pages/Index.tsx`
- [Search results](https://github.com/nsk-syam/myig/blob/main/src/pages/SearchResults.tsx): results view · Outfit result presentation and follow-up actions · `src/pages/SearchResults.tsx`
- [Account area](https://github.com/nsk-syam/myig/blob/main/src/pages/Account.tsx): authenticated views · Account, saved items, and analytics surfaces · `src/pages/Account.tsx`
- [App screens](https://github.com/nsk-syam/myig/tree/main/src/components/app): mobile UI · Home, premium, quota, and native-bridge screens · `src/components/app`
- [UI chrome](https://github.com/nsk-syam/myig/tree/main/src/components): shared components · Navigation, hero, footer, and shared presentation components · `src/components`
- [State hooks](https://github.com/nsk-syam/myig/tree/main/src/hooks): client state · Mobile detection, saved products, and search access hooks · `src/hooks`
- [Domain logic](https://github.com/nsk-syam/myig/tree/main/src/lib): business rules · Auth, access, analytics, search, product, and market helpers · `src/lib`
- [Supabase client](https://github.com/nsk-syam/myig/blob/main/src/integrations/supabase/client.ts): db client · Frontend Supabase integration and typed client · `src/integrations/supabase/client.ts`

### Supabase backend

Edge functions and database migrations

- [Access APIs](https://github.com/nsk-syam/myig/tree/main/supabase/functions): edge functions · Entitlements, tokens, and quota enforcement · `supabase/functions`
- [Search pipeline](https://github.com/nsk-syam/myig/blob/main/supabase/functions/analyze-outfit/index.ts): edge functions · Image ingestion, analysis, extraction, and product search · `supabase/functions/analyze-outfit/index.ts`
- [Analytics API](https://github.com/nsk-syam/myig/blob/main/supabase/functions/ingest-analytics/index.ts): edge functions · Event ingestion and analytics summaries · `supabase/functions/ingest-analytics/index.ts`
- [Account ops](https://github.com/nsk-syam/myig/blob/main/supabase/functions/delete-account/index.ts): edge functions · Account deletion and user-data cleanup · `supabase/functions/delete-account/index.ts`
- [Database schema](https://github.com/nsk-syam/myig/tree/main/supabase/migrations): migrations · Security, saved products, analytics, and search access schema · `supabase/migrations`

### iOS wrapper

Capacitor shell for the web app

- [iOS shell](https://github.com/nsk-syam/myig/blob/main/ios/App/App/AppDelegate.swift): Capacitor app · Native container around the shared web app · `ios/App/App/AppDelegate.swift`

### Delivery surface

Public marketing and SEO assets

- [Static site](https://github.com/nsk-syam/myig/tree/main/public): public assets · SEO pages, redirects, robots, sitemap, and app manifest · `public`
- [Build scripts](https://github.com/nsk-syam/myig/tree/main/scripts): release tooling · OG image generation and iOS packaging scripts · `scripts`

## Connections

- Web shell → App routes: boots · Renders the SPA and mounts routed pages
- App routes → Public pages: serves · Public landing, blog, privacy, and terms pages
- App routes → Search results: navigates · Shows analyzed outfit and product matches
- App routes → Account area: navigates · Account, saved items, and analytics surfaces
- App routes → App screens: uses · Mobile and premium app experiences
- UI chrome → App routes: frames · Shared navigation and page-level composition
- State hooks → Domain logic: derives from · Hooks wrap business logic and access checks
- Domain logic → Supabase client: queries · Reads auth state and app data from Supabase
- Domain logic → Access APIs: calls · Checks access, app entitlement, and quota state
- Domain logic → Search pipeline: calls · Submits images and requests outfit/product results
- Domain logic → Analytics API: emits · Sends analytics events and summaries
- Domain logic → Account ops: calls · Coordinates account deletion and cleanup
- Access APIs → Database schema: enforced by · Server-side access rules and search limits live in the database
- Search pipeline → Database schema: stores via · Uses persisted schema for saved/search-related data
- Analytics API → Database schema: aggregates from · Analytics events are stored and summarized in Postgres
- Supabase client → Database schema: targets · Frontend client reads the schema defined by migrations
- iOS shell → Web shell: wraps · Capacitor embeds the shared web application
- Static site → Public pages: publishes · Marketing and SEO content is served from the public directory
- Build scripts → iOS shell: packages · Release tooling supports native app builds
- Build scripts → Static site: generates · Scripts support SEO and preview asset generation
