# ranchia/next-ai-draw-io architecture

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

- Interactive diagram: https://gitdiagram.com/ranchia/next-ai-draw-io
- Repository: https://github.com/ranchia/next-ai-draw-io

## Overview

Next AI Draw.io is a web and desktop-capable application for creating and editing draw.io diagrams through AI chat, with document/image inputs, diagram validation, history, templates, and an MCP server for agent clients. The main workflow is a user prompt or uploaded material in the chat workspace, streamed AI assistance, diagram operations in the editor, then validation and save/history. The graph combines sampled call evidence with README-documented capabilities; links for unsampled subsystems are marked dashed and unverified.

Main entry points: [`components/chat-panel.tsx`](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-panel.tsx) (Chat workspace), [`app/api/chat/route.ts`](https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/chat/route.ts) (Chat orchestration), [`contexts/diagram-context.tsx`](https://github.com/ranchia/next-ai-draw-io/blob/main/contexts/diagram-context.tsx) (Diagram context), [`lib/ai-providers.ts`](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/ai-providers.ts) (AI providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Chat workspace"]
  node_chat["Chat workspace<br/>[chat-panel.tsx]"]
  node_input["Prompt and uploads<br/>[chat-input.tsx]"]
  node_messages["Chat messages"]
  node_fileprocessor["File extraction"]
end

subgraph group_diagram["Diagram editing"]
  node_diagramctx["Diagram context"]
  node_tools["Diagram operations"]
  node_validator["Diagram validation<br/>[route.ts]"]
  node_validationui["Validation display<br/>[ValidationCard.tsx]"]
end

subgraph group_ai["AI services"]
  node_chatapi["Chat orchestration<br/>[route.ts]"]
  node_providers["AI providers<br/>[ai-providers.ts]"]
  node_modelconfig["Model configuration"]
  node_modeltest["Provider verification<br/>[route.ts]"]
end

subgraph group_persistence["State and integrations"]
  node_sessions["Session manager"]
  node_sessiondb[("Session history<br/>[session-storage.ts]")]
  node_templates["Prompt templates<br/>[TemplatePanel.tsx]"]
  node_templatedb[("Template storage")]
  node_mcp["MCP server<br/>[index.ts]"]
  node_mcpops["MCP diagram tools"]
end

node_user(("Diagram author"))
node_drawio["draw.io editor"]
node_llm["LLM services"]
node_agent(("MCP agent client"))

node_user -->|"uses"| node_chat
node_chat -->|"renders"| node_input
node_chat -->|"renders"| node_messages
node_input -.->|"extracts files"| node_fileprocessor
node_chat -.->|"sends prompts"| node_chatapi
node_chatapi -->|"selects model"| node_providers
node_chatapi -->|"looks up model"| node_modelconfig
node_providers -.->|"invokes model"| node_llm
node_llm -.->|"streams response"| node_chatapi
node_chat -->|"manages sessions"| node_sessions
node_sessions -->|"loads and saves"| node_sessiondb
node_chat -.->|"offers templates"| node_templates
node_templates -.->|"stores templates"| node_templatedb
node_chat -->|"hosts editor state"| node_diagramctx
node_diagramctx -->|"loads and exports"| node_drawio
node_tools -->|"reads diagram XML"| node_diagramctx
node_tools -.->|"requests validation"| node_validator
node_validator -->|"gets validation model"| node_providers
node_messages -.->|"shows results"| node_validationui
node_agent -->|"connects via MCP"| node_mcp
node_mcp -.->|"exposes tools"| node_mcpops
node_mcpops -.->|"updates diagram"| node_drawio
node_user -.->|"tests provider"| node_modeltest
node_modeltest -->|"checks connectivity"| node_llm

click node_chat "https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-panel.tsx"
click node_input "https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-input.tsx"
click node_messages "https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-message-display.tsx"
click node_fileprocessor "https://github.com/ranchia/next-ai-draw-io/blob/main/lib/use-file-processor.tsx"
click node_sessions "https://github.com/ranchia/next-ai-draw-io/blob/main/hooks/use-session-manager.ts"
click node_sessiondb "https://github.com/ranchia/next-ai-draw-io/blob/main/lib/session-storage.ts"
click node_templates "https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat/TemplatePanel.tsx"
click node_templatedb "https://github.com/ranchia/next-ai-draw-io/blob/main/lib/template-storage.ts"
click node_diagramctx "https://github.com/ranchia/next-ai-draw-io/blob/main/contexts/diagram-context.tsx"
click node_tools "https://github.com/ranchia/next-ai-draw-io/blob/main/hooks/use-diagram-tool-handlers.ts"
click node_validator "https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/validate-diagram/route.ts"
click node_validationui "https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat/ValidationCard.tsx"
click node_chatapi "https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/chat/route.ts"
click node_providers "https://github.com/ranchia/next-ai-draw-io/blob/main/lib/ai-providers.ts"
click node_modelconfig "https://github.com/ranchia/next-ai-draw-io/blob/main/lib/server-model-config.ts"
click node_modeltest "https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/validate-model/route.ts"
click node_mcp "https://github.com/ranchia/next-ai-draw-io/blob/main/packages/mcp-server/src/index.ts"
click node_mcpops "https://github.com/ranchia/next-ai-draw-io/blob/main/packages/mcp-server/src/diagram-operations.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_chat,node_input,node_messages,node_fileprocessor,node_agent toneBlue
class node_diagramctx,node_tools,node_validator,node_validationui toneAmber
class node_chatapi,node_providers,node_modelconfig,node_modeltest toneMint
class node_sessions,node_sessiondb,node_templates,node_templatedb,node_mcp,node_mcpops toneRose
class node_user,node_drawio,node_llm toneIndigo
```

## Components

### Chat workspace

- [Chat workspace](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-panel.tsx): `components/chat-panel.tsx`
- [Prompt and uploads](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-input.tsx): `components/chat-input.tsx`
- [Chat messages](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat-message-display.tsx): `components/chat-message-display.tsx`
- [File extraction](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/use-file-processor.tsx): `lib/use-file-processor.tsx`

### Diagram editing

- [Diagram context](https://github.com/ranchia/next-ai-draw-io/blob/main/contexts/diagram-context.tsx): `contexts/diagram-context.tsx`
- [Diagram operations](https://github.com/ranchia/next-ai-draw-io/blob/main/hooks/use-diagram-tool-handlers.ts): `hooks/use-diagram-tool-handlers.ts`
- [Diagram validation](https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/validate-diagram/route.ts): `app/api/validate-diagram/route.ts`
- [Validation display](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat/ValidationCard.tsx): `components/chat/ValidationCard.tsx`

### AI services

- [Chat orchestration](https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [AI providers](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/ai-providers.ts): `lib/ai-providers.ts`
- [Model configuration](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/server-model-config.ts): `lib/server-model-config.ts`
- [Provider verification](https://github.com/ranchia/next-ai-draw-io/blob/main/app/api/validate-model/route.ts): `app/api/validate-model/route.ts`

### State and integrations

- [Session manager](https://github.com/ranchia/next-ai-draw-io/blob/main/hooks/use-session-manager.ts): `hooks/use-session-manager.ts`
- [Session history](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/session-storage.ts): `lib/session-storage.ts`
- [Prompt templates](https://github.com/ranchia/next-ai-draw-io/blob/main/components/chat/TemplatePanel.tsx): `components/chat/TemplatePanel.tsx`
- [Template storage](https://github.com/ranchia/next-ai-draw-io/blob/main/lib/template-storage.ts): `lib/template-storage.ts`
- [MCP server](https://github.com/ranchia/next-ai-draw-io/blob/main/packages/mcp-server/src/index.ts): `packages/mcp-server/src/index.ts`
- [MCP diagram tools](https://github.com/ranchia/next-ai-draw-io/blob/main/packages/mcp-server/src/diagram-operations.ts): `packages/mcp-server/src/diagram-operations.ts`

### Other components

- **Diagram author**
- **draw.io editor**
- **LLM services**
- **MCP agent client**

## Connections

- Diagram author → Chat workspace: uses (evidence: `README.md`)
- Chat workspace → Prompt and uploads: renders (evidence: `components/chat-panel.tsx`)
- Chat workspace → Chat messages: renders (evidence: `components/chat-panel.tsx`)
- Prompt and uploads → File extraction: extracts files
- Chat workspace → Chat orchestration: sends prompts
- Chat orchestration → AI providers: selects model (evidence: `app/api/chat/route.ts`)
- Chat orchestration → Model configuration: looks up model (evidence: `app/api/chat/route.ts`)
- AI providers → LLM services: invokes model
- LLM services → Chat orchestration: streams response
- Chat workspace → Session manager: manages sessions (evidence: `components/chat-panel.tsx`)
- Session manager → Session history: loads and saves (evidence: `hooks/use-session-manager.ts`)
- Chat workspace → Prompt templates: offers templates
- Prompt templates → Template storage: stores templates
- Chat workspace → Diagram context: hosts editor state (evidence: `app/[lang]/page.tsx`)
- Diagram context → draw.io editor: loads and exports (evidence: `contexts/diagram-context.tsx`)
- Diagram operations → Diagram context: reads diagram XML (evidence: `hooks/use-diagram-tool-handlers.ts`)
- Diagram operations → Diagram validation: requests validation
- Diagram validation → AI providers: gets validation model (evidence: `app/api/validate-diagram/route.ts`)
- Chat messages → Validation display: shows results
- MCP agent client → MCP server: connects via MCP (evidence: `README.md`)
- MCP server → MCP diagram tools: exposes tools
- MCP diagram tools → draw.io editor: updates diagram
- Diagram author → Provider verification: tests provider
- Provider verification → LLM services: checks connectivity (evidence: `app/api/validate-model/route.ts`)
