# harshitsingh4321/appointy architecture

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

- Interactive diagram: https://gitdiagram.com/harshitsingh4321/appointy
- Repository: https://github.com/harshitsingh4321/appointy

## Overview

1. This repository is split into three main deployable parts: a patient-facing React app in `frontend/`, an admin/doctor-facing React app in `admin/`, and a Node/Express API in `backend/`. The architecture is a classic MERN-style split where both UIs consume the same backend and database.

2. The `frontend/` app is the public booking experience. Its pages cover home, doctor browsing, appointment booking, profile management, login, about, and contact. The UI is organized around reusable components like the header, navbar, footer, doctor cards, speciality menu, and top-doctors lists.

3. The `admin/` app is a separate React frontend for privileged users. It contains admin dashboards for analytics, doctor management, and appointment oversight, plus doctor-specific pages for doctor dashboard, appointments, and profile. This separation indicates role-specific UX and probably independent routing/auth guards per role.

4. Both frontends use React Context for shared client-side state. The patient app has `AppContext`, while the admin app includes `AppContext`, `AdminContext`, and `DoctorContext`. These contexts likely hold session data, current user/doctor records, appointment state, and shared API results that multiple components need.

5. The backend is an Express application entrypointed from `backend/server.js`. Routes are divided by role into `userRoute.js`, `doctorRoute.js`, and `adminRoute.js`, which keeps patient, doctor, and admin APIs separated at the boundary level rather than mixing them in one controller surface.

6. The backend data model is centered on three MongoDB collections: users, doctors, and appointments. `userModel.js`, `doctorModel.js`, and `appointmentModel.js` define the persistence layer and form the core data flow for booking, profile updates, dashboards, and status changes.

7. Authentication and authorization are enforced with role-specific middleware: `authUser`, `authDoctor`, and `authAdmin`. This is a key architectural boundary because each frontend can call only the APIs allowed for its role, and the backend can reject cross-role access even if a client is compromised.

8. File upload and image hosting are handled as a separate subsystem. `multer.js` suggests multipart upload handling on the API side, while `cloudinary.js` indicates uploaded doctor/user images are stored in Cloudinary rather than directly in MongoDB or the app server filesystem.

9. The main transactional flow is appointment booking. A patient selects a doctor in the frontend, submits booking details and payment choice, the backend creates an appointment record, and later doctor/admin panels update that appointment’s status to completed or canceled. The README mentions payment methods such as cash and Razorpay; the repo structure suggests payment logic is integrated into the appointment/API layer rather than isolated in a dedicated payment service.

10. The doctor/admin dashboards are derived views over appointment and user data. Admin pages aggregate totals like doctors, patients, and bookings; doctor pages aggregate earnings, appointment lists, and availability/profile state. These are read-heavy dashboard views backed by the same appointment and doctor collections.

11. Both frontends are built with Vite and styled with Tailwind/PostCSS, which affects architecture mainly at the presentation layer. The presence of `vercel.json` in both frontend folders suggests the React apps are deployed independently from the backend, likely as separate static SPA deployments.

12. A useful way to draw the system is: two browser clients on the left, a shared Express API in the middle, MongoDB plus Cloudinary as backend dependencies on the right, and role-based middleware guarding the API boundaries. The central business object connecting almost everything is the appointment.

