# dranzio/bungipin-clinic architecture

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

- Interactive diagram: https://gitdiagram.com/dranzio/bungipin-clinic
- Repository: https://github.com/dranzio/bungipin-clinic

## Overview

Bungipin Clinic is a role-based dental clinic management application, with a primary Express application and a separate backend API implementation. The main workflow is patient appointment booking and management, including schedule/slot checks and payment; clinic staff manage schedules, queues, patient records, and payments, while administrators manage services, users, and audit activity. Evidence is limited to the README, source index, and sampled excerpts, so unsampled subsystem links are omitted where not supported.

Main entry points: [`app.js`](https://github.com/dranzio/bungipin-clinic/blob/main/app.js) (Express application), [`Services/PaymongoWebhook.js`](https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymongoWebhook.js) (Payment webhook), [`Customer/BookingRoutes.js`](https://github.com/dranzio/bungipin-clinic/blob/main/Customer/BookingRoutes.js) (Appointment booking), [`Services/PaymentRoutes.js`](https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymentRoutes.js) (Payment workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_main["Clinic application"]
  node_mainapp["Express application<br/>[app.js]"]
  node_booking["Appointment booking<br/>[BookingRoutes.js]"]
  node_history["Appointment history<br/>[HistoryRoutes.js]"]
  node_db[("Clinic MySQL pool<br/>[db.js]")]
end

subgraph group_ops["Clinic operations"]
  node_scheduling["Doctor schedules"]
  node_queue["Queue management<br/>[QueueRoutes.js]"]
  node_records["Patient records<br/>[PatientRecords.js]"]
  node_employee["Staff booking requests<br/>[BookingRequest.js]"]
  node_services["Service catalog<br/>[ServiceRoutes.js]"]
end

subgraph group_identity["Identity and oversight"]
  node_auth["Authentication<br/>[auth.js]"]
  node_authmw["Request authorization<br/>[authMiddleware.js]"]
  node_users["User administration<br/>[UserManage.js]"]
  node_audit["Audit logging<br/>[auditLogRoutes.js]"]
end

subgraph group_payments["Payments"]
  node_paymentroutes["Payment workflows<br/>[PaymentRoutes.js]"]
  node_webhook["Payment webhook<br/>[PaymongoWebhook.js]"]
  node_payclient["PayMongo client<br/>[paymongo.js]"]
  node_email["Appointment email"]
end

subgraph group_backend["Separate backend API"]
  node_backendapp["Backend Express app<br/>[app.js]"]
  node_backendroutes["Backend route modules"]
  node_appointmentcontroller["Appointment controller"]
  node_backendauth["Backend token middleware<br/>[authMiddleware.js]"]
  node_backenddb[("Backend MySQL pool<br/>[db.js]")]
end

node_patient(("Patient"))
node_staff(("Clinic staff"))
node_admin(("Administrator"))
node_paymongo{{"PayMongo"}}

node_patient -.->|"uses"| node_mainapp
node_staff -.->|"uses"| node_mainapp
node_admin -.->|"uses"| node_mainapp
node_mainapp -->|"registers"| node_booking
node_mainapp -->|"registers"| node_history
node_mainapp -->|"registers"| node_scheduling
node_mainapp -->|"registers"| node_queue
node_mainapp -->|"registers"| node_records
node_mainapp -->|"registers"| node_employee
node_mainapp -->|"registers"| node_services
node_mainapp -->|"registers"| node_paymentroutes
node_mainapp -->|"registers"| node_webhook
node_mainapp -->|"loads"| node_auth
node_booking -->|"authenticates"| node_authmw
node_history -->|"authenticates"| node_authmw
node_scheduling -->|"authenticates"| node_authmw
node_employee -->|"authenticates"| node_authmw
node_services -->|"authenticates"| node_authmw
node_booking -->|"creates checkout"| node_payclient
node_booking -->|"sends email"| node_email
node_history -->|"syncs payments"| node_webhook
node_paymentroutes -->|"creates checkout"| node_payclient
node_paymentroutes -->|"reconciles via"| node_webhook
node_paymentroutes -->|"sends email"| node_email
node_webhook -->|"verifies payment"| node_payclient
node_webhook -->|"sends email"| node_email
node_paymongo -->|"posts events"| node_webhook
node_booking -->|"logs activity"| node_audit
node_history -->|"logs activity"| node_audit
node_services -->|"logs activity"| node_audit
node_paymentroutes -->|"logs activity"| node_audit
node_webhook -->|"logs activity"| node_audit
node_auth -->|"queries"| node_db
node_authmw -->|"checks session"| node_db
node_services -->|"queries"| node_db
node_booking -->|"reads and writes"| node_db
node_paymentroutes -->|"reads and writes"| node_db
node_backendapp -->|"mounts routes"| node_backendroutes
node_backendroutes -->|"dispatches"| node_appointmentcontroller
node_backendroutes -->|"checks tokens"| node_backendauth
node_appointmentcontroller -->|"queries"| node_backenddb

click node_mainapp "https://github.com/dranzio/bungipin-clinic/blob/main/app.js"
click node_booking "https://github.com/dranzio/bungipin-clinic/blob/main/Customer/BookingRoutes.js"
click node_history "https://github.com/dranzio/bungipin-clinic/blob/main/Customer/HistoryRoutes.js"
click node_scheduling "https://github.com/dranzio/bungipin-clinic/blob/main/Employee/doctorScheduleRoutes.js"
click node_queue "https://github.com/dranzio/bungipin-clinic/blob/main/Employee/QueueRoutes.js"
click node_records "https://github.com/dranzio/bungipin-clinic/blob/main/Employee/PatientRecords.js"
click node_employee "https://github.com/dranzio/bungipin-clinic/blob/main/Employee/BookingRequest.js"
click node_services "https://github.com/dranzio/bungipin-clinic/blob/main/Admin/ServiceRoutes.js"
click node_auth "https://github.com/dranzio/bungipin-clinic/blob/main/auth.js"
click node_authmw "https://github.com/dranzio/bungipin-clinic/blob/main/authMiddleware.js"
click node_users "https://github.com/dranzio/bungipin-clinic/blob/main/Admin/UserManage.js"
click node_audit "https://github.com/dranzio/bungipin-clinic/blob/main/Admin/auditLogRoutes.js"
click node_paymentroutes "https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymentRoutes.js"
click node_webhook "https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymongoWebhook.js"
click node_payclient "https://github.com/dranzio/bungipin-clinic/blob/main/Services/paymongo.js"
click node_email "https://github.com/dranzio/bungipin-clinic/blob/main/AppointmentEmails.js"
click node_backendapp "https://github.com/dranzio/bungipin-clinic/blob/main/backend/app.js"
click node_backendroutes "https://github.com/dranzio/bungipin-clinic/blob/main/backend/routes/appointmentRoutes.js"
click node_appointmentcontroller "https://github.com/dranzio/bungipin-clinic/blob/main/backend/controllers/appointmentController.js"
click node_backendauth "https://github.com/dranzio/bungipin-clinic/blob/main/backend/middleware/authMiddleware.js"
click node_db "https://github.com/dranzio/bungipin-clinic/blob/main/db.js"
click node_backenddb "https://github.com/dranzio/bungipin-clinic/blob/main/backend/config/db.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_mainapp,node_booking,node_history,node_db toneBlue
class node_scheduling,node_queue,node_records,node_employee,node_services toneAmber
class node_auth,node_authmw,node_users,node_audit toneMint
class node_paymentroutes,node_webhook,node_payclient,node_email toneRose
class node_backendapp,node_backendroutes,node_appointmentcontroller,node_backendauth,node_backenddb,node_patient,node_staff,node_admin,node_paymongo toneIndigo
```

## Components

### Clinic application

- [Express application](https://github.com/dranzio/bungipin-clinic/blob/main/app.js): `app.js`
- [Appointment booking](https://github.com/dranzio/bungipin-clinic/blob/main/Customer/BookingRoutes.js): `Customer/BookingRoutes.js`
- [Appointment history](https://github.com/dranzio/bungipin-clinic/blob/main/Customer/HistoryRoutes.js): `Customer/HistoryRoutes.js`
- [Clinic MySQL pool](https://github.com/dranzio/bungipin-clinic/blob/main/db.js): `db.js`

### Clinic operations

- [Doctor schedules](https://github.com/dranzio/bungipin-clinic/blob/main/Employee/doctorScheduleRoutes.js): `Employee/doctorScheduleRoutes.js`
- [Queue management](https://github.com/dranzio/bungipin-clinic/blob/main/Employee/QueueRoutes.js): `Employee/QueueRoutes.js`
- [Patient records](https://github.com/dranzio/bungipin-clinic/blob/main/Employee/PatientRecords.js): `Employee/PatientRecords.js`
- [Staff booking requests](https://github.com/dranzio/bungipin-clinic/blob/main/Employee/BookingRequest.js): `Employee/BookingRequest.js`
- [Service catalog](https://github.com/dranzio/bungipin-clinic/blob/main/Admin/ServiceRoutes.js): `Admin/ServiceRoutes.js`

### Identity and oversight

- [Authentication](https://github.com/dranzio/bungipin-clinic/blob/main/auth.js): `auth.js`
- [Request authorization](https://github.com/dranzio/bungipin-clinic/blob/main/authMiddleware.js): `authMiddleware.js`
- [User administration](https://github.com/dranzio/bungipin-clinic/blob/main/Admin/UserManage.js): `Admin/UserManage.js`
- [Audit logging](https://github.com/dranzio/bungipin-clinic/blob/main/Admin/auditLogRoutes.js): `Admin/auditLogRoutes.js`

### Payments

- [Payment workflows](https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymentRoutes.js): `Services/PaymentRoutes.js`
- [Payment webhook](https://github.com/dranzio/bungipin-clinic/blob/main/Services/PaymongoWebhook.js): `Services/PaymongoWebhook.js`
- [PayMongo client](https://github.com/dranzio/bungipin-clinic/blob/main/Services/paymongo.js): `Services/paymongo.js`
- [Appointment email](https://github.com/dranzio/bungipin-clinic/blob/main/AppointmentEmails.js): `AppointmentEmails.js`

### Separate backend API

- [Backend Express app](https://github.com/dranzio/bungipin-clinic/blob/main/backend/app.js): `backend/app.js`
- [Backend route modules](https://github.com/dranzio/bungipin-clinic/blob/main/backend/routes/appointmentRoutes.js): `backend/routes/appointmentRoutes.js`
- [Appointment controller](https://github.com/dranzio/bungipin-clinic/blob/main/backend/controllers/appointmentController.js): `backend/controllers/appointmentController.js`
- [Backend token middleware](https://github.com/dranzio/bungipin-clinic/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [Backend MySQL pool](https://github.com/dranzio/bungipin-clinic/blob/main/backend/config/db.js): `backend/config/db.js`

### Other components

- **Patient**
- **Clinic staff**
- **Administrator**
- **PayMongo**

## Connections

- Patient → Express application: uses
- Clinic staff → Express application: uses
- Administrator → Express application: uses
- Express application → Appointment booking: registers (evidence: `app.js`)
- Express application → Appointment history: registers (evidence: `app.js`)
- Express application → Doctor schedules: registers (evidence: `app.js`)
- Express application → Queue management: registers (evidence: `app.js`)
- Express application → Patient records: registers (evidence: `app.js`)
- Express application → Staff booking requests: registers (evidence: `app.js`)
- Express application → Service catalog: registers (evidence: `app.js`)
- Express application → Payment workflows: registers (evidence: `app.js`)
- Express application → Payment webhook: registers (evidence: `app.js`)
- Express application → Authentication: loads (evidence: `app.js`)
- Appointment booking → Request authorization: authenticates (evidence: `Customer/BookingRoutes.js`)
- Appointment history → Request authorization: authenticates (evidence: `Customer/HistoryRoutes.js`)
- Doctor schedules → Request authorization: authenticates (evidence: `Employee/doctorScheduleRoutes.js`)
- Staff booking requests → Request authorization: authenticates (evidence: `Employee/BookingRequest.js`)
- Service catalog → Request authorization: authenticates (evidence: `Admin/ServiceRoutes.js`)
- Appointment booking → PayMongo client: creates checkout (evidence: `Customer/BookingRoutes.js`)
- Appointment booking → Appointment email: sends email (evidence: `Customer/BookingRoutes.js`)
- Appointment history → Payment webhook: syncs payments (evidence: `Customer/HistoryRoutes.js`)
- Payment workflows → PayMongo client: creates checkout (evidence: `Services/PaymentRoutes.js`)
- Payment workflows → Payment webhook: reconciles via (evidence: `Services/PaymentRoutes.js`)
- Payment workflows → Appointment email: sends email (evidence: `Services/PaymentRoutes.js`)
- Payment webhook → PayMongo client: verifies payment (evidence: `Services/PaymongoWebhook.js`)
- Payment webhook → Appointment email: sends email (evidence: `Services/PaymongoWebhook.js`)
- PayMongo → Payment webhook: posts events (evidence: `Services/PaymongoWebhook.js`)
- Appointment booking → Audit logging: logs activity (evidence: `Customer/BookingRoutes.js`)
- Appointment history → Audit logging: logs activity (evidence: `Customer/HistoryRoutes.js`)
- Service catalog → Audit logging: logs activity (evidence: `Admin/ServiceRoutes.js`)
- Payment workflows → Audit logging: logs activity (evidence: `Services/PaymentRoutes.js`)
- Payment webhook → Audit logging: logs activity (evidence: `Services/PaymongoWebhook.js`)
- Authentication → Clinic MySQL pool: queries (evidence: `auth.js`)
- Request authorization → Clinic MySQL pool: checks session (evidence: `authMiddleware.js`)
- Service catalog → Clinic MySQL pool: queries (evidence: `Admin/ServiceRoutes.js`)
- Appointment booking → Clinic MySQL pool: reads and writes (evidence: `Customer/BookingRoutes.js`)
- Payment workflows → Clinic MySQL pool: reads and writes (evidence: `Services/PaymentRoutes.js`)
- Backend Express app → Backend route modules: mounts routes (evidence: `backend/app.js`)
- Backend route modules → Appointment controller: dispatches (evidence: `backend/routes/appointmentRoutes.js`)
- Backend route modules → Backend token middleware: checks tokens (evidence: `backend/routes/appointmentRoutes.js`)
- Appointment controller → Backend MySQL pool: queries (evidence: `backend/controllers/appointmentController.js`)
