# mtcto/cadam architecture

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

- Interactive diagram: https://gitdiagram.com/mtcto/cadam
- Repository: https://github.com/mtcto/cadam

## Overview

CADAM is a browser-based text-to-CAD application: users describe or reference a model, receive AI-generated parametric OpenSCAD, adjust dimensions, preview the result, and export it. The graph preserves the documented image-input, library, and export capabilities alongside the chat, rendering, and persistence layers. Several server and parameter-generation links are documented only at product level; those relationships are shown as unverified where source excerpts do not establish their wiring.

Main entry points: [`src/components/chat/ChatSession.tsx`](https://github.com/mtcto/cadam/blob/master/src/components/chat/ChatSession.tsx) (Chat session), [`src/components/viewer/MeshPreview.tsx`](https://github.com/mtcto/cadam/blob/master/src/components/viewer/MeshPreview.tsx) (3D preview), [`src/components/TextAreaChat.tsx`](https://github.com/mtcto/cadam/blob/master/src/components/TextAreaChat.tsx) (Prompt and images), [`src/lib/supabase.ts`](https://github.com/mtcto/cadam/blob/master/src/lib/supabase.ts) (Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_app["Application shell<br/>[App.tsx]"]
  node_chat["Chat session<br/>[ChatSession.tsx]"]
  node_prompt["Prompt and images<br/>[TextAreaChat.tsx]"]
  node_message["Message display<br/>[MessageBubble.tsx]"]
end

subgraph group_generation["Model generation"]
  node_api["Generation API"]
  node_ai["AI chat orchestration<br/>[aiChat.ts]"]
  node_paramparse["Parameter extraction<br/>[parseParameters.ts]"]
end

subgraph group_modeling["Model editing and preview"]
  node_parametric["Parametric controls"]
  node_editor["Model editor<br/>[EditorView.tsx]"]
  node_viewer["3D preview<br/>[MeshPreview.tsx]"]
  node_exports["Model export<br/>[DownloadMenu.tsx]"]
end

subgraph group_platform["Identity and persistence"]
  node_meshdata["Mesh data access<br/>[useMeshData.ts]"]
  node_messages["Message persistence<br/>[messageService.ts]"]
  node_supabase["Supabase client<br/>[supabase.ts]"]
  node_auth["Authentication provider<br/>[AuthProvider.tsx]"]
end

subgraph group_compute["Browser computation"]
  node_toolworker["Tool execution worker<br/>[toolWorker.ts]"]
  node_openscad["OpenSCAD worker<br/>[worker.ts]"]
end

node_user(("CADAM user"))
node_database[("Supabase backend")]

node_user -->|"describes model"| node_prompt
node_prompt -.->|"submits prompt"| node_chat
node_chat -->|"renders input"| node_prompt
node_chat -->|"renders messages"| node_message
node_chat -->|"executes tools"| node_toolworker
node_chat -->|"persists messages"| node_messages
node_chat -.->|"requests generation"| node_ai
node_ai -.->|"serves generation"| node_api
node_ai -.->|"extracts parameters"| node_paramparse
node_user -->|"adjusts model"| node_editor
node_editor -.->|"offers controls"| node_parametric
node_editor -.->|"shows preview"| node_viewer
node_viewer -->|"offers downloads"| node_exports
node_viewer -->|"loads mesh"| node_meshdata
node_meshdata -->|"reads mesh data"| node_supabase
node_messages -->|"reads and writes"| node_supabase
node_supabase -.->|"accesses backend"| node_database
node_toolworker -->|"dispatches preview"| node_openscad
node_auth -->|"uses client"| node_supabase
node_app -->|"provides auth"| node_auth
node_user -->|"views generated model"| node_viewer
node_user -->|"adds image reference"| node_prompt
node_user -->|"exports model"| node_exports

click node_app "https://github.com/mtcto/cadam/blob/master/src/App.tsx"
click node_chat "https://github.com/mtcto/cadam/blob/master/src/components/chat/ChatSession.tsx"
click node_prompt "https://github.com/mtcto/cadam/blob/master/src/components/TextAreaChat.tsx"
click node_message "https://github.com/mtcto/cadam/blob/master/src/components/chat/MessageBubble.tsx"
click node_api "https://github.com/mtcto/cadam/tree/master/src/routes/api"
click node_ai "https://github.com/mtcto/cadam/blob/master/src/server/aiChat.ts"
click node_paramparse "https://github.com/mtcto/cadam/blob/master/shared/parseParameters.ts"
click node_parametric "https://github.com/mtcto/cadam/tree/master/src/components/parameter"
click node_editor "https://github.com/mtcto/cadam/blob/master/src/views/EditorView.tsx"
click node_viewer "https://github.com/mtcto/cadam/blob/master/src/components/viewer/MeshPreview.tsx"
click node_exports "https://github.com/mtcto/cadam/blob/master/src/components/viewer/DownloadMenu.tsx"
click node_meshdata "https://github.com/mtcto/cadam/blob/master/src/hooks/useMeshData.ts"
click node_messages "https://github.com/mtcto/cadam/blob/master/src/services/messageService.ts"
click node_supabase "https://github.com/mtcto/cadam/blob/master/src/lib/supabase.ts"
click node_toolworker "https://github.com/mtcto/cadam/blob/master/src/worker/toolWorker.ts"
click node_openscad "https://github.com/mtcto/cadam/blob/master/src/worker/worker.ts"
click node_auth "https://github.com/mtcto/cadam/blob/master/src/contexts/AuthProvider.tsx"

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,node_chat,node_prompt,node_message,node_user toneBlue
class node_api,node_ai,node_paramparse,node_database toneAmber
class node_parametric,node_editor,node_viewer,node_exports toneMint
class node_meshdata,node_messages,node_supabase,node_auth toneRose
class node_toolworker,node_openscad toneIndigo
```

## Components

### User experience

- [Application shell](https://github.com/mtcto/cadam/blob/master/src/App.tsx): `src/App.tsx`
- [Chat session](https://github.com/mtcto/cadam/blob/master/src/components/chat/ChatSession.tsx): `src/components/chat/ChatSession.tsx`
- [Prompt and images](https://github.com/mtcto/cadam/blob/master/src/components/TextAreaChat.tsx): `src/components/TextAreaChat.tsx`
- [Message display](https://github.com/mtcto/cadam/blob/master/src/components/chat/MessageBubble.tsx): `src/components/chat/MessageBubble.tsx`

### Model generation

- [Generation API](https://github.com/mtcto/cadam/tree/master/src/routes/api): `src/routes/api`
- [AI chat orchestration](https://github.com/mtcto/cadam/blob/master/src/server/aiChat.ts): `src/server/aiChat.ts`
- [Parameter extraction](https://github.com/mtcto/cadam/blob/master/shared/parseParameters.ts): `shared/parseParameters.ts`

### Model editing and preview

- [Parametric controls](https://github.com/mtcto/cadam/tree/master/src/components/parameter): `src/components/parameter`
- [Model editor](https://github.com/mtcto/cadam/blob/master/src/views/EditorView.tsx): `src/views/EditorView.tsx`
- [3D preview](https://github.com/mtcto/cadam/blob/master/src/components/viewer/MeshPreview.tsx): `src/components/viewer/MeshPreview.tsx`
- [Model export](https://github.com/mtcto/cadam/blob/master/src/components/viewer/DownloadMenu.tsx): `src/components/viewer/DownloadMenu.tsx`

### Identity and persistence

- [Mesh data access](https://github.com/mtcto/cadam/blob/master/src/hooks/useMeshData.ts): `src/hooks/useMeshData.ts`
- [Message persistence](https://github.com/mtcto/cadam/blob/master/src/services/messageService.ts): `src/services/messageService.ts`
- [Supabase client](https://github.com/mtcto/cadam/blob/master/src/lib/supabase.ts): `src/lib/supabase.ts`
- [Authentication provider](https://github.com/mtcto/cadam/blob/master/src/contexts/AuthProvider.tsx): `src/contexts/AuthProvider.tsx`

### Browser computation

- [Tool execution worker](https://github.com/mtcto/cadam/blob/master/src/worker/toolWorker.ts): `src/worker/toolWorker.ts`
- [OpenSCAD worker](https://github.com/mtcto/cadam/blob/master/src/worker/worker.ts): `src/worker/worker.ts`

### Other components

- **CADAM user**
- **Supabase backend**

## Connections

- CADAM user → Prompt and images: describes model (evidence: `README.md`)
- Prompt and images → Chat session: submits prompt (evidence: `src/components/chat/ChatSession.tsx`)
- Chat session → Prompt and images: renders input (evidence: `src/components/chat/ChatSession.tsx`)
- Chat session → Message display: renders messages (evidence: `src/components/chat/ChatSession.tsx`)
- Chat session → Tool execution worker: executes tools (evidence: `src/components/chat/ChatSession.tsx`)
- Chat session → Message persistence: persists messages (evidence: `src/components/chat/ChatSession.tsx`)
- Chat session → AI chat orchestration: requests generation
- AI chat orchestration → Generation API: serves generation
- AI chat orchestration → Parameter extraction: extracts parameters
- CADAM user → Model editor: adjusts model (evidence: `README.md`)
- Model editor → Parametric controls: offers controls
- Model editor → 3D preview: shows preview
- 3D preview → Model export: offers downloads (evidence: `src/components/viewer/MeshPreview.tsx`)
- 3D preview → Mesh data access: loads mesh (evidence: `src/components/viewer/MeshPreview.tsx`)
- Mesh data access → Supabase client: reads mesh data (evidence: `src/hooks/useMeshData.ts`)
- Message persistence → Supabase client: reads and writes (evidence: `src/services/messageService.ts`)
- Supabase client → Supabase backend: accesses backend
- Tool execution worker → OpenSCAD worker: dispatches preview (evidence: `src/worker/toolWorker.ts`)
- Authentication provider → Supabase client: uses client (evidence: `src/contexts/AuthProvider.tsx`)
- Application shell → Authentication provider: provides auth (evidence: `src/App.tsx`)
- CADAM user → 3D preview: views generated model (evidence: `README.md`)
- CADAM user → Prompt and images: adds image reference (evidence: `README.md`)
- CADAM user → Model export: exports model (evidence: `README.md`)
