# mahdiaziz97/rainbow-hospital architecture

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

- Interactive diagram: https://gitdiagram.com/mahdiaziz97/rainbow-hospital
- Repository: https://github.com/mahdiaziz97/rainbow-hospital

## Overview

#### Purpose and entry points
This is a hospital-facing system split into three applications: a public patient portal, an administrative portal, and a Node.js backend API. The React/Vite clients boot from `Frontend/src/main.jsx` and `Admin/src/main.jsx`; backend startup is `Backend/server.js`.

#### Public patient portal
The public frontend presents hospital content, services, departments, doctors, appointments, contact/enquiry, patient profile, and appointment history. Routing and top-level composition are centered in `Frontend/src/App.jsx`, with page-level flows including `Frontend/src/pages/Home.jsx`, `Frontend/src/pages/Appointment.jsx`, and `Frontend/src/pages/MyAppointments.jsx`.

#### Administrative and staff portal
The separate admin client supports privileged management of doctors, staff, health/OT packages, notices, appointments, and credentials. Application-wide state is divided into role-oriented React contexts: `Admin/src/context/AdminContext.jsx`, `Admin/src/context/StaffContext.jsx`, and `Admin/src/context/AppContext.jsx`. Admin CRUD screens include `Admin/src/pages/Admin/Dashboard.jsx`, `Admin/src/pages/Admin/AddDoctor.jsx`, and `Admin/src/pages/Admin/AllAppointments.jsx`; staff has its own dashboard at `Admin/src/pages/Staff/SDashboard.jsx`.

#### API and authorization boundary
The backend exposes role-segregated route surfaces for public/user, admin, and staff operations through `Backend/routes/userRoute.js`, `Backend/routes/adminRoute.js`, and `Backend/routes/staffRoute.js`. Controllers implement the corresponding request orchestration in `Backend/controllers/userController.js`, `Backend/controllers/adminController.js`, and `Backend/controllers/staffController.js`. Admin authentication is enforced by `Backend/middlewares/authAdmin.js`; password hashing support is isolated in `Backend/Hashing/hashAdmin.js`.

#### Domain persistence
MongoDB is the primary persistence layer, configured in `Backend/config/mongodb.js`. Core domain records cover doctors, staff, notices, packages, bookings, enquiries, and contact submissions: `Backend/models/doctorModel.js`, `Backend/models/staffModel.js`, `Backend/models/allBookingModel.js`, `Backend/models/allEnquiryModel.js`, `Backend/models/healthPackageModel.js`, and `Backend/models/noticeModel.js`. Update-field behavior is centralized in `Backend/modelsModify/updateFields.js`, creating a boundary between controller actions and partial-record mutation logic.

#### Content, uploads, and external infrastructure
The backend supports multipart/file handling via `Backend/middlewares/multer.js`, stores local uploaded documents under `Backend/uploads/pdfs`, and has a Cloudinary integration configuration at `Backend/config/cloudinary.js`. This creates a media boundary: browser clients submit managed content to API endpoints; the backend persists metadata in MongoDB and handles local or cloud-backed assets.

#### Primary flow
Public users consume content and submit appointment, enquiry, contact, or account-related requests through the frontend to user routes. Administrators and staff authenticate through the admin client, then use protected API operations to manage operational records. Updated doctors, packages, notices, and booking data are persisted in MongoDB and subsequently surfaced through the public-facing pages and admin/staff dashboards.

