# sahilsharma-stage/figma-ai-generator architecture

> Architecture diagram of the GitHub repository sahilsharma-stage/figma-ai-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sahilsharma-stage/figma-ai-generator
- Repository: https://github.com/sahilsharma-stage/figma-ai-generator

## Overview

Figma AI Design Generator turns prompts and optional screenshots into validated design specifications, then supports viewing or generating them in Figma. Users can start through the CLI or web UI; screenshot analysis and AI generation are distinct stages, followed by spec validation. The plugin accepts a spec and renders it onto the Figma canvas. Relationships are grounded in the README and shown source/index references; web UI request wiring and some plugin UI details are documented but unsampled.

Main entry points: [`src/ai/generator.ts`](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/generator.ts) (Spec Generator), [`src/server.ts`](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/server.ts) (Web API), [`src/cli.ts`](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/cli.ts) (CLI Commands), [`src/ai/analyzer.ts`](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/analyzer.ts) (Screenshot Analyzer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User Entry Points"]
  node_cli["CLI Commands<br/>[cli.ts]"]
  node_webui["Web UI<br/>[index.html]"]
end

subgraph group_ai["AI Design Pipeline"]
  node_analyzer["Screenshot Analyzer<br/>[analyzer.ts]"]
  node_generator["Spec Generator<br/>[generator.ts]"]
  node_prompts["AI Prompts<br/>[prompts.ts]"]
end

subgraph group_spec["Specification System"]
  node_defaults["Design Tokens<br/>[defaults.ts]"]
  node_validator["Spec Validator<br/>[validator.ts]"]
  node_spec["Design Spec<br/>[types.ts]"]
end

subgraph group_delivery["Web And Figma Delivery"]
  node_server["Web API<br/>[server.ts]"]
  node_specstore[("Stored Specs<br/>[server.ts]")]
  node_pluginui["Plugin UI<br/>[ui.html]"]
  node_plugin["Plugin Main<br/>[code.ts]"]
  node_renderer["Figma Renderer<br/>[renderer.ts]"]
end

node_user(("Designer"))
node_anthropic["Anthropic Claude"]
node_figma["Figma Canvas"]

node_user -->|"runs commands"| node_cli
node_user -->|"submits prompt"| node_webui
node_user -->|"provides spec"| node_pluginui
node_cli -->|"generates specs"| node_generator
node_cli -->|"analyzes screenshots"| node_analyzer
node_cli -->|"starts server"| node_server
node_cli -->|"validates specs"| node_validator
node_webui -->|"calls API"| node_server
node_server -->|"generates specs"| node_generator
node_server -->|"analyzes screenshots"| node_analyzer
node_server -->|"validates specs"| node_validator
node_server -->|"stores and retrieves"| node_specstore
node_server -->|"serves tokens"| node_defaults
node_generator -->|"analyzes references"| node_analyzer
node_generator -->|"builds prompts"| node_prompts
node_generator -->|"uses defaults"| node_defaults
node_generator -->|"validates output"| node_validator
node_analyzer -->|"analyzes images"| node_anthropic
node_generator -->|"requests generation"| node_anthropic
node_pluginui -->|"sends spec"| node_plugin
node_plugin -->|"renders spec"| node_renderer
node_renderer -->|"creates canvas nodes"| node_figma

click node_cli "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/cli.ts"
click node_webui "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/web/index.html"
click node_server "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/server.ts"
click node_analyzer "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/analyzer.ts"
click node_generator "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/generator.ts"
click node_prompts "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/prompts.ts"
click node_defaults "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/defaults.ts"
click node_validator "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/validator.ts"
click node_spec "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/types.ts"
click node_specstore "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/server.ts"
click node_pluginui "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/ui.html"
click node_plugin "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/code.ts"
click node_renderer "https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/renderer.ts"

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_cli,node_webui toneBlue
class node_analyzer,node_generator,node_prompts toneAmber
class node_defaults,node_validator,node_spec toneMint
class node_server,node_specstore,node_pluginui,node_plugin,node_renderer toneRose
class node_user,node_anthropic,node_figma toneIndigo
```

## Components

### User Entry Points

- [CLI Commands](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/cli.ts): `src/cli.ts`
- [Web UI](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/web/index.html): `src/web/index.html`

### AI Design Pipeline

- [Screenshot Analyzer](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/analyzer.ts): `src/ai/analyzer.ts`
- [Spec Generator](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/generator.ts): `src/ai/generator.ts`
- [AI Prompts](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/ai/prompts.ts): `src/ai/prompts.ts`

### Specification System

- [Design Tokens](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/defaults.ts): `src/spec/defaults.ts`
- [Spec Validator](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/validator.ts): `src/spec/validator.ts`
- [Design Spec](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/spec/types.ts): `src/spec/types.ts`

### Web And Figma Delivery

- [Web API](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/server.ts): `src/server.ts`
- [Stored Specs](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/src/server.ts): `src/server.ts`
- [Plugin UI](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/ui.html): `figma-plugin/src/ui.html`
- [Plugin Main](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/code.ts): `figma-plugin/src/code.ts`
- [Figma Renderer](https://github.com/sahilsharma-stage/figma-ai-generator/blob/master/figma-plugin/src/renderer.ts): `figma-plugin/src/renderer.ts`

### Other components

- **Designer**
- **Anthropic Claude**
- **Figma Canvas**

## Connections

- Designer → CLI Commands: runs commands (evidence: `README.md`)
- Designer → Web UI: submits prompt (evidence: `README.md`)
- Designer → Plugin UI: provides spec (evidence: `README.md`)
- CLI Commands → Spec Generator: generates specs (evidence: `src/cli.ts`)
- CLI Commands → Screenshot Analyzer: analyzes screenshots (evidence: `src/cli.ts`)
- CLI Commands → Web API: starts server (evidence: `src/cli.ts`)
- CLI Commands → Spec Validator: validates specs (evidence: `src/cli.ts`)
- Web UI → Web API: calls API (evidence: `README.md`)
- Web API → Spec Generator: generates specs (evidence: `src/server.ts`)
- Web API → Screenshot Analyzer: analyzes screenshots (evidence: `src/server.ts`)
- Web API → Spec Validator: validates specs (evidence: `src/server.ts`)
- Web API → Stored Specs: stores and retrieves (evidence: `README.md`)
- Web API → Design Tokens: serves tokens (evidence: `README.md`)
- Spec Generator → Screenshot Analyzer: analyzes references (evidence: `src/ai/generator.ts`)
- Spec Generator → AI Prompts: builds prompts (evidence: `src/ai/generator.ts`)
- Spec Generator → Design Tokens: uses defaults (evidence: `src/ai/generator.ts`)
- Spec Generator → Spec Validator: validates output (evidence: `src/ai/generator.ts`)
- Screenshot Analyzer → Anthropic Claude: analyzes images (evidence: `src/ai/analyzer.ts`)
- Spec Generator → Anthropic Claude: requests generation (evidence: `src/ai/generator.ts`)
- Plugin UI → Plugin Main: sends spec (evidence: `README.md`)
- Plugin Main → Figma Renderer: renders spec (evidence: `figma-plugin/src/code.ts`)
- Figma Renderer → Figma Canvas: creates canvas nodes (evidence: `figma-plugin/src/renderer.ts`)
