# prabhu0023/client-saas architecture

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

- Interactive diagram: https://gitdiagram.com/prabhu0023/client-saas
- Repository: https://github.com/prabhu0023/client-saas

## Overview

DoctorDesk is a WhatsApp-first clinic appointment platform with a staff portal. Its patient workflow routes inbound WhatsApp events to a clinic, processes booking or messaging intents, offers timezone-aware slots, books appointments, and sends replies. Staff separately manage availability and appointments, handle patient inbox threads, and receive due-reminder processing. The README documents these capabilities; unsampled modules appear as directory-level subsystem nodes, and edges are limited to relationships supported by excerpts, the source index, or README.

Main entry points: [`src/app/api/whatsapp/inbound/route.ts`](https://github.com/prabhu0023/client-saas/blob/main/src/app/api/whatsapp/inbound/route.ts) (Inbound webhook), [`src/lib/supabase/admin.ts`](https://github.com/prabhu0023/client-saas/blob/main/src/lib/supabase/admin.ts) (Service-role client), [`src/lib/portal/messages.ts`](https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/messages.ts) (Thread data access), [`src/lib/whatsapp/send.ts`](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/send.ts) (WhatsApp sending)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patient["Patient WhatsApp"]
  node_inbound["Inbound webhook<br/>[route.ts]"]
  node_clinic_route["Clinic routing"]
  node_wa_contact["Contact lookup<br/>[wacrm-client.ts]"]
  node_wa_session["Conversation session<br/>[session.ts]"]
  node_text_flow["Message flow<br/>[text-flow.ts]"]
end

subgraph group_booking["Scheduling"]
  node_wa_queries["Booking queries<br/>[query.ts]"]
  node_slot_generation["Slot generation<br/>[slot-generation.ts]"]
  node_timezone["Timezone conversion<br/>[timezone.ts]"]
  node_booking_tx["Booking transaction<br/>[book.ts]"]
  node_reminders["Reminder dispatch<br/>[send-due.ts]"]
  node_cron["Reminder cron<br/>[route.ts]"]
end

subgraph group_staff["Staff Portal"]
  node_appointments["Appointment dashboard<br/>[appointments.ts]"]
  node_availability_portal["Availability management<br/>[actions.ts]"]
  node_availability_page["Availability view<br/>[page.tsx]"]
  node_dashboard["Staff dashboard<br/>[page.tsx]"]
  node_kanban["Appointment board<br/>[KanbanBoard.tsx]"]
  node_dashboard_actions["Appointment actions<br/>[actions.ts]"]
  node_inbox["Patient inbox<br/>[page.tsx]"]
  node_thread_view["Thread detail<br/>[page.tsx]"]
  node_inbox_actions["Inbox actions<br/>[actions.ts]"]
  node_reply_form["Reply form<br/>[ReplyForm.tsx]"]
  node_portal_messages["Thread data access<br/>[messages.ts]"]
end

subgraph group_infra["Data and Messaging"]
  node_supabase[("Supabase database")]
  node_portal_auth["Staff authentication<br/>[auth.ts]"]
  node_server_client["RLS server client<br/>[server.ts]"]
  node_admin_client["Service-role client<br/>[admin.ts]"]
  node_wa_send["WhatsApp sending<br/>[send.ts]"]
end

node_patient_actor(("Patient"))
node_wa_service["WhatsApp / wacrm"]

node_patient_actor -->|"sends message"| node_wa_service
node_wa_service -->|"delivers webhook"| node_inbound
node_inbound -->|"resolves clinic"| node_clinic_route
node_inbound -->|"loads session"| node_wa_session
node_inbound -->|"resolves phone"| node_wa_contact
node_inbound -->|"dispatches text"| node_text_flow
node_text_flow -->|"reads booking data"| node_wa_queries
node_wa_queries -->|"generates slots"| node_slot_generation
node_slot_generation -->|"converts times"| node_timezone
node_text_flow -->|"books appointment"| node_booking_tx
node_inbound -->|"sends response"| node_wa_send
node_wa_send -->|"sends WhatsApp"| node_wa_service
node_wa_service -->|"delivers reply"| node_patient_actor
node_booking_tx -->|"uses service role"| node_admin_client
node_admin_client -->|"reads and writes"| node_supabase
node_slot_generation -->|"reads schedule"| node_admin_client
node_wa_queries -->|"queries records"| node_admin_client
node_availability_page -->|"submits changes"| node_availability_portal
node_availability_page -->|"requires staff"| node_portal_auth
node_availability_page -->|"formats dates"| node_timezone
node_dashboard -->|"loads appointments"| node_appointments
node_dashboard -->|"requires staff"| node_portal_auth
node_dashboard -->|"renders board"| node_kanban
node_kanban -->|"submits transitions"| node_dashboard_actions
node_inbox -->|"loads threads"| node_portal_messages
node_thread_view -->|"loads thread"| node_portal_messages
node_thread_view -->|"renders reply"| node_reply_form
node_reply_form -->|"submits reply"| node_inbox_actions
node_inbox_actions -->|"checks thread"| node_portal_messages
node_inbox_actions -->|"sends staff reply"| node_wa_send
node_portal_messages -->|"uses RLS client"| node_server_client
node_portal_auth -->|"uses auth client"| node_server_client
node_server_client -->|"queries RLS data"| node_supabase
node_cron -->|"runs due reminders"| node_reminders
node_reminders -->|"reads appointments"| node_admin_client
node_reminders -->|"sends reminders"| node_wa_send

click node_inbound "https://github.com/prabhu0023/client-saas/blob/main/src/app/api/whatsapp/inbound/route.ts"
click node_clinic_route "https://github.com/prabhu0023/client-saas/blob/main/src/lib/clinics/resolve-by-account.ts"
click node_wa_contact "https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/wacrm-client.ts"
click node_wa_session "https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/session.ts"
click node_text_flow "https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/text-flow.ts"
click node_wa_queries "https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/query.ts"
click node_slot_generation "https://github.com/prabhu0023/client-saas/blob/main/src/lib/availability/slot-generation.ts"
click node_timezone "https://github.com/prabhu0023/client-saas/blob/main/src/lib/availability/timezone.ts"
click node_booking_tx "https://github.com/prabhu0023/client-saas/blob/main/src/lib/booking/book.ts"
click node_appointments "https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/appointments.ts"
click node_availability_portal "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/availability/actions.ts"
click node_availability_page "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/availability/page.tsx"
click node_dashboard "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/page.tsx"
click node_kanban "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/KanbanBoard.tsx"
click node_dashboard_actions "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/actions.ts"
click node_inbox "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/page.tsx"
click node_thread_view "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/%5BthreadId%5D/page.tsx"
click node_inbox_actions "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/actions.ts"
click node_reply_form "https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/ReplyForm.tsx"
click node_portal_messages "https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/messages.ts"
click node_reminders "https://github.com/prabhu0023/client-saas/blob/main/src/lib/reminders/send-due.ts"
click node_cron "https://github.com/prabhu0023/client-saas/blob/main/src/app/api/cron/reminders/route.ts"
click node_portal_auth "https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/auth.ts"
click node_server_client "https://github.com/prabhu0023/client-saas/blob/main/src/lib/supabase/server.ts"
click node_admin_client "https://github.com/prabhu0023/client-saas/blob/main/src/lib/supabase/admin.ts"
click node_wa_send "https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/send.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_inbound,node_clinic_route,node_wa_contact,node_wa_session,node_text_flow toneBlue
class node_wa_queries,node_slot_generation,node_timezone,node_booking_tx,node_reminders,node_cron toneAmber
class node_appointments,node_availability_portal,node_availability_page,node_dashboard,node_kanban,node_dashboard_actions,node_inbox,node_thread_view,node_inbox_actions,node_reply_form,node_portal_messages toneMint
class node_supabase,node_portal_auth,node_server_client,node_admin_client,node_wa_send toneRose
class node_patient_actor,node_wa_service toneIndigo
```

## Components

### Patient WhatsApp

- [Inbound webhook](https://github.com/prabhu0023/client-saas/blob/main/src/app/api/whatsapp/inbound/route.ts): `src/app/api/whatsapp/inbound/route.ts`
- [Clinic routing](https://github.com/prabhu0023/client-saas/blob/main/src/lib/clinics/resolve-by-account.ts): `src/lib/clinics/resolve-by-account.ts`
- [Contact lookup](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/wacrm-client.ts): `src/lib/whatsapp/wacrm-client.ts`
- [Conversation session](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/session.ts): `src/lib/whatsapp/session.ts`
- [Message flow](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/text-flow.ts): `src/lib/whatsapp/text-flow.ts`

### Scheduling

- [Booking queries](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/query.ts): `src/lib/whatsapp/query.ts`
- [Slot generation](https://github.com/prabhu0023/client-saas/blob/main/src/lib/availability/slot-generation.ts): `src/lib/availability/slot-generation.ts`
- [Timezone conversion](https://github.com/prabhu0023/client-saas/blob/main/src/lib/availability/timezone.ts): `src/lib/availability/timezone.ts`
- [Booking transaction](https://github.com/prabhu0023/client-saas/blob/main/src/lib/booking/book.ts): `src/lib/booking/book.ts`
- [Reminder dispatch](https://github.com/prabhu0023/client-saas/blob/main/src/lib/reminders/send-due.ts): `src/lib/reminders/send-due.ts`
- [Reminder cron](https://github.com/prabhu0023/client-saas/blob/main/src/app/api/cron/reminders/route.ts): `src/app/api/cron/reminders/route.ts`

### Staff Portal

- [Appointment dashboard](https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/appointments.ts): `src/lib/portal/appointments.ts`
- [Availability management](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/availability/actions.ts): `src/app/(portal)/availability/actions.ts`
- [Availability view](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/availability/page.tsx): `src/app/(portal)/availability/page.tsx`
- [Staff dashboard](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/page.tsx): `src/app/(portal)/dashboard/page.tsx`
- [Appointment board](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/KanbanBoard.tsx): `src/app/(portal)/dashboard/KanbanBoard.tsx`
- [Appointment actions](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/dashboard/actions.ts): `src/app/(portal)/dashboard/actions.ts`
- [Patient inbox](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/page.tsx): `src/app/(portal)/inbox/page.tsx`
- [Thread detail](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/%5BthreadId%5D/page.tsx): `src/app/(portal)/inbox/[threadId]/page.tsx`
- [Inbox actions](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/actions.ts): `src/app/(portal)/inbox/actions.ts`
- [Reply form](https://github.com/prabhu0023/client-saas/blob/main/src/app/(portal)/inbox/ReplyForm.tsx): `src/app/(portal)/inbox/ReplyForm.tsx`
- [Thread data access](https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/messages.ts): `src/lib/portal/messages.ts`

### Data and Messaging

- **Supabase database**
- [Staff authentication](https://github.com/prabhu0023/client-saas/blob/main/src/lib/portal/auth.ts): `src/lib/portal/auth.ts`
- [RLS server client](https://github.com/prabhu0023/client-saas/blob/main/src/lib/supabase/server.ts): `src/lib/supabase/server.ts`
- [Service-role client](https://github.com/prabhu0023/client-saas/blob/main/src/lib/supabase/admin.ts): `src/lib/supabase/admin.ts`
- [WhatsApp sending](https://github.com/prabhu0023/client-saas/blob/main/src/lib/whatsapp/send.ts): `src/lib/whatsapp/send.ts`

### Other components

- **Patient**
- **WhatsApp / wacrm**

## Connections

- Patient → WhatsApp / wacrm: sends message (evidence: `README.md`)
- WhatsApp / wacrm → Inbound webhook: delivers webhook (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- Inbound webhook → Clinic routing: resolves clinic (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- Inbound webhook → Conversation session: loads session (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- Inbound webhook → Contact lookup: resolves phone (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- Inbound webhook → Message flow: dispatches text (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- Message flow → Booking queries: reads booking data (evidence: `src/lib/whatsapp/text-flow.ts`)
- Booking queries → Slot generation: generates slots (evidence: `src/lib/whatsapp/query.ts`)
- Slot generation → Timezone conversion: converts times (evidence: `src/lib/availability/slot-generation.ts`)
- Message flow → Booking transaction: books appointment (evidence: `src/lib/whatsapp/text-flow.ts`)
- Inbound webhook → WhatsApp sending: sends response (evidence: `src/app/api/whatsapp/inbound/route.ts`)
- WhatsApp sending → WhatsApp / wacrm: sends WhatsApp (evidence: `src/lib/whatsapp/send.ts`)
- WhatsApp / wacrm → Patient: delivers reply (evidence: `README.md`)
- Booking transaction → Service-role client: uses service role (evidence: `src/lib/booking/book.ts`)
- Service-role client → Supabase database: reads and writes (evidence: `src/lib/supabase/admin.ts`)
- Slot generation → Service-role client: reads schedule (evidence: `src/lib/availability/slot-generation.ts`)
- Booking queries → Service-role client: queries records (evidence: `src/lib/whatsapp/query.ts`)
- Availability view → Availability management: submits changes (evidence: `src/app/(portal)/availability/page.tsx`)
- Availability view → Staff authentication: requires staff (evidence: `src/app/(portal)/availability/page.tsx`)
- Availability view → Timezone conversion: formats dates (evidence: `src/app/(portal)/availability/page.tsx`)
- Staff dashboard → Appointment dashboard: loads appointments (evidence: `src/app/(portal)/dashboard/page.tsx`)
- Staff dashboard → Staff authentication: requires staff (evidence: `src/app/(portal)/dashboard/page.tsx`)
- Staff dashboard → Appointment board: renders board (evidence: `src/app/(portal)/dashboard/page.tsx`)
- Appointment board → Appointment actions: submits transitions (evidence: `src/app/(portal)/dashboard/KanbanBoard.tsx`)
- Patient inbox → Thread data access: loads threads (evidence: `src/app/(portal)/inbox/page.tsx`)
- Thread detail → Thread data access: loads thread (evidence: `src/app/(portal)/inbox/[threadId]/page.tsx`)
- Thread detail → Reply form: renders reply (evidence: `src/app/(portal)/inbox/[threadId]/page.tsx`)
- Reply form → Inbox actions: submits reply (evidence: `src/app/(portal)/inbox/ReplyForm.tsx`)
- Inbox actions → Thread data access: checks thread (evidence: `src/app/(portal)/inbox/actions.ts`)
- Inbox actions → WhatsApp sending: sends staff reply (evidence: `src/app/(portal)/inbox/actions.ts`)
- Thread data access → RLS server client: uses RLS client (evidence: `src/lib/portal/messages.ts`)
- Staff authentication → RLS server client: uses auth client (evidence: `src/lib/portal/auth.ts`)
- RLS server client → Supabase database: queries RLS data (evidence: `src/lib/supabase/server.ts`)
- Reminder cron → Reminder dispatch: runs due reminders (evidence: `src/app/api/cron/reminders/route.ts`)
- Reminder dispatch → Service-role client: reads appointments (evidence: `src/lib/reminders/send-due.ts`)
- Reminder dispatch → WhatsApp sending: sends reminders (evidence: `src/lib/reminders/send-due.ts`)
