# dhruvkachhadiya3350/ai-workspace architecture

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

- Interactive diagram: https://gitdiagram.com/dhruvkachhadiya3350/ai-workspace
- Repository: https://github.com/dhruvkachhadiya3350/ai-workspace

## Overview

AI Workspace is a multi-model chat and document-RAG product. Users authenticate, organize conversations and projects, select a Bedrock model, and stream responses; optional uploaded documents are validated, stored, extracted and indexed for scoped retrieval and citations. The graph also preserves model discovery, usage tracking and diagnostics. README statements support the frontend/backend and cloud-service boundaries; source-index references support several backend calls. Some frontend internals and RAG stages are unsampled, so their links are limited to documented relationships.

Main entry points: [`backend/app/utils/db.py`](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/utils/db.py) (PostgreSQL and pgvector), [`backend/app/services/chat_service.py`](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/chat_service.py) (Chat orchestration), [`backend/app/routes/attachments.py`](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/attachments.py) (Attachment routes), [`frontend/src/components/WorkspaceApp.tsx`](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/WorkspaceApp.tsx) (Workspace UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Workspace interface"]
  node_ui["Workspace UI<br/>[WorkspaceApp.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_auth_ui["Auth screens<br/>[AuthScreen.tsx]"]
  node_messages["Message rendering<br/>[MessageItem.tsx]"]
end

subgraph group_api["Backend API"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_conversation_routes["Conversation routes<br/>[conversations.py]"]
  node_project_routes["Project routes<br/>[projects.py]"]
  node_chat_routes["Chat routes<br/>[chat.py]"]
  node_attachment_routes["Attachment routes<br/>[attachments.py]"]
  node_model_routes["Model routes<br/>[models.py]"]
  node_usage_routes["Usage routes<br/>[usage.py]"]
  node_health_routes["Diagnostics route<br/>[health.py]"]
  node_auth_service["Auth and JWT<br/>[auth.py]"]
end

subgraph group_chat["Chat and models"]
  node_chat_service["Chat orchestration<br/>[chat_service.py]"]
  node_model_discovery["Model discovery<br/>[discovery.py]"]
  node_adapter_registry["Chat adapter registry<br/>[registry.py]"]
  node_converse["Converse adapter"]
  node_invoke["Invoke adapter<br/>[invoke_adapter.py]"]
  node_embedding["Embedding adapter"]
end

subgraph group_documents["Documents and retrieval"]
  node_validation["Upload validation<br/>[validators.py]"]
  node_extract["Document extraction<br/>[extractors.py]"]
  node_indexer["Chunk and index<br/>[indexer.py]"]
  node_retriever["Semantic retrieval<br/>[retriever.py]"]
  node_ocr["Optional OCR<br/>[ocr_service.py]"]
end

subgraph group_platform["Persistence and cloud"]
  node_s3_service["Attachment storage<br/>[s3_service.py]"]
  node_usage_tracker["Usage tracking<br/>[tracker.py]"]
  node_db[("PostgreSQL and pgvector<br/>[db.py]")]
  node_s3[("Amazon S3")]
  node_bedrock["Amazon Bedrock"]
  node_textract["Amazon Textract"]
end

node_user(("Workspace user"))

node_user -->|"uses"| node_ui
node_ui -->|"requests"| node_api_client
node_api_client -->|"REST and SSE"| node_auth_routes
node_user -->|"signs in"| node_auth_ui
node_auth_ui -->|"authenticates"| node_api_client
node_ui -->|"renders"| node_messages
node_chat_routes -->|"delegates"| node_chat_service
node_conversation_routes -->|"uses"| node_chat_service
node_chat_service -->|"resolves adapter"| node_adapter_registry
node_adapter_registry -->|"selects"| node_converse
node_adapter_registry -->|"selects"| node_invoke
node_converse -->|"invokes"| node_bedrock
node_invoke -->|"invokes"| node_bedrock
node_chat_service -->|"retrieves context"| node_retriever
node_chat_service -->|"records usage"| node_usage_tracker
node_model_routes -->|"syncs models"| node_model_discovery
node_model_discovery -->|"discovers catalog"| node_bedrock
node_model_discovery -->|"persists catalog"| node_db
node_attachment_routes -->|"validates upload"| node_validation
node_attachment_routes -->|"stores files"| node_s3_service
node_s3_service -->|"reads and writes"| node_s3
node_attachment_routes -->|"extracts text"| node_extract
node_attachment_routes -->|"indexes document"| node_indexer
node_indexer -.->|"generates vectors"| node_embedding
node_embedding -->|"embeds text"| node_bedrock
node_indexer -->|"stores chunks"| node_db
node_retriever -->|"embeds query"| node_embedding
node_retriever -->|"searches vectors"| node_db
node_ocr -->|"requests OCR"| node_textract
node_auth_routes -->|"hashes and verifies"| node_auth_service
node_auth_service -->|"checks user"| node_db
node_conversation_routes -->|"reads and writes"| node_db
node_project_routes -->|"reads and writes"| node_db
node_usage_routes -->|"requests summaries"| node_usage_tracker
node_usage_tracker -->|"stores usage"| node_db
node_health_routes -->|"checks health"| node_db

click node_ui "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/WorkspaceApp.tsx"
click node_api_client "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/services/api.ts"
click node_auth_ui "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/AuthScreen.tsx"
click node_messages "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/MessageItem.tsx"
click node_auth_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/auth.py"
click node_conversation_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/conversations.py"
click node_project_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/projects.py"
click node_chat_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/chat.py"
click node_attachment_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/attachments.py"
click node_model_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/models.py"
click node_usage_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/usage.py"
click node_health_routes "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/health.py"
click node_auth_service "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/utils/auth.py"
click node_chat_service "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/chat_service.py"
click node_model_discovery "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/discovery.py"
click node_adapter_registry "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/registry.py"
click node_converse "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/converse_adapter.py"
click node_invoke "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/invoke_adapter.py"
click node_embedding "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/embedding_adapter.py"
click node_validation "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/storage/validators.py"
click node_extract "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/extractors.py"
click node_indexer "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/indexer.py"
click node_retriever "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/retriever.py"
click node_ocr "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/ocr_service.py"
click node_s3_service "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/storage/s3_service.py"
click node_usage_tracker "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/usage/tracker.py"
click node_db "https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/utils/db.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_ui,node_api_client,node_auth_ui,node_messages,node_user toneBlue
class node_auth_routes,node_conversation_routes,node_project_routes,node_chat_routes,node_attachment_routes,node_model_routes,node_usage_routes,node_health_routes,node_auth_service toneAmber
class node_chat_service,node_model_discovery,node_adapter_registry,node_converse,node_invoke,node_embedding toneMint
class node_validation,node_extract,node_indexer,node_retriever,node_ocr toneRose
class node_s3_service,node_usage_tracker,node_db,node_s3,node_bedrock,node_textract toneIndigo
```

## Components

### Workspace interface

- [Workspace UI](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/WorkspaceApp.tsx): `frontend/src/components/WorkspaceApp.tsx`
- [API client](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Auth screens](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/AuthScreen.tsx): `frontend/src/components/AuthScreen.tsx`
- [Message rendering](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/frontend/src/components/MessageItem.tsx): `frontend/src/components/MessageItem.tsx`

### Backend API

- [Authentication routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/auth.py): `backend/app/routes/auth.py`
- [Conversation routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/conversations.py): `backend/app/routes/conversations.py`
- [Project routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/projects.py): `backend/app/routes/projects.py`
- [Chat routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/chat.py): `backend/app/routes/chat.py`
- [Attachment routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/attachments.py): `backend/app/routes/attachments.py`
- [Model routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/models.py): `backend/app/routes/models.py`
- [Usage routes](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/usage.py): `backend/app/routes/usage.py`
- [Diagnostics route](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/routes/health.py): `backend/app/routes/health.py`
- [Auth and JWT](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/utils/auth.py): `backend/app/utils/auth.py`

### Chat and models

- [Chat orchestration](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Model discovery](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/discovery.py): `backend/app/services/bedrock/discovery.py`
- [Chat adapter registry](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/registry.py): `backend/app/services/bedrock/adapters/registry.py`
- [Converse adapter](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/converse_adapter.py): `backend/app/services/bedrock/adapters/converse_adapter.py`
- [Invoke adapter](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/invoke_adapter.py): `backend/app/services/bedrock/adapters/invoke_adapter.py`
- [Embedding adapter](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/bedrock/adapters/embedding_adapter.py): `backend/app/services/bedrock/adapters/embedding_adapter.py`

### Documents and retrieval

- [Upload validation](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/storage/validators.py): `backend/app/services/storage/validators.py`
- [Document extraction](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/extractors.py): `backend/app/services/rag/extractors.py`
- [Chunk and index](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/indexer.py): `backend/app/services/rag/indexer.py`
- [Semantic retrieval](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/retriever.py): `backend/app/services/rag/retriever.py`
- [Optional OCR](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/rag/ocr_service.py): `backend/app/services/rag/ocr_service.py`

### Persistence and cloud

- [Attachment storage](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/storage/s3_service.py): `backend/app/services/storage/s3_service.py`
- [Usage tracking](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/services/usage/tracker.py): `backend/app/services/usage/tracker.py`
- [PostgreSQL and pgvector](https://github.com/dhruvkachhadiya3350/ai-workspace/blob/main/backend/app/utils/db.py): `backend/app/utils/db.py`
- **Amazon S3**
- **Amazon Bedrock**
- **Amazon Textract**

### Other components

- **Workspace user**

## Connections

- Workspace user → Workspace UI: uses
- Workspace UI → API client: requests
- API client → Authentication routes: REST and SSE
- Workspace user → Auth screens: signs in
- Auth screens → API client: authenticates
- Workspace UI → Message rendering: renders
- Chat routes → Chat orchestration: delegates (evidence: `backend/app/routes/chat.py`)
- Conversation routes → Chat orchestration: uses (evidence: `backend/app/routes/conversations.py`)
- Chat orchestration → Chat adapter registry: resolves adapter (evidence: `backend/app/services/chat_service.py`)
- Chat adapter registry → Converse adapter: selects (evidence: `backend/app/services/bedrock/adapters/registry.py`)
- Chat adapter registry → Invoke adapter: selects (evidence: `backend/app/services/bedrock/adapters/registry.py`)
- Converse adapter → Amazon Bedrock: invokes
- Invoke adapter → Amazon Bedrock: invokes
- Chat orchestration → Semantic retrieval: retrieves context (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Usage tracking: records usage (evidence: `backend/app/services/chat_service.py`)
- Model routes → Model discovery: syncs models (evidence: `backend/app/routes/models.py`)
- Model discovery → Amazon Bedrock: discovers catalog
- Model discovery → PostgreSQL and pgvector: persists catalog (evidence: `backend/app/services/bedrock/discovery.py`)
- Attachment routes → Upload validation: validates upload (evidence: `backend/app/routes/attachments.py`)
- Attachment routes → Attachment storage: stores files (evidence: `backend/app/routes/attachments.py`)
- Attachment storage → Amazon S3: reads and writes
- Attachment routes → Document extraction: extracts text (evidence: `backend/app/routes/attachments.py`)
- Attachment routes → Chunk and index: indexes document (evidence: `backend/app/routes/attachments.py`)
- Chunk and index → Embedding adapter: generates vectors
- Embedding adapter → Amazon Bedrock: embeds text
- Chunk and index → PostgreSQL and pgvector: stores chunks
- Semantic retrieval → Embedding adapter: embeds query (evidence: `backend/app/services/rag/retriever.py`)
- Semantic retrieval → PostgreSQL and pgvector: searches vectors (evidence: `backend/app/services/rag/retriever.py`)
- Optional OCR → Amazon Textract: requests OCR
- Authentication routes → Auth and JWT: hashes and verifies (evidence: `backend/app/routes/auth.py`)
- Auth and JWT → PostgreSQL and pgvector: checks user (evidence: `backend/app/utils/auth.py`)
- Conversation routes → PostgreSQL and pgvector: reads and writes (evidence: `backend/app/routes/conversations.py`)
- Project routes → PostgreSQL and pgvector: reads and writes (evidence: `backend/app/routes/projects.py`)
- Usage routes → Usage tracking: requests summaries (evidence: `backend/app/routes/usage.py`)
- Usage tracking → PostgreSQL and pgvector: stores usage (evidence: `backend/app/services/usage/tracker.py`)
- Diagnostics route → PostgreSQL and pgvector: checks health (evidence: `backend/app/routes/health.py`)
