# songhaiwen-creator/enterprise-ai-workbench architecture

> Architecture diagram of the GitHub repository songhaiwen-creator/enterprise-ai-workbench, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/songhaiwen-creator/enterprise-ai-workbench
- Repository: https://github.com/songhaiwen-creator/enterprise-ai-workbench

## Overview

Enterprise AI Workbench is a B2B application for managing knowledge bases and documents, configuring agents and tools, and answering enterprise questions. Users interact through the Next.js UI and FastAPI API. The sampled retrieval path covers document indexing and semantic search: the API delegates to retrieval services, which chunk documents, obtain embeddings, and persist or query chunks. The tree and README identify additional auth, workspace, answer, agent, and tool capabilities; their internal wiring is not fully shown in the sampled source, so those links are kept conservative.

Main entry points: [`backend/app/api/router.py`](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/router.py) (API router), [`backend/app/services/retrieval.py`](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/retrieval.py) (Index and search), [`frontend/app/page.tsx`](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/page.tsx) (Workbench UI), [`frontend/utils/api.ts`](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/utils/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_frontend["Workbench UI<br/>[page.tsx]"]
  node_assistant_ui["Assistant UI<br/>[assistant.tsx]"]
  node_knowledge_ui["Knowledge Q&amp;A UI<br/>[knowledge-qa.tsx]"]
  node_frontend_api["API client<br/>[api.ts]"]
end

subgraph group_api["API and access"]
  node_app["FastAPI app<br/>[main.py]"]
  node_api_router["API router<br/>[router.py]"]
  node_auth_routes["Auth routes<br/>[auth.py]"]
  node_workspace_routes["Workspace routes<br/>[workspaces.py]"]
  node_kb_routes["Knowledge-base routes<br/>[knowledge_bases.py]"]
  node_document_routes["Document routes<br/>[documents.py]"]
  node_retrieval_routes["Retrieval routes<br/>[retrieval.py]"]
  node_answer_routes["Answer routes<br/>[answers.py]"]
  node_agent_routes["Agent routes<br/>[agents.py]"]
  node_tool_routes["Tool routes<br/>[tools.py]"]
end

subgraph group_knowledge["Knowledge pipeline"]
  node_retrieval_service["Index and search<br/>[retrieval.py]"]
  node_chunking["Text chunking<br/>[chunking.py]"]
  node_documents_service["Document handling<br/>[documents.py]"]
  node_extraction["Document extraction"]
  node_embedding_service["Embedding provider<br/>[embeddings.py]"]
  node_database[("PostgreSQL + vectors<br/>[session.py]")]
end

subgraph group_agents["Agents and tools"]
  node_answer_service["Answer generation<br/>[answers.py]"]
  node_routing_service["Intent routing<br/>[routing.py]"]
  node_tool_selection["Tool selection<br/>[tool_selection.py]"]
  node_tool_execution["Tool execution<br/>[tool_execution.py]"]
end

node_user(("Workbench user"))
node_openai{{"OpenAI"}}

node_user -->|"uses"| node_frontend
node_frontend -->|"renders"| node_assistant_ui
node_frontend -->|"renders"| node_knowledge_ui
node_assistant_ui -->|"requests"| node_frontend_api
node_knowledge_ui -->|"requests"| node_frontend_api
node_frontend_api -->|"calls API"| node_app
node_app -->|"mounts"| node_api_router
node_api_router -->|"dispatches"| node_auth_routes
node_api_router -->|"dispatches"| node_workspace_routes
node_api_router -->|"dispatches"| node_kb_routes
node_api_router -->|"dispatches"| node_document_routes
node_api_router -->|"dispatches"| node_retrieval_routes
node_api_router -->|"dispatches"| node_answer_routes
node_api_router -->|"dispatches"| node_agent_routes
node_api_router -->|"dispatches"| node_tool_routes
node_retrieval_routes -->|"calls"| node_retrieval_service
node_retrieval_service -->|"loads document"| node_documents_service
node_retrieval_service -->|"splits text"| node_chunking
node_retrieval_service -->|"embeds text"| node_embedding_service
node_retrieval_service -->|"reads and writes"| node_database
node_documents_service -->|"loads records"| node_database
node_embedding_service -.->|"requests embeddings"| node_openai
node_routing_service -.->|"classifies request"| node_openai

click node_frontend "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/page.tsx"
click node_assistant_ui "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/components/assistant.tsx"
click node_knowledge_ui "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/components/knowledge-qa.tsx"
click node_frontend_api "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/utils/api.ts"
click node_app "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/main.py"
click node_api_router "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/router.py"
click node_auth_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/auth.py"
click node_workspace_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/workspaces.py"
click node_kb_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/knowledge_bases.py"
click node_document_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/documents.py"
click node_retrieval_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/retrieval.py"
click node_answer_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/answers.py"
click node_agent_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/agents.py"
click node_tool_routes "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/tools.py"
click node_retrieval_service "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/retrieval.py"
click node_chunking "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/chunking.py"
click node_documents_service "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/documents.py"
click node_extraction "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/document_extraction.py"
click node_embedding_service "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/embeddings.py"
click node_database "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/db/session.py"
click node_answer_service "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/answers.py"
click node_routing_service "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/routing.py"
click node_tool_selection "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/tool_selection.py"
click node_tool_execution "https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/tool_execution.py"

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_frontend,node_assistant_ui,node_knowledge_ui,node_frontend_api,node_user toneBlue
class node_app,node_api_router,node_auth_routes,node_workspace_routes,node_kb_routes,node_document_routes,node_retrieval_routes,node_answer_routes,node_agent_routes,node_tool_routes toneAmber
class node_retrieval_service,node_chunking,node_documents_service,node_extraction,node_embedding_service,node_database toneMint
class node_answer_service,node_routing_service,node_tool_selection,node_tool_execution toneRose
class node_openai toneIndigo
```

## Components

### User interface

- [Workbench UI](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Assistant UI](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/components/assistant.tsx): `frontend/app/components/assistant.tsx`
- [Knowledge Q&A UI](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/app/components/knowledge-qa.tsx): `frontend/app/components/knowledge-qa.tsx`
- [API client](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/frontend/utils/api.ts): `frontend/utils/api.ts`

### API and access

- [FastAPI app](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/main.py): `backend/app/main.py`
- [API router](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/router.py): `backend/app/api/router.py`
- [Auth routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Workspace routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/workspaces.py): `backend/app/api/routes/workspaces.py`
- [Knowledge-base routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/knowledge_bases.py): `backend/app/api/routes/knowledge_bases.py`
- [Document routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/documents.py): `backend/app/api/routes/documents.py`
- [Retrieval routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/retrieval.py): `backend/app/api/routes/retrieval.py`
- [Answer routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/answers.py): `backend/app/api/routes/answers.py`
- [Agent routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/agents.py): `backend/app/api/routes/agents.py`
- [Tool routes](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/api/routes/tools.py): `backend/app/api/routes/tools.py`

### Knowledge pipeline

- [Index and search](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/retrieval.py): `backend/app/services/retrieval.py`
- [Text chunking](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/chunking.py): `backend/app/services/chunking.py`
- [Document handling](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/documents.py): `backend/app/services/documents.py`
- [Document extraction](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/document_extraction.py): `backend/app/services/document_extraction.py`
- [Embedding provider](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/embeddings.py): `backend/app/services/embeddings.py`
- [PostgreSQL + vectors](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/db/session.py): `backend/app/db/session.py`

### Agents and tools

- [Answer generation](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/answers.py): `backend/app/services/answers.py`
- [Intent routing](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/routing.py): `backend/app/services/routing.py`
- [Tool selection](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/tool_selection.py): `backend/app/services/tool_selection.py`
- [Tool execution](https://github.com/songhaiwen-creator/enterprise-ai-workbench/blob/main/backend/app/services/tool_execution.py): `backend/app/services/tool_execution.py`

### Other components

- **Workbench user**
- **OpenAI**

## Connections

- Workbench user → Workbench UI: uses
- Workbench UI → Assistant UI: renders
- Workbench UI → Knowledge Q&A UI: renders
- Assistant UI → API client: requests
- Knowledge Q&A UI → API client: requests
- API client → FastAPI app: calls API
- FastAPI app → API router: mounts
- API router → Auth routes: dispatches
- API router → Workspace routes: dispatches
- API router → Knowledge-base routes: dispatches
- API router → Document routes: dispatches
- API router → Retrieval routes: dispatches
- API router → Answer routes: dispatches
- API router → Agent routes: dispatches
- API router → Tool routes: dispatches
- Retrieval routes → Index and search: calls
- Index and search → Document handling: loads document
- Index and search → Text chunking: splits text
- Index and search → Embedding provider: embeds text
- Index and search → PostgreSQL + vectors: reads and writes
- Document handling → PostgreSQL + vectors: loads records
- Embedding provider → OpenAI: requests embeddings
- Intent routing → OpenAI: classifies request
