# oscarmarulanda/clinicdesk-ai architecture

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

- Interactive diagram: https://gitdiagram.com/oscarmarulanda/clinicdesk-ai
- Repository: https://github.com/oscarmarulanda/clinicdesk-ai

## Overview

ClinicDesk AI is a customer-support agent for clinic staff, with an embeddable chat widget and an admin console. The main workflow is a staff message over WebSocket, processed by the chat use case with AI and knowledge-base tools; session state is persisted, and unresolved requests can lead to callback scheduling and human escalation. Separate admin workflows cover authentication, article management, document ingestion, session review, escalation tracking, and analytics. The graph combines sampled call sites with README-documented capabilities; unsampled feature links are omitted or marked unverified.

Main entry points: [`src/presentation/api`](https://github.com/oscarmarulanda/clinicdesk-ai/tree/main/src/presentation/api) (Admin API Routes), [`src/application/use_cases/process_chat_message.py`](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/process_chat_message.py) (Chat Processing), [`frontend/admin/app.js`](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/frontend/admin/app.js) (Admin Dashboard), [`src/application/use_cases/ingest_document.py`](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/ingest_document.py) (Document Ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channels["User Channels"]
  node_widget["Chat Widget<br/>[chat-widget.js]"]
  node_dashboard["Admin Dashboard<br/>[app.js]"]
  node_chat_ws["Chat WebSocket<br/>[chat.py]"]
  node_admin_api["Admin API Routes"]
  node_admin_ws["Admin Notifications<br/>[admin.py]"]
end

subgraph group_application["Application Workflows"]
  node_auth["Authentication"]
  node_chat_flow["Chat Processing"]
  node_knowledge_search["Knowledge Search"]
  node_article_management["Article Management<br/>[manage_articles.py]"]
  node_document_ingestion["Document Ingestion<br/>[ingest_document.py]"]
  node_session_review["Session Review<br/>[get_sessions.py]"]
  node_escalation_management["Escalation Management"]
  node_analytics["Analytics<br/>[get_analytics.py]"]
  node_callback["Callback Scheduling"]
  node_email_notice["Escalation Email"]
end

subgraph group_data["Domain and Data"]
  node_articles_store[("Knowledge Articles")]
  node_sessions_store[("Session Store")]
  node_escalations_store[("Escalation Store")]
  node_users_store[("User Store<br/>[user_repository.py]")]
end

subgraph group_integrations["External Integrations"]
  node_ai_service["AI Service<br/>[claude_service.py]"]
  node_extractor["Document Extractor"]
  node_calendar["Google Calendar"]
  node_sendgrid["SendGrid Email"]
end

node_staff(("Clinic Staff"))
node_admins(("Clinic Admins"))

node_staff -->|"asks for help"| node_widget
node_widget -.->|"sends chat"| node_chat_ws
node_chat_ws -->|"processes message"| node_chat_flow
node_chat_flow -->|"requests AI response"| node_ai_service
node_chat_flow -.->|"uses knowledge tools"| node_knowledge_search
node_chat_flow -.->|"searches articles"| node_articles_store
node_chat_flow -.->|"uses session state"| node_sessions_store
node_chat_flow -.->|"uses escalation data"| node_escalations_store
node_chat_flow -.->|"checks and books"| node_calendar
node_chat_flow -.->|"sends escalation notices"| node_sendgrid
node_admins -->|"manages support"| node_dashboard
node_dashboard -.->|"uses admin features"| node_admin_api
node_dashboard -.->|"receives updates"| node_admin_ws
node_admin_api -->|"authenticates users"| node_auth
node_auth -->|"reads and creates users"| node_users_store
node_admin_api -->|"manages articles"| node_article_management
node_article_management -->|"reads and writes"| node_articles_store
node_admin_api -->|"submits documents"| node_document_ingestion
node_document_ingestion -->|"extracts text"| node_extractor
node_document_ingestion -->|"structures article"| node_ai_service
node_admin_api -->|"lists sessions"| node_session_review
node_session_review -.->|"reads sessions"| node_sessions_store
node_admin_api -.->|"tracks escalations"| node_escalation_management
node_escalation_management -.->|"manages records"| node_escalations_store
node_admin_api -.->|"requests metrics"| node_analytics
node_admin_api -.->|"schedules callbacks"| node_callback
node_callback -.->|"books callback"| node_calendar
node_admin_api -.->|"triggers notifications"| node_email_notice
node_email_notice -.->|"delivers email"| node_sendgrid
node_admin_ws -.->|"pushes escalation alerts"| node_admins

click node_widget "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/frontend/widget/chat-widget.js"
click node_dashboard "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/frontend/admin/app.js"
click node_chat_ws "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/presentation/ws/chat.py"
click node_admin_api "https://github.com/oscarmarulanda/clinicdesk-ai/tree/main/src/presentation/api"
click node_admin_ws "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/presentation/ws/admin.py"
click node_auth "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/authenticate_user.py"
click node_chat_flow "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/process_chat_message.py"
click node_knowledge_search "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/search_knowledge_base.py"
click node_article_management "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/manage_articles.py"
click node_document_ingestion "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/ingest_document.py"
click node_session_review "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/get_sessions.py"
click node_escalation_management "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/manage_escalations.py"
click node_analytics "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/get_analytics.py"
click node_callback "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/schedule_callback.py"
click node_email_notice "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/send_escalation_email.py"
click node_ai_service "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/ai/claude_service.py"
click node_extractor "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/documents/document_extractor.py"
click node_calendar "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/calendar/google_calendar_service.py"
click node_sendgrid "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/email/sendgrid_service.py"
click node_articles_store "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/knowledge_repository.py"
click node_sessions_store "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/session_repository.py"
click node_escalations_store "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/escalation_repository.py"
click node_users_store "https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/user_repository.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_widget,node_dashboard,node_chat_ws,node_admin_api,node_admin_ws toneBlue
class node_auth,node_chat_flow,node_knowledge_search,node_article_management,node_document_ingestion,node_session_review,node_escalation_management,node_analytics,node_callback,node_email_notice toneAmber
class node_articles_store,node_sessions_store,node_escalations_store,node_users_store toneMint
class node_ai_service,node_extractor,node_calendar,node_sendgrid toneRose
class node_staff,node_admins toneIndigo
```

## Components

### User Channels

- [Chat Widget](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/frontend/widget/chat-widget.js): `frontend/widget/chat-widget.js`
- [Admin Dashboard](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/frontend/admin/app.js): `frontend/admin/app.js`
- [Chat WebSocket](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/presentation/ws/chat.py): `src/presentation/ws/chat.py`
- [Admin API Routes](https://github.com/oscarmarulanda/clinicdesk-ai/tree/main/src/presentation/api): `src/presentation/api`
- [Admin Notifications](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/presentation/ws/admin.py): `src/presentation/ws/admin.py`

### Application Workflows

- [Authentication](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/authenticate_user.py): `src/application/use_cases/authenticate_user.py`
- [Chat Processing](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/process_chat_message.py): `src/application/use_cases/process_chat_message.py`
- [Knowledge Search](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/search_knowledge_base.py): `src/application/use_cases/search_knowledge_base.py`
- [Article Management](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/manage_articles.py): `src/application/use_cases/manage_articles.py`
- [Document Ingestion](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/ingest_document.py): `src/application/use_cases/ingest_document.py`
- [Session Review](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/get_sessions.py): `src/application/use_cases/get_sessions.py`
- [Escalation Management](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/manage_escalations.py): `src/application/use_cases/manage_escalations.py`
- [Analytics](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/get_analytics.py): `src/application/use_cases/get_analytics.py`
- [Callback Scheduling](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/schedule_callback.py): `src/application/use_cases/schedule_callback.py`
- [Escalation Email](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/application/use_cases/send_escalation_email.py): `src/application/use_cases/send_escalation_email.py`

### Domain and Data

- [Knowledge Articles](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/knowledge_repository.py): `src/infrastructure/database/knowledge_repository.py`
- [Session Store](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/session_repository.py): `src/infrastructure/database/session_repository.py`
- [Escalation Store](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/escalation_repository.py): `src/infrastructure/database/escalation_repository.py`
- [User Store](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/database/user_repository.py): `src/infrastructure/database/user_repository.py`

### External Integrations

- [AI Service](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/ai/claude_service.py): `src/infrastructure/ai/claude_service.py`
- [Document Extractor](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/documents/document_extractor.py): `src/infrastructure/documents/document_extractor.py`
- [Google Calendar](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/calendar/google_calendar_service.py): `src/infrastructure/calendar/google_calendar_service.py`
- [SendGrid Email](https://github.com/oscarmarulanda/clinicdesk-ai/blob/main/src/infrastructure/email/sendgrid_service.py): `src/infrastructure/email/sendgrid_service.py`

### Other components

- **Clinic Staff**
- **Clinic Admins**

## Connections

- Clinic Staff → Chat Widget: asks for help
- Chat Widget → Chat WebSocket: sends chat
- Chat WebSocket → Chat Processing: processes message (evidence: `src/presentation/ws/chat.py`)
- Chat Processing → AI Service: requests AI response
- Chat Processing → Knowledge Search: uses knowledge tools
- Chat Processing → Knowledge Articles: searches articles
- Chat Processing → Session Store: uses session state (evidence: `src/presentation/dependencies.py`)
- Chat Processing → Escalation Store: uses escalation data (evidence: `src/presentation/dependencies.py`)
- Chat Processing → Google Calendar: checks and books
- Chat Processing → SendGrid Email: sends escalation notices
- Clinic Admins → Admin Dashboard: manages support
- Admin Dashboard → Admin API Routes: uses admin features
- Admin Dashboard → Admin Notifications: receives updates
- Admin API Routes → Authentication: authenticates users (evidence: `src/presentation/api/auth.py`)
- Authentication → User Store: reads and creates users (evidence: `src/application/use_cases/authenticate_user.py`)
- Admin API Routes → Article Management: manages articles (evidence: `src/presentation/api/articles.py`)
- Article Management → Knowledge Articles: reads and writes (evidence: `src/application/use_cases/manage_articles.py`)
- Admin API Routes → Document Ingestion: submits documents (evidence: `src/presentation/api/ingest.py`)
- Document Ingestion → Document Extractor: extracts text (evidence: `src/application/use_cases/ingest_document.py`)
- Document Ingestion → AI Service: structures article (evidence: `src/application/use_cases/ingest_document.py`)
- Admin API Routes → Session Review: lists sessions (evidence: `src/presentation/api/sessions.py`)
- Session Review → Session Store: reads sessions (evidence: `src/presentation/dependencies.py`)
- Admin API Routes → Escalation Management: tracks escalations
- Escalation Management → Escalation Store: manages records (evidence: `src/presentation/dependencies.py`)
- Admin API Routes → Analytics: requests metrics
- Admin API Routes → Callback Scheduling: schedules callbacks
- Callback Scheduling → Google Calendar: books callback
- Admin API Routes → Escalation Email: triggers notifications
- Escalation Email → SendGrid Email: delivers email
- Admin Notifications → Clinic Admins: pushes escalation alerts
