# duchai1703/bookingcare-backend architecture

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

- Interactive diagram: https://gitdiagram.com/duchai1703/bookingcare-backend
- Repository: https://github.com/duchai1703/bookingcare-backend

## Overview

BookingCare is a medical-appointment backend. Its central patient journey is to find a doctor and an available schedule, book an appointment, and complete payment; after the visit, the doctor manages the encounter and the patient can leave a review. The tree also shows clinic and specialty administration, doctor onboarding and financial operations, policy management, and AI assistance. Sampled controller/service code confirms parts of booking, encounter, review, payment, policy, and AI behavior; other subsystem links are limited to their named modules because their implementation was not sampled.

Main entry points: [`src/routes/web.js`](https://github.com/duchai1703/bookingcare-backend/blob/main/src/routes/web.js) (API routes), [`src/models/index.js`](https://github.com/duchai1703/bookingcare-backend/blob/main/src/models/index.js) (Application database), [`src/services/authService.js`](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/authService.js) (Authentication), [`src/controllers/paymentController.js`](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/paymentController.js) (Payment processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_server["HTTP server<br/>[server.js]"]
  node_routes["API routes<br/>[web.js]"]
  node_auth["Authentication<br/>[authService.js]"]
  node_usercontroller["User endpoints<br/>[userController.js]"]
end

subgraph group_care["Care booking"]
  node_catalogcontroller["Catalog endpoints"]
  node_catalogservice["Catalog search<br/>[catalogService.js]"]
  node_patientcontroller["Patient endpoints"]
  node_patientservice["Patient bookings<br/>[patientService.js]"]
  node_doctorcontroller["Doctor endpoints"]
  node_doctorservice["Doctor workflow<br/>[doctorService.js]"]
  node_reviewcontroller["Review endpoints"]
  node_reviewservice["Review service<br/>[reviewService.js]"]
end

subgraph group_operations["Clinic operations"]
  node_clinicops["Clinic management"]
  node_specialtyops["Specialty management"]
  node_onboarding["Doctor onboarding"]
  node_stats["Statistics"]
end

subgraph group_finance["Payments and policy"]
  node_payment["Payment processing"]
  node_policycontroller["Policy endpoints"]
  node_policyservice["Policy engine"]
end

subgraph group_assistance["AI assistance"]
  node_ai["AI streaming<br/>[aiController.js]"]
  node_aifunctions["AI function handlers"]
end

node_patient(("Patient"))
node_doctor(("Doctor"))
node_admin(("Administrator"))
node_db[("Application database<br/>[index.js]")]
node_vnpay["VNPay"]
node_gemini["Gemini API"]
node_email["Email service<br/>[emailService.js]"]

node_server -->|"mounts routes"| node_routes
node_patient -->|"sends requests"| node_routes
node_doctor -->|"sends requests"| node_routes
node_admin -->|"sends requests"| node_routes
node_routes -->|"dispatches"| node_catalogcontroller
node_routes -->|"dispatches"| node_patientcontroller
node_routes -->|"dispatches"| node_doctorcontroller
node_routes -->|"dispatches"| node_reviewcontroller
node_routes -->|"dispatches"| node_payment
node_routes -->|"dispatches"| node_policycontroller
node_routes -->|"dispatches"| node_ai
node_routes -->|"dispatches"| node_usercontroller
node_usercontroller -->|"calls"| node_auth
node_auth -->|"reads and writes"| node_db
node_auth -->|"sends messages"| node_email
node_catalogcontroller -->|"calls"| node_catalogservice
node_catalogservice -->|"queries"| node_db
node_patientcontroller -->|"calls"| node_patientservice
node_patientservice -->|"reads and writes"| node_db
node_doctorcontroller -->|"calls"| node_doctorservice
node_doctorservice -->|"reads and writes"| node_db
node_reviewcontroller -->|"calls"| node_reviewservice
node_reviewservice -->|"validates and stores"| node_db
node_payment -->|"reads and updates"| node_db
node_payment -->|"creates and verifies payments"| node_vnpay
node_policycontroller -->|"calls"| node_policyservice
node_policyservice -->|"resolves and stores policies"| node_db
node_clinicops -->|"manages clinic data"| node_db
node_specialtyops -->|"manages specialty data"| node_db
node_onboarding -->|"stores requests"| node_db
node_stats -->|"queries metrics"| node_db
node_ai -->|"dispatches functions"| node_aifunctions
node_ai -->|"streams model requests"| node_gemini
node_aifunctions -->|"queries booking data"| node_db

click node_server "https://github.com/duchai1703/bookingcare-backend/blob/main/src/server.js"
click node_routes "https://github.com/duchai1703/bookingcare-backend/blob/main/src/routes/web.js"
click node_auth "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/authService.js"
click node_usercontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/userController.js"
click node_catalogcontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/catalogController.js"
click node_catalogservice "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/catalogService.js"
click node_patientcontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/patientController.js"
click node_patientservice "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/patientService.js"
click node_doctorcontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/doctorController.js"
click node_doctorservice "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/doctorService.js"
click node_reviewcontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/reviewController.js"
click node_reviewservice "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/reviewService.js"
click node_clinicops "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/clinicManageService.js"
click node_specialtyops "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/specialtyManageService.js"
click node_onboarding "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/doctorOnboardingService.js"
click node_stats "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/statisticService.js"
click node_payment "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/paymentController.js"
click node_policycontroller "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/policyController.js"
click node_policyservice "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/policyEngineService.js"
click node_ai "https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/aiController.js"
click node_aifunctions "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/aiFunctionHandlers.js"
click node_db "https://github.com/duchai1703/bookingcare-backend/blob/main/src/models/index.js"
click node_email "https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/emailService.js"

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_server,node_routes,node_auth,node_usercontroller toneBlue
class node_catalogcontroller,node_catalogservice,node_patientcontroller,node_patientservice,node_doctorcontroller,node_doctorservice,node_reviewcontroller,node_reviewservice,node_db toneAmber
class node_clinicops,node_specialtyops,node_onboarding,node_stats,node_gemini toneMint
class node_payment,node_policycontroller,node_policyservice toneRose
class node_ai,node_aifunctions,node_patient,node_doctor,node_admin,node_vnpay toneIndigo
class node_email toneTeal
```

## Components

### API entry

- [HTTP server](https://github.com/duchai1703/bookingcare-backend/blob/main/src/server.js): `src/server.js`
- [API routes](https://github.com/duchai1703/bookingcare-backend/blob/main/src/routes/web.js): `src/routes/web.js`
- [Authentication](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/authService.js): `src/services/authService.js`
- [User endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/userController.js): `src/controllers/userController.js`

### Care booking

- [Catalog endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/catalogController.js): `src/controllers/catalogController.js`
- [Catalog search](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/catalogService.js): `src/services/catalogService.js`
- [Patient endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/patientController.js): `src/controllers/patientController.js`
- [Patient bookings](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/patientService.js): `src/services/patientService.js`
- [Doctor endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/doctorController.js): `src/controllers/doctorController.js`
- [Doctor workflow](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/doctorService.js): `src/services/doctorService.js`
- [Review endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/reviewController.js): `src/controllers/reviewController.js`
- [Review service](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/reviewService.js): `src/services/reviewService.js`

### Clinic operations

- [Clinic management](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/clinicManageService.js): `src/services/clinicManageService.js`
- [Specialty management](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/specialtyManageService.js): `src/services/specialtyManageService.js`
- [Doctor onboarding](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/doctorOnboardingService.js): `src/services/doctorOnboardingService.js`
- [Statistics](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/statisticService.js): `src/services/statisticService.js`

### Payments and policy

- [Payment processing](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/paymentController.js): `src/controllers/paymentController.js`
- [Policy endpoints](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/policyController.js): `src/controllers/policyController.js`
- [Policy engine](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/policyEngineService.js): `src/services/policyEngineService.js`

### AI assistance

- [AI streaming](https://github.com/duchai1703/bookingcare-backend/blob/main/src/controllers/aiController.js): `src/controllers/aiController.js`
- [AI function handlers](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/aiFunctionHandlers.js): `src/services/aiFunctionHandlers.js`

### Other components

- **Patient**
- **Doctor**
- **Administrator**
- [Application database](https://github.com/duchai1703/bookingcare-backend/blob/main/src/models/index.js): `src/models/index.js`
- **VNPay**
- **Gemini API**
- [Email service](https://github.com/duchai1703/bookingcare-backend/blob/main/src/services/emailService.js): `src/services/emailService.js`

## Connections

- HTTP server → API routes: mounts routes
- Patient → API routes: sends requests
- Doctor → API routes: sends requests
- Administrator → API routes: sends requests
- API routes → Catalog endpoints: dispatches
- API routes → Patient endpoints: dispatches
- API routes → Doctor endpoints: dispatches
- API routes → Review endpoints: dispatches
- API routes → Payment processing: dispatches
- API routes → Policy endpoints: dispatches
- API routes → AI streaming: dispatches
- API routes → User endpoints: dispatches
- User endpoints → Authentication: calls
- Authentication → Application database: reads and writes
- Authentication → Email service: sends messages
- Catalog endpoints → Catalog search: calls
- Catalog search → Application database: queries
- Patient endpoints → Patient bookings: calls
- Patient bookings → Application database: reads and writes
- Doctor endpoints → Doctor workflow: calls
- Doctor workflow → Application database: reads and writes
- Review endpoints → Review service: calls
- Review service → Application database: validates and stores
- Payment processing → Application database: reads and updates
- Payment processing → VNPay: creates and verifies payments
- Policy endpoints → Policy engine: calls
- Policy engine → Application database: resolves and stores policies
- Clinic management → Application database: manages clinic data
- Specialty management → Application database: manages specialty data
- Doctor onboarding → Application database: stores requests
- Statistics → Application database: queries metrics
- AI streaming → AI function handlers: dispatches functions
- AI streaming → Gemini API: streams model requests
- AI function handlers → Application database: queries booking data
