How mallahyari/system-design-visualizer works
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: App.jsx App workflow · ThemeContext.jsx Theme provider · analysisService.js Analysis service · SystemDiagram.jsx Interactive graph
Components 20
Application shell
- Vite entry
index.html - React bootstrap
src/main.jsx - App workflow · Owns view, diagram, selection, and panel state.
src/App.jsx - Global styles
src/index.css
Image analysis
- Upload zone · Accepts dropped or selected architecture images.
src/components/UploadZone.jsx - Analysis service · Calls OpenAI when configured or returns mock analysis.
src/services/analysisService.js - OpenAI Vision / GPT-4o · Client-side credential boundary.
- API key convention · Provides VITE_OPENAI_API_KEY to the client build/runtime.
.env.example
Diagram pipeline
- Mermaid review · Edits, previews, and approves generated Mermaid source.
src/components/MermaidDisplay.jsx - Mermaid.js
- Interactive graph · Builds topology and provides pan, zoom, and interaction.
src/components/SystemDiagram.jsx - React Flow
- Custom node renderers
src/components/CustomNodes.jsx - Node type mappings
src/config/nodeTypes.js - Component details · Shows inferred metadata for the selected graph node.
src/components/InfoPanel.jsx
Theme state
- Theme provider · Global presentation state separate from diagram state.
src/contexts/ThemeContext.jsx - Theme context definition
src/contexts/ThemeContextDef.js - Theme hook
src/hooks/useTheme.js - Theme toggle
src/components/ThemeToggle.jsx - Theme values
src/themes/index.js
Connections 22
- 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