Main entry points: [`backend/routes/userRoute.js`](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/userRoute.js) (User API), [`frontend/src/App.jsx`](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/App.jsx) (Patient SPA), [`backend/routes/doctorRoute.js`](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/doctorRoute.js) (Doctor API), [`backend/routes/adminRoute.js`](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/adminRoute.js) (Admin API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Patient App"]
  node_frontend_app["Patient SPA<br/>React/Vite app<br/>[App.jsx]"]
  node_frontend_context(("App state<br/>React context<br/>[AppContext.jsx]"))
  node_frontend_nav["UI shell<br/>layout components<br/>[Header.jsx]"]
  node_frontend_doctors["Doctor browsing<br/>pages/components<br/>[Doctors.jsx]"]
  node_frontend_booking["Booking flow<br/>appointment pages<br/>[Appointment.jsx]"]
  node_frontend_auth["Login & profile<br/>account pages<br/>[Login.jsx]"]
end

subgraph group_group_admin["Admin App"]
  node_admin_app["Admin SPA<br/>React/Vite app<br/>[App.jsx]"]
  node_admin_contexts(("Role state<br/>React context<br/>[AdminContext.jsx]"))
  node_admin_shell["Admin shell<br/>layout components<br/>[Sidebar.jsx]"]
  node_admin_dashboards["Dashboards<br/>dashboard pages<br/>[Dashboard.jsx]"]
  node_admin_ops["Operations<br/>management pages<br/>[AddDoctor.jsx]"]
end

subgraph group_group_backend["API Server"]
  node_api_server["Express API<br/>Node/Express app<br/>[server.js]"]
  node_api_user_routes["User API<br/>route/controller<br/>[userRoute.js]"]
  node_api_doctor_routes["Doctor API<br/>route/controller<br/>[doctorRoute.js]"]
  node_api_admin_routes["Admin API<br/>route/controller<br/>[adminRoute.js]"]
  node_api_auth{{"Role guards<br/>middleware<br/>[authUser.js]"}}
  node_api_storage[("Upload & cloud<br/>infrastructure<br/>[cloudinary.js]")]
  node_api_models[("Core models<br/>MongoDB models")]
end

node_frontend_app -->|"uses"| node_frontend_context
node_frontend_app -->|"renders"| node_frontend_nav
node_frontend_app -->|"routes to"| node_frontend_doctors
node_frontend_app -->|"routes to"| node_frontend_booking
node_frontend_app -->|"routes to"| node_frontend_auth
node_frontend_booking -->|"calls"| node_api_user_routes
node_frontend_doctors -->|"calls"| node_api_user_routes
node_admin_app -->|"uses"| node_admin_contexts
node_admin_app -->|"renders"| node_admin_shell
node_admin_app -->|"routes to"| node_admin_dashboards
node_admin_app -->|"routes to"| node_admin_ops
node_admin_dashboards -->|"calls"| node_api_admin_routes
node_admin_ops -->|"calls"| node_api_admin_routes
node_admin_dashboards -->|"calls"| node_api_doctor_routes
node_admin_ops -->|"calls"| node_api_doctor_routes
node_api_server -->|"mounts"| node_api_user_routes
node_api_server -->|"mounts"| node_api_doctor_routes
node_api_server -->|"mounts"| node_api_admin_routes
node_api_user_routes -->|"protected by"| node_api_auth
node_api_doctor_routes -->|"protected by"| node_api_auth
node_api_admin_routes -->|"protected by"| node_api_auth
node_api_user_routes -->|"reads/writes"| node_api_models
node_api_doctor_routes -->|"reads/writes"| node_api_models
node_api_admin_routes -->|"reads/writes"| node_api_models
node_api_user_routes -->|"uploads"| node_api_storage
node_api_storage -->|"enriches"| node_api_models

click node_frontend_app "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/App.jsx"
click node_frontend_context "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/context/AppContext.jsx"
click node_frontend_nav "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/components/Header.jsx"
click node_frontend_doctors "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/pages/Doctors.jsx"
click node_frontend_booking "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/Appointment.jsx"
click node_frontend_auth "https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/pages/Login.jsx"
click node_admin_app "https://github.com/harshitsingh4321/appointy/blob/master/admin/src/App.jsx"
click node_admin_contexts "https://github.com/harshitsingh4321/appointy/blob/master/admin/src/context/AdminContext.jsx"
click node_admin_shell "https://github.com/harshitsingh4321/appointy/blob/master/admin/src/components/Sidebar.jsx"
click node_admin_dashboards "https://github.com/harshitsingh4321/appointy/blob/master/admin/src/pages/Admin/Dashboard.jsx"
click node_admin_ops "https://github.com/harshitsingh4321/appointy/blob/master/admin/src/pages/Admin/AddDoctor.jsx"
click node_api_server "https://github.com/harshitsingh4321/appointy/blob/master/backend/server.js"
click node_api_user_routes "https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/userRoute.js"
click node_api_doctor_routes "https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/doctorRoute.js"
click node_api_admin_routes "https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/adminRoute.js"
click node_api_auth "https://github.com/harshitsingh4321/appointy/blob/master/backend/middlewares/authUser.js"
click node_api_storage "https://github.com/harshitsingh4321/appointy/blob/master/backend/config/cloudinary.js"
click node_api_models "https://github.com/harshitsingh4321/appointy/blob/master/backend/models/appointmentModel.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_frontend_app,node_frontend_context,node_frontend_nav,node_frontend_doctors,node_frontend_booking,node_frontend_auth toneBlue
class node_admin_app,node_admin_contexts,node_admin_shell,node_admin_dashboards,node_admin_ops toneAmber
class node_api_server,node_api_user_routes,node_api_doctor_routes,node_api_admin_routes,node_api_auth,node_api_storage,node_api_models toneMint
```

## Components

### Patient App

Public booking experience for patients.

- [Patient SPA](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/App.jsx): React/Vite app · Public-facing booking and profile experience. · `frontend/src/App.jsx`
- [App state](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/context/AppContext.jsx): React context · Shared client state for appointments, profile, and API data. · `frontend/src/context/AppContext.jsx`
- [UI shell](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/components/Header.jsx): layout components · Header, navbar, footer, and home-page marketing sections. · `frontend/src/components/Header.jsx`
- [Doctor browsing](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/pages/Doctors.jsx): pages/components · Doctor discovery, speciality filtering, and doctor detail listings. · `frontend/src/pages/Doctors.jsx`
- [Booking flow](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/Appointment.jsx): appointment pages · Appointment creation, My Appointments, and profile management. · `frontend/src/Appointment.jsx`
- [Login & profile](https://github.com/harshitsingh4321/appointy/blob/master/frontend/src/pages/Login.jsx): account pages · Authentication entry and patient account pages. · `frontend/src/pages/Login.jsx`

### Admin App

Privileged admin and doctor interface.

- [Admin SPA](https://github.com/harshitsingh4321/appointy/blob/master/admin/src/App.jsx): React/Vite app · Separate privileged interface for admins and doctors. · `admin/src/App.jsx`
- [Role state](https://github.com/harshitsingh4321/appointy/blob/master/admin/src/context/AdminContext.jsx): React context · Admin, doctor, and shared app context for role-specific state. · `admin/src/context/AdminContext.jsx`
- [Admin shell](https://github.com/harshitsingh4321/appointy/blob/master/admin/src/components/Sidebar.jsx): layout components · Sidebar and top navigation for the dashboard interface. · `admin/src/components/Sidebar.jsx`
- [Dashboards](https://github.com/harshitsingh4321/appointy/blob/master/admin/src/pages/Admin/Dashboard.jsx): dashboard pages · Admin and doctor overview screens for totals, earnings, and activity. · `admin/src/pages/Admin/Dashboard.jsx`
- [Operations](https://github.com/harshitsingh4321/appointy/blob/master/admin/src/pages/Admin/AddDoctor.jsx): management pages · Doctor management, appointment oversight, and doctor profile pages. · `admin/src/pages/Admin/AddDoctor.jsx`

### API Server

Express backend with routes, auth, and persistence.

- [Express API](https://github.com/harshitsingh4321/appointy/blob/master/backend/server.js): Node/Express app · Backend entrypoint that mounts role-specific routes. · `backend/server.js`
- [User API](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/userRoute.js): route/controller · Patient-facing endpoints for profiles, booking, and appointments. · `backend/routes/userRoute.js`
- [Doctor API](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/doctorRoute.js): route/controller · Doctor endpoints for dashboard data, appointments, and profile updates. · `backend/routes/doctorRoute.js`
- [Admin API](https://github.com/harshitsingh4321/appointy/blob/master/backend/routes/adminRoute.js): route/controller · Admin endpoints for doctor management and aggregate reporting. · `backend/routes/adminRoute.js`
- [Role guards](https://github.com/harshitsingh4321/appointy/blob/master/backend/middlewares/authUser.js): middleware · Auth middleware for users, doctors, and admins. · `backend/middlewares/authUser.js`
- [Upload & cloud](https://github.com/harshitsingh4321/appointy/blob/master/backend/config/cloudinary.js): infrastructure · Multipart upload handling and Cloudinary image storage. · `backend/config/cloudinary.js`
- [Core models](https://github.com/harshitsingh4321/appointy/blob/master/backend/models/appointmentModel.js): MongoDB models · User, doctor, and appointment persistence models. · `backend/models/appointmentModel.js`

## Connections

- Patient SPA → App state: uses · Patient UI reads shared client state.
- Patient SPA → UI shell: renders · Main app composes the shell and home experience.
- Patient SPA → Doctor browsing: routes to · Users browse doctors and specialities.
- Patient SPA → Booking flow: routes to · Users book and track appointments.
- Patient SPA → Login & profile: routes to · Users log in and manage profile.
- Booking flow → User API: calls · Booking and appointment actions go through user APIs.
- Doctor browsing → User API: calls · Doctor browsing uses backend data.
- Admin SPA → Role state: uses · Role-aware shared state in the admin area.
- Admin SPA → Admin shell: renders · Dashboard layout is built from shell components.
- Admin SPA → Dashboards: routes to · Admin and doctor overview screens.
- Admin SPA → Operations: routes to · Doctor and appointment management screens.
- Dashboards → Admin API: calls · Dashboard metrics come from admin endpoints.
- Operations → Admin API: calls · Management actions go through admin APIs.
- Dashboards → Doctor API: calls · Doctor dashboard pulls role-specific summaries.
- Operations → Doctor API: calls · Doctor profile and appointment views use doctor APIs.
- Express API → User API: mounts · Server exposes the patient route set.
- Express API → Doctor API: mounts · Server exposes doctor endpoints.
- Express API → Admin API: mounts · Server exposes admin endpoints.
- User API → Role guards: protected by · User requests are role-checked.
- Doctor API → Role guards: protected by · Doctor requests are role-checked.
- Admin API → Role guards: protected by · Admin requests are role-checked.
- User API → Core models: reads/writes · User flows touch users, doctors, and appointments.
- Doctor API → Core models: reads/writes · Doctor flows use appointments and doctor records.
- Admin API → Core models: reads/writes · Admin workflows manage core collections.
- User API → Upload & cloud: uploads · Profile/image uploads are handled separately.
- Upload & cloud → Core models: enriches · Stored image URLs and metadata support records.
