# bigc7292/stonesightainew architecture

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

- Interactive diagram: https://gitdiagram.com/bigc7292/stonesightainew
- Repository: https://github.com/bigc7292/stonesightainew

## Overview

#### Purpose and Entry Points
StoneSight AI is a Vite/React client with a separate TypeScript Node backend for visualizing stone materials in interior imagery and generating image, video, and 3D outputs. Frontend bootstraps at `src/main.tsx` into `src/App.tsx`; backend bootstraps at `server/server.ts`. Local development is initiated through the root `package.json`.

#### Client Application and Session Boundary
The React application owns interactive workflow state, rendering, galleries, and authenticated-user context. Authentication is modeled through `src/auth/AuthContext.tsx`, with login UI in `src/auth/LoginPage.tsx`; Supabase client integration is centralized in `src/lib/supabase.ts`. App features should consume this boundary rather than directly coupling UI to persistence/auth APIs.

#### Stone Catalog and Visualization UI
Stone choices and associated local assets are represented by `src/stones.ts`, backed by material directories such as `public/Dekton`, `public/granite`, and `public/quartz`. The primary result presentation layer includes `src/components/GenerationGallery.tsx`, `src/components/BeforeAfterSlider.tsx`, and `src/components/SplatViewer3D.tsx`, separating generated-media display from generation orchestration.

#### Generation Orchestration
Client-side service modules form the generation API boundary: `src/services/generationService.ts` handles paid/main generation workflows, while `src/services/freeGenerationService.ts` handles the free 3D path. `src/services/aiMemoryService.ts` indicates persistent or reusable AI context. These services should mediate calls from `src/App.tsx` to backend routes, rather than embedding provider logic in components.

#### Backend API Stages
The Node server exposes capability-oriented HTTP routes:
- Image generation/editing: `server/routes/image.ts`
- Video generation: `server/routes/video.ts`
- Primary 3D generation: `server/routes/3d.ts`
- Free 3D/splat conversion: `server/routes/3d-free.ts`

`server/server.ts` composes these routes, while `server/middleware/auth.ts` protects backend operations. This is the trust boundary for secrets, provider credentials, input validation, job submission, and provider-response normalization.

#### AI Providers and Media Pipeline
The README identifies NVIDIA NIM and Cosmos 3 as material external AI infrastructure, configured through `NVIDIA_API_KEY`. Repository artifacts such as `ai_logic.json`, `bucket_config.json`, and `metadata.json`, plus setup documents `docs/image-pipeline-setup.md` and `docs/video-pipeline-setup.md`, indicate multi-stage image/video generation and storage pipeline concerns. 3D output is represented as PLY assets, including `public/demo_trellis_1784532841222.ply` and `test.ply`.

#### Persistence, Storage, and Deployment Assets
Supabase is the apparent authentication and object-storage backend, accessed via `src/lib/supabase.ts`, `src/services/supabaseAuth.ts`, and `src/services/supabaseStorage.ts`; schema/bootstrap material resides in `supabase-setup.sql`. Public media is served from `public/`, while generated artifacts likely move through Supabase storage before being rendered in the gallery/viewer. Environment-specific secrets remain outside the client, with `.env.example` documenting required configuration.

