# mallahyari/system-design-visualizer architecture

> Architecture diagram of the GitHub repository mallahyari/system-design-visualizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mallahyari/system-design-visualizer
- Repository: https://github.com/mallahyari/system-design-visualizer

## Overview

#### Purpose and runtime
System Design Visualizer is a browser-only React/Vite application that turns an uploaded architecture image into AI-generated Mermaid source, then an interactive node graph with inferred component details. It runs locally via Vite; OpenAI GPT-4o is called from the client when `VITE_OPENAI_API_KEY` is available, otherwise the analysis layer supplies mock data.

Entry points: `index.html`, `src/main.jsx`, and `src/App.jsx`.

#### Application orchestration
`src/App.jsx` owns the user workflow and switches between upload/review/interactive-graph views. It coordinates image input, generated Mermaid text, conversion to graph data, selected-node state, and panel visibility. Global styling is established in `src/index.css`.

#### Image ingestion and analysis boundary
`src/components/UploadZone.jsx` provides drag/drop or file selection and passes the image into the application flow. `src/services/analysisService.js` is the primary external-service boundary: it prepares image analysis requests, invokes OpenAI Vision/code generation, and returns Mermaid-oriented analysis plus component metadata. It also supports the documented mock-mode fallback.

The API key is injected at Vite build/runtime through `.env.example` conventions; there is no server-side proxy shown in this tree.

#### Mermaid review stage
Generated diagram text is displayed and rendered by `src/components/MermaidDisplay.jsx`. This is the editable/reviewable intermediate representation between AI inference and graph construction: users can inspect Mermaid output, preview it, and trigger conversion. Mermaid.js is the diagram rendering runtime.

#### Interactive graph stage
`src/components/SystemDiagram.jsx` converts or consumes Mermaid-derived topology as a React Flow graph, providing pan/zoom and graph interaction. Node rendering is specialized through `src/components/CustomNodes.jsx`, with supported node mappings/types centralized in `src/config/nodeTypes.js`.

React Flow is the main graph runtime and establishes the interaction boundary between topology data and UI-specific node presentation.

#### Component exploration
Selecting an interactive graph node drives `src/components/InfoPanel.jsx`, which presents inferred role, technology, or related architecture details. This metadata originates from the analysis result and is associated with the graph node identity through the conversion/display flow.

#### Theme and presentation state
Theme state is provided through `src/contexts/ThemeContext.jsx` and its definition file `src/contexts/ThemeContextDef.js`, consumed via `src/hooks/useTheme.js`. `src/components/ThemeToggle.jsx` changes the active theme, while `src/themes/index.js` defines theme-level presentation values. This is UI-global state, separate from diagram and analysis state.

#### Key flow
Image → `UploadZone` → `analysisService` (OpenAI or mock) → Mermaid source/metadata → `MermaidDisplay` review → `SystemDiagram` React Flow topology → node selection → `InfoPanel` details. The critical trust and security boundary is client-side use of the configured OpenAI key; production deployment would need a server-side analysis proxy to avoid exposing that credential.