Main entry points: [`Backend/controllers/userController.js`](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/controllers/userController.js) (Request controllers), [`Backend/routes/adminRoute.js`](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/adminRoute.js) (Admin routes), [`Backend/server.js`](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/server.js) (API server), [`Admin/src/context/AdminContext.jsx`](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/context/AdminContext.jsx) (Role state contexts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Patient Portal"]
  node_patient_boot["Patient client boot<br/>React/Vite entry<br/>[main.jsx]"]
  node_patient_app["Patient routes<br/>React application<br/>[App.jsx]"]
  node_patient_flows["Patient request flows<br/>public pages<br/>[Appointment.jsx]"]
end

subgraph group_admin["Admin &amp; Staff Portal"]
  node_admin_boot["Admin client boot<br/>React/Vite entry<br/>[main.jsx]"]
  node_role_contexts["Role state contexts<br/>React contexts<br/>[AdminContext.jsx]"]
  node_admin_operations["Admin operations<br/>admin pages<br/>[Dashboard.jsx]"]
  node_staff_dashboard["Staff dashboard<br/>staff page<br/>[SDashboard.jsx]"]
end

subgraph group_api["Backend API"]
  node_server["API server<br/>Node.js entry<br/>[server.js]"]
  node_user_routes["Public/user routes<br/>route surface<br/>[userRoute.js]"]
  node_admin_routes["Admin routes<br/>protected route surface<br/>[adminRoute.js]"]
  node_staff_routes["Staff routes<br/>route surface<br/>[staffRoute.js]"]
  node_controllers["Request controllers<br/>controller layer<br/>[userController.js]"]
  node_admin_auth["Admin authorization<br/>authentication middleware<br/>[authAdmin.js]"]
  node_admin_hashing["Admin password hashing<br/>security utility<br/>[hashAdmin.js]"]
  node_uploads["Upload handling<br/>multipart middleware<br/>[multer.js]"]
end

subgraph group_data["Data &amp; Media"]
  node_domain_models["Hospital domain models<br/>MongoDB models<br/>[doctorModel.js]"]
  node_update_fields["Partial update policy<br/>mutation utility<br/>[updateFields.js]"]
  node_mongodb[("MongoDB<br/>database configuration<br/>[mongodb.js]")]
  node_asset_storage["Asset storage<br/>local/cloud media<br/>[cloudinary.js]"]
end

node_patient_boot -->|"boots"| node_patient_app
node_patient_app -->|"renders"| node_patient_flows
node_patient_flows -->|"public requests"| node_user_routes
node_admin_boot -->|"provides state"| node_role_contexts
node_role_contexts -->|"drives"| node_admin_operations
node_role_contexts -->|"drives"| node_staff_dashboard
node_admin_operations -->|"admin API calls"| node_admin_routes
node_staff_dashboard -->|"staff API calls"| node_staff_routes
node_server -->|"mounts"| node_user_routes
node_server -->|"mounts"| node_admin_routes
node_server -->|"mounts"| node_staff_routes
node_admin_routes -->|"authorizes"| node_admin_auth
node_admin_auth -.->|"credential support"| node_admin_hashing
node_user_routes -->|"dispatches"| node_controllers
node_admin_routes -->|"dispatches"| node_controllers
node_staff_routes -->|"dispatches"| node_controllers
node_controllers -->|"handles files"| node_uploads
node_controllers -->|"applies partial updates"| node_update_fields
node_controllers -->|"reads and writes"| node_domain_models
node_domain_models -->|"persists"| node_mongodb
node_uploads -->|"stores assets"| node_asset_storage
node_controllers -.->|"stores media metadata"| node_asset_storage

click node_patient_boot "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/main.jsx"
click node_patient_app "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/App.jsx"
click node_patient_flows "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/pages/Appointment.jsx"
click node_admin_boot "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/main.jsx"
click node_role_contexts "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/context/AdminContext.jsx"
click node_admin_operations "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/pages/Admin/Dashboard.jsx"
click node_staff_dashboard "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/pages/Staff/SDashboard.jsx"
click node_server "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/server.js"
click node_user_routes "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/userRoute.js"
click node_admin_routes "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/adminRoute.js"
click node_staff_routes "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/staffRoute.js"
click node_controllers "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/controllers/userController.js"
click node_admin_auth "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/middlewares/authAdmin.js"
click node_admin_hashing "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/Hashing/hashAdmin.js"
click node_uploads "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/middlewares/multer.js"
click node_domain_models "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/models/doctorModel.js"
click node_update_fields "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/modelsModify/updateFields.js"
click node_mongodb "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/config/mongodb.js"
click node_asset_storage "https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/config/cloudinary.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_patient_boot,node_patient_app,node_patient_flows toneBlue
class node_admin_boot,node_role_contexts,node_admin_operations,node_staff_dashboard toneAmber
class node_server,node_user_routes,node_admin_routes,node_staff_routes,node_controllers,node_admin_auth,node_admin_hashing,node_uploads toneMint
class node_domain_models,node_update_fields,node_mongodb,node_asset_storage toneRose
```

## Components

### Patient Portal

- [Patient client boot](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/main.jsx): React/Vite entry · `Frontend/src/main.jsx`
- [Patient routes](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/App.jsx): React application · Composes public pages and navigation. · `Frontend/src/App.jsx`
- [Patient request flows](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Frontend/src/pages/Appointment.jsx): public pages · Home, appointment, and appointment-history experiences. · `Frontend/src/pages/Appointment.jsx`

### Admin & Staff Portal

- [Admin client boot](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/main.jsx): React/Vite entry · `Admin/src/main.jsx`
- [Role state contexts](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/context/AdminContext.jsx): React contexts · Separates admin, staff, and shared application state. · `Admin/src/context/AdminContext.jsx`
- [Admin operations](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/pages/Admin/Dashboard.jsx): admin pages · Dashboard, doctor management, and appointment administration. · `Admin/src/pages/Admin/Dashboard.jsx`
- [Staff dashboard](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Admin/src/pages/Staff/SDashboard.jsx): staff page · `Admin/src/pages/Staff/SDashboard.jsx`

### Backend API

- [API server](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/server.js): Node.js entry · `Backend/server.js`
- [Public/user routes](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/userRoute.js): route surface · `Backend/routes/userRoute.js`
- [Admin routes](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/adminRoute.js): protected route surface · `Backend/routes/adminRoute.js`
- [Staff routes](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/routes/staffRoute.js): route surface · `Backend/routes/staffRoute.js`
- [Request controllers](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/controllers/userController.js): controller layer · Orchestrates user, admin, and staff operations. · `Backend/controllers/userController.js`
- [Admin authorization](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/middlewares/authAdmin.js): authentication middleware · `Backend/middlewares/authAdmin.js`
- [Admin password hashing](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/Hashing/hashAdmin.js): security utility · `Backend/Hashing/hashAdmin.js`
- [Upload handling](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/middlewares/multer.js): multipart middleware · Accepts managed file content for API operations. · `Backend/middlewares/multer.js`

### Data & Media

- [Hospital domain models](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/models/doctorModel.js): MongoDB models · Doctors, staff, bookings, enquiries, packages, and notices. · `Backend/models/doctorModel.js`
- [Partial update policy](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/modelsModify/updateFields.js): mutation utility · `Backend/modelsModify/updateFields.js`
- [MongoDB](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/config/mongodb.js): database configuration · Primary persistence for operational records and content metadata. · `Backend/config/mongodb.js`
- [Asset storage](https://github.com/mahdiaziz97/rainbow-hospital/blob/master/Backend/config/cloudinary.js): local/cloud media · Local PDFs with Cloudinary integration for managed assets. · `Backend/config/cloudinary.js`

## Connections

- Patient client boot → Patient routes: boots
- Patient routes → Patient request flows: renders
- Patient request flows → Public/user routes: public requests
- Admin client boot → Role state contexts: provides state
- Role state contexts → Admin operations: drives
- Role state contexts → Staff dashboard: drives
- Admin operations → Admin routes: admin API calls
- Staff dashboard → Staff routes: staff API calls
- API server → Public/user routes: mounts
- API server → Admin routes: mounts
- API server → Staff routes: mounts
- Admin routes → Admin authorization: authorizes
- Admin authorization → Admin password hashing: credential support
- Public/user routes → Request controllers: dispatches
- Admin routes → Request controllers: dispatches
- Staff routes → Request controllers: dispatches
- Request controllers → Upload handling: handles files
- Request controllers → Partial update policy: applies partial updates
- Request controllers → Hospital domain models: reads and writes
- Hospital domain models → MongoDB: persists
- Upload handling → Asset storage: stores assets
- Request controllers → Asset storage: stores media metadata