Main entry points: [`server/server.ts`](https://github.com/bigc7292/stonesightainew/blob/main/server/server.ts) (API server), [`src/App.tsx`](https://github.com/bigc7292/stonesightainew/blob/main/src/App.tsx) (Workflow application), [`src/components/GenerationGallery.tsx`](https://github.com/bigc7292/stonesightainew/blob/main/src/components/GenerationGallery.tsx) (Generation gallery), [`src/auth/AuthContext.tsx`](https://github.com/bigc7292/stonesightainew/blob/main/src/auth/AuthContext.tsx) (Auth context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_main["Client bootstrap<br/>Vite entry<br/>[main.tsx]"]
  node_app["Workflow application<br/>React app<br/>[App.tsx]"]
  node_auth_context["Auth context<br/>session boundary<br/>[AuthContext.tsx]"]
  node_login["Login UI<br/>React page<br/>[LoginPage.tsx]"]
  node_catalog["Stone catalog<br/>material data<br/>[stones.ts]"]
  node_material_assets["Material assets<br/>public media"]
  node_generation_service["Paid generation API<br/>client service"]
  node_free_3d_service["Free 3D API<br/>client service"]
  node_ai_memory["AI memory service<br/>client service<br/>[aiMemoryService.ts]"]
  node_gallery["Generation gallery<br/>result UI"]
  node_comparison["Before/after viewer<br/>result UI"]
  node_splat_viewer["3D splat viewer<br/>result UI<br/>[SplatViewer3D.tsx]"]
end

subgraph group_backend["Node API"]
  node_server["API server<br/>Node entry<br/>[server.ts]"]
  node_api_auth["API authentication<br/>middleware<br/>[auth.ts]"]
  node_image_route["Image generation<br/>HTTP route<br/>[image.ts]"]
  node_video_route["Video generation<br/>HTTP route<br/>[video.ts]"]
  node_three_d_route["Primary 3D generation<br/>HTTP route<br/>[3d.ts]"]
  node_free_3d_route["Free 3D conversion<br/>HTTP route<br/>[3d-free.ts]"]
end

subgraph group_platform["External Platform"]
  node_supabase_client["Supabase client<br/>client integration<br/>[supabase.ts]"]
  node_supabase[("Supabase<br/>auth and object storage<br/>[supabase-setup.sql]")]
  node_nvidia{{"NVIDIA NIM / Cosmos 3<br/>AI provider"}}
end

node_dev["Local development<br/>npm scripts<br/>[package.json]"]

node_dev -->|"starts client"| node_main
node_dev -->|"starts API"| node_server
node_main -->|"mounts"| node_app
node_app -->|"uses session"| node_auth_context
node_login -->|"signs in through"| node_auth_context
node_auth_context -->|"uses"| node_supabase_client
node_supabase_client -->|"connects to"| node_supabase
node_app -->|"selects material"| node_catalog
node_catalog -->|"references"| node_material_assets
node_app -->|"requests generation"| node_generation_service
node_app -->|"requests free 3D"| node_free_3d_service
node_app -->|"uses context"| node_ai_memory
node_app -->|"renders results"| node_gallery
node_gallery -->|"presents image results"| node_comparison
node_gallery -->|"presents 3D results"| node_splat_viewer
node_generation_service -->|"calls protected API"| node_server
node_free_3d_service -->|"calls protected API"| node_server
node_server -->|"applies"| node_api_auth
node_server -->|"mounts"| node_image_route
node_server -->|"mounts"| node_video_route
node_server -->|"mounts"| node_three_d_route
node_server -->|"mounts"| node_free_3d_route
node_image_route -->|"submits jobs"| node_nvidia
node_video_route -->|"submits jobs"| node_nvidia
node_three_d_route -->|"submits jobs"| node_nvidia
node_free_3d_route -->|"converts media"| node_nvidia
node_server -->|"stores generated artifacts"| node_supabase
node_supabase -->|"serves generated media"| node_gallery

click node_dev "https://github.com/bigc7292/stonesightainew/blob/main/package.json"
click node_main "https://github.com/bigc7292/stonesightainew/blob/main/src/main.tsx"
click node_app "https://github.com/bigc7292/stonesightainew/blob/main/src/App.tsx"
click node_auth_context "https://github.com/bigc7292/stonesightainew/blob/main/src/auth/AuthContext.tsx"
click node_login "https://github.com/bigc7292/stonesightainew/blob/main/src/auth/LoginPage.tsx"
click node_catalog "https://github.com/bigc7292/stonesightainew/blob/main/src/stones.ts"
click node_material_assets "https://github.com/bigc7292/stonesightainew/tree/main/public/Dekton"
click node_generation_service "https://github.com/bigc7292/stonesightainew/blob/main/src/services/generationService.ts"
click node_free_3d_service "https://github.com/bigc7292/stonesightainew/blob/main/src/services/freeGenerationService.ts"
click node_ai_memory "https://github.com/bigc7292/stonesightainew/blob/main/src/services/aiMemoryService.ts"
click node_gallery "https://github.com/bigc7292/stonesightainew/blob/main/src/components/GenerationGallery.tsx"
click node_comparison "https://github.com/bigc7292/stonesightainew/blob/main/src/components/BeforeAfterSlider.tsx"
click node_splat_viewer "https://github.com/bigc7292/stonesightainew/blob/main/src/components/SplatViewer3D.tsx"
click node_server "https://github.com/bigc7292/stonesightainew/blob/main/server/server.ts"
click node_api_auth "https://github.com/bigc7292/stonesightainew/blob/main/server/middleware/auth.ts"
click node_image_route "https://github.com/bigc7292/stonesightainew/blob/main/server/routes/image.ts"
click node_video_route "https://github.com/bigc7292/stonesightainew/blob/main/server/routes/video.ts"
click node_three_d_route "https://github.com/bigc7292/stonesightainew/blob/main/server/routes/3d.ts"
click node_free_3d_route "https://github.com/bigc7292/stonesightainew/blob/main/server/routes/3d-free.ts"
click node_supabase_client "https://github.com/bigc7292/stonesightainew/blob/main/src/lib/supabase.ts"
click node_supabase "https://github.com/bigc7292/stonesightainew/blob/main/supabase-setup.sql"

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_main,node_app,node_auth_context,node_login,node_catalog,node_material_assets,node_generation_service,node_free_3d_service,node_ai_memory,node_gallery,node_comparison,node_splat_viewer toneBlue
class node_server,node_api_auth,node_image_route,node_video_route,node_three_d_route,node_free_3d_route toneAmber
class node_supabase_client,node_supabase,node_nvidia toneMint
class node_dev toneNeutral
```

## Components

### React Client

Interactive material-selection and generation workflow.

- [Client bootstrap](https://github.com/bigc7292/stonesightainew/blob/main/src/main.tsx): Vite entry · `src/main.tsx`
- [Workflow application](https://github.com/bigc7292/stonesightainew/blob/main/src/App.tsx): React app · Owns interactive generation workflow state. · `src/App.tsx`
- [Auth context](https://github.com/bigc7292/stonesightainew/blob/main/src/auth/AuthContext.tsx): session boundary · Provides authenticated-user context to client features. · `src/auth/AuthContext.tsx`
- [Login UI](https://github.com/bigc7292/stonesightainew/blob/main/src/auth/LoginPage.tsx): React page · `src/auth/LoginPage.tsx`
- [Stone catalog](https://github.com/bigc7292/stonesightainew/blob/main/src/stones.ts): material data · Maps stone choices to local material assets. · `src/stones.ts`
- [Material assets](https://github.com/bigc7292/stonesightainew/tree/main/public/Dekton): public media · `public/Dekton`
- [Paid generation API](https://github.com/bigc7292/stonesightainew/blob/main/src/services/generationService.ts): client service · Mediates main image, video, and 3D workflows. · `src/services/generationService.ts`
- [Free 3D API](https://github.com/bigc7292/stonesightainew/blob/main/src/services/freeGenerationService.ts): client service · Mediates free splat conversion. · `src/services/freeGenerationService.ts`
- [AI memory service](https://github.com/bigc7292/stonesightainew/blob/main/src/services/aiMemoryService.ts): client service · Manages reusable AI context. · `src/services/aiMemoryService.ts`
- [Generation gallery](https://github.com/bigc7292/stonesightainew/blob/main/src/components/GenerationGallery.tsx): result UI · `src/components/GenerationGallery.tsx`
- [Before/after viewer](https://github.com/bigc7292/stonesightainew/blob/main/src/components/BeforeAfterSlider.tsx): result UI · `src/components/BeforeAfterSlider.tsx`
- [3D splat viewer](https://github.com/bigc7292/stonesightainew/blob/main/src/components/SplatViewer3D.tsx): result UI · `src/components/SplatViewer3D.tsx`

### Node API

Protected generation capability boundary.

- [API server](https://github.com/bigc7292/stonesightainew/blob/main/server/server.ts): Node entry · Composes capability routes. · `server/server.ts`
- [API authentication](https://github.com/bigc7292/stonesightainew/blob/main/server/middleware/auth.ts): middleware · Protects backend operations before provider access. · `server/middleware/auth.ts`
- [Image generation](https://github.com/bigc7292/stonesightainew/blob/main/server/routes/image.ts): HTTP route · `server/routes/image.ts`
- [Video generation](https://github.com/bigc7292/stonesightainew/blob/main/server/routes/video.ts): HTTP route · `server/routes/video.ts`
- [Primary 3D generation](https://github.com/bigc7292/stonesightainew/blob/main/server/routes/3d.ts): HTTP route · `server/routes/3d.ts`
- [Free 3D conversion](https://github.com/bigc7292/stonesightainew/blob/main/server/routes/3d-free.ts): HTTP route · `server/routes/3d-free.ts`

### External Platform

Identity, storage, and AI infrastructure.

- [Supabase client](https://github.com/bigc7292/stonesightainew/blob/main/src/lib/supabase.ts): client integration · Central client access to authentication and storage. · `src/lib/supabase.ts`
- [Supabase](https://github.com/bigc7292/stonesightainew/blob/main/supabase-setup.sql): auth and object storage · Stores identity and generated media artifacts. · `supabase-setup.sql`
- **NVIDIA NIM / Cosmos 3**: AI provider · External image, video, and 3D generation infrastructure.

### Other components

- [Local development](https://github.com/bigc7292/stonesightainew/blob/main/package.json): npm scripts · `package.json`

## Connections

- Local development → Client bootstrap: starts client
- Local development → API server: starts API
- Client bootstrap → Workflow application: mounts
- Workflow application → Auth context: uses session
- Login UI → Auth context: signs in through
- Auth context → Supabase client: uses
- Supabase client → Supabase: connects to
- Workflow application → Stone catalog: selects material
- Stone catalog → Material assets: references
- Workflow application → Paid generation API: requests generation
- Workflow application → Free 3D API: requests free 3D
- Workflow application → AI memory service: uses context
- Workflow application → Generation gallery: renders results
- Generation gallery → Before/after viewer: presents image results
- Generation gallery → 3D splat viewer: presents 3D results
- Paid generation API → API server: calls protected API
- Free 3D API → API server: calls protected API
- API server → API authentication: applies
- API server → Image generation: mounts
- API server → Video generation: mounts
- API server → Primary 3D generation: mounts
- API server → Free 3D conversion: mounts
- Image generation → NVIDIA NIM / Cosmos 3: submits jobs
- Video generation → NVIDIA NIM / Cosmos 3: submits jobs
- Primary 3D generation → NVIDIA NIM / Cosmos 3: submits jobs
- Free 3D conversion → NVIDIA NIM / Cosmos 3: converts media
- API server → Supabase: stores generated artifacts
- Supabase → Generation gallery: serves generated media