Main entry points: [`src/App.jsx`](https://github.com/mallahyari/system-design-visualizer/blob/main/src/App.jsx) (App workflow), [`src/contexts/ThemeContext.jsx`](https://github.com/mallahyari/system-design-visualizer/blob/main/src/contexts/ThemeContext.jsx) (Theme provider), [`src/services/analysisService.js`](https://github.com/mallahyari/system-design-visualizer/blob/main/src/services/analysisService.js) (Analysis service), [`src/components/SystemDiagram.jsx`](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/SystemDiagram.jsx) (Interactive graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application shell"]
  node_index["Vite entry<br/>HTML entry<br/>[index.html]"]
  node_main["React bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app_root["App workflow<br/>React orchestrator<br/>[App.jsx]"]
  node_styles["Global styles<br/>CSS<br/>[index.css]"]
end

subgraph group_analysis["Image analysis"]
  node_upload["Upload zone<br/>React component<br/>[UploadZone.jsx]"]
  node_analysis_service{{"Analysis service<br/>client AI service<br/>[analysisService.js]"}}
  node_openai{{"OpenAI Vision / GPT-4o<br/>external AI API"}}
  node_env["API key convention<br/>environment config<br/>[.env.example]"]
end

subgraph group_visualization["Diagram pipeline"]
  node_mermaid_display["Mermaid review<br/>React component<br/>[MermaidDisplay.jsx]"]
  node_mermaid["Mermaid.js<br/>diagram runtime"]
  node_system_diagram["Interactive graph<br/>React Flow component<br/>[SystemDiagram.jsx]"]
  node_react_flow["React Flow<br/>graph runtime"]
  node_custom_nodes["Custom node renderers<br/>React components<br/>[CustomNodes.jsx]"]
  node_node_types["Node type mappings<br/>graph config<br/>[nodeTypes.js]"]
  node_info_panel["Component details<br/>React component<br/>[InfoPanel.jsx]"]
end

subgraph group_theme["Theme state"]
  node_theme_context["Theme provider<br/>React context<br/>[ThemeContext.jsx]"]
  node_theme_definition["Theme context definition<br/>[ThemeContextDef.js]"]
  node_use_theme["Theme hook<br/>React hook<br/>[useTheme.js]"]
  node_theme_toggle["Theme toggle<br/>React component<br/>[ThemeToggle.jsx]"]
  node_themes["Theme values<br/>theme definitions<br/>[index.js]"]
end

node_index -->|"loads"| node_main
node_main -->|"mounts"| node_app_root
node_main -->|"provides"| node_theme_context
node_styles -->|"styles"| node_app_root
node_app_root -->|"image input"| node_upload
node_upload -->|"image"| node_analysis_service
node_env -.->|"API key"| node_analysis_service
node_analysis_service -->|"vision/code request"| node_openai
node_analysis_service -->|"Mermaid and metadata"| node_app_root
node_app_root -->|"generated source"| node_mermaid_display
node_mermaid_display -->|"renders preview"| node_mermaid
node_mermaid_display -->|"approved Mermaid topology"| node_system_diagram
node_system_diagram -->|"interactive graph"| node_react_flow
node_node_types -->|"maps types"| node_custom_nodes
node_custom_nodes -->|"node presentation"| node_system_diagram
node_system_diagram -->|"selected node"| node_app_root
node_app_root -->|"selection and metadata"| node_info_panel
node_theme_definition -->|"defines context"| node_theme_context
node_themes -->|"presentation values"| node_theme_context
node_theme_context -->|"consumed through"| node_use_theme
node_use_theme -->|"reads and updates"| node_theme_toggle
node_theme_toggle -->|"changes theme"| node_theme_context

click node_index "https://github.com/mallahyari/system-design-visualizer/blob/main/index.html"
click node_main "https://github.com/mallahyari/system-design-visualizer/blob/main/src/main.jsx"
click node_app_root "https://github.com/mallahyari/system-design-visualizer/blob/main/src/App.jsx"
click node_styles "https://github.com/mallahyari/system-design-visualizer/blob/main/src/index.css"
click node_upload "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/UploadZone.jsx"
click node_analysis_service "https://github.com/mallahyari/system-design-visualizer/blob/main/src/services/analysisService.js"
click node_env "https://github.com/mallahyari/system-design-visualizer/blob/main/.env.example"
click node_mermaid_display "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/MermaidDisplay.jsx"
click node_system_diagram "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/SystemDiagram.jsx"
click node_custom_nodes "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/CustomNodes.jsx"
click node_node_types "https://github.com/mallahyari/system-design-visualizer/blob/main/src/config/nodeTypes.js"
click node_info_panel "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/InfoPanel.jsx"
click node_theme_context "https://github.com/mallahyari/system-design-visualizer/blob/main/src/contexts/ThemeContext.jsx"
click node_theme_definition "https://github.com/mallahyari/system-design-visualizer/blob/main/src/contexts/ThemeContextDef.js"
click node_use_theme "https://github.com/mallahyari/system-design-visualizer/blob/main/src/hooks/useTheme.js"
click node_theme_toggle "https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/ThemeToggle.jsx"
click node_themes "https://github.com/mallahyari/system-design-visualizer/blob/main/src/themes/index.js"

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_index,node_main,node_app_root,node_styles toneBlue
class node_upload,node_analysis_service,node_openai,node_env toneAmber
class node_mermaid_display,node_mermaid,node_system_diagram,node_react_flow,node_custom_nodes,node_node_types,node_info_panel toneMint
class node_theme_context,node_theme_definition,node_use_theme,node_theme_toggle,node_themes toneRose
```

## Components

### Application shell

- [Vite entry](https://github.com/mallahyari/system-design-visualizer/blob/main/index.html): HTML entry · `index.html`
- [React bootstrap](https://github.com/mallahyari/system-design-visualizer/blob/main/src/main.jsx): React entry · `src/main.jsx`
- [App workflow](https://github.com/mallahyari/system-design-visualizer/blob/main/src/App.jsx): React orchestrator · Owns view, diagram, selection, and panel state. · `src/App.jsx`
- [Global styles](https://github.com/mallahyari/system-design-visualizer/blob/main/src/index.css): CSS · `src/index.css`

### Image analysis

- [Upload zone](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/UploadZone.jsx): React component · Accepts dropped or selected architecture images. · `src/components/UploadZone.jsx`
- [Analysis service](https://github.com/mallahyari/system-design-visualizer/blob/main/src/services/analysisService.js): client AI service · Calls OpenAI when configured or returns mock analysis. · `src/services/analysisService.js`
- **OpenAI Vision / GPT-4o**: external AI API · Client-side credential boundary.
- [API key convention](https://github.com/mallahyari/system-design-visualizer/blob/main/.env.example): environment config · Provides VITE_OPENAI_API_KEY to the client build/runtime. · `.env.example`

### Diagram pipeline

- [Mermaid review](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/MermaidDisplay.jsx): React component · Edits, previews, and approves generated Mermaid source. · `src/components/MermaidDisplay.jsx`
- **Mermaid.js**: diagram runtime
- [Interactive graph](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/SystemDiagram.jsx): React Flow component · Builds topology and provides pan, zoom, and interaction. · `src/components/SystemDiagram.jsx`
- **React Flow**: graph runtime
- [Custom node renderers](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/CustomNodes.jsx): React components · `src/components/CustomNodes.jsx`
- [Node type mappings](https://github.com/mallahyari/system-design-visualizer/blob/main/src/config/nodeTypes.js): graph config · `src/config/nodeTypes.js`
- [Component details](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/InfoPanel.jsx): React component · Shows inferred metadata for the selected graph node. · `src/components/InfoPanel.jsx`

### Theme state

- [Theme provider](https://github.com/mallahyari/system-design-visualizer/blob/main/src/contexts/ThemeContext.jsx): React context · Global presentation state separate from diagram state. · `src/contexts/ThemeContext.jsx`
- [Theme context definition](https://github.com/mallahyari/system-design-visualizer/blob/main/src/contexts/ThemeContextDef.js): context definition · `src/contexts/ThemeContextDef.js`
- [Theme hook](https://github.com/mallahyari/system-design-visualizer/blob/main/src/hooks/useTheme.js): React hook · `src/hooks/useTheme.js`
- [Theme toggle](https://github.com/mallahyari/system-design-visualizer/blob/main/src/components/ThemeToggle.jsx): React component · `src/components/ThemeToggle.jsx`
- [Theme values](https://github.com/mallahyari/system-design-visualizer/blob/main/src/themes/index.js): theme definitions · `src/themes/index.js`

## Connections

- Vite entry → React bootstrap: loads
- React bootstrap → App workflow: mounts
- React bootstrap → Theme provider: provides
- Global styles → App workflow: styles
- App workflow → Upload zone: image input
- Upload zone → Analysis service: image
- API key convention → Analysis service: API key
- Analysis service → OpenAI Vision / GPT-4o: vision/code request
- Analysis service → App workflow: Mermaid and metadata
- App workflow → Mermaid review: generated source
- Mermaid review → Mermaid.js: renders preview
- Mermaid review → Interactive graph: approved Mermaid topology
- Interactive graph → React Flow: interactive graph
- Node type mappings → Custom node renderers: maps types
- Custom node renderers → Interactive graph: node presentation
- Interactive graph → App workflow: selected node
- App workflow → Component details: selection and metadata
- Theme context definition → Theme provider: defines context
- Theme values → Theme provider: presentation values
- Theme provider → Theme hook: consumed through
- Theme hook → Theme toggle: reads and updates
- Theme toggle → Theme provider: changes theme
