# abhishek9680/digital-healthcare-system architecture

> Architecture diagram of the GitHub repository abhishek9680/digital-healthcare-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhishek9680/digital-healthcare-system
- Repository: https://github.com/abhishek9680/digital-healthcare-system

## Overview

##### Project type and purpose
- Full-stack healthcare appointment system.
- React SPA with separate dashboards for patients and doctors.
- Express API server implementing MVC (router → controller → model).
- MongoDB Atlas as the database, JWT for stateless authentication.

##### File structure
- Top-level “frontend/” directory: Vite-powered React app, pages, components, API utility, styles.
- Top-level “backend/” directory: Express entry point (index.js), config (db.js), router, controllers, models, auth middleware.
- Separation of concerns:
- frontend handles UI, routing, API calls
- backend exposes REST endpoints, business logic, data persistence
- models define Mongoose schemas for Patient, Doctor, Appointment

##### Key README insights
- Role-based flows: register/login for doctor and patient, protected dashboards.
- Tech stack: React, Node.js, Express, MongoDB, Tailwind CSS, daisyUI.
- Runtime: local dev via Vite (port 5173) and Express (port 3000), environment variables for DB URI and JWT secret.

##### Main components & their interactions
a. Client (Browser/Electron wrapper)
- React UI
- Uses AppRoutes, ProtectedRoute, Navbar, page components
- Calls backend via API functions in src/api.js
b. API Gateway (Express server)
- Routes defined in router/doctorRoute.js and patientRoute.js
- Auth middleware (authMiddleware.js) verifies JWT
- Controllers (doctorController, patientController) implement business logic
c. Persistence Layer
- MongoDB (hosted on Atlas)
- Mongoose models: Doctor, Patient, Appointment
d. External Services
- MongoDB Atlas cluster
- JWT issuer/validator (using JWT_SECRET)

Data flow example:
1. User (Doctor/Patient) fills login form →
2. Frontend (src/api.js) issues POST /login →
3. Express router → authMiddleware (for protected routes) → controller →
4. Mongoose model queries/inserts into MongoDB →
5. Backend returns JSON + JWT →
6. Frontend stores JWT, updates UI (dashboard).

##### Architectural patterns & principles
- Layered architecture (Presentation → API layer → Business logic → Data access)
- MVC on backend:
- Router maps endpoints → Controller applies logic → Model handles DB
- Component-based UI on frontend
- Stateless authentication with JWT
- Role-based access control enforced via ProtectedRoute component and authMiddleware

- Client: User Roles → Browser/Electron → React Components → API Utility
- Server: Express Entry Point → Routers → Auth Middleware → Controllers → Models
- Database: MongoDB Atlas
- Environment variables feeding into the backend (e.g., MONGO_URI, JWT_SECRET).
- Protected routes and JWT validation path.
- Keep it at a single canvas but scalable: group components logically.

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Client Layer"
    Browser["Browser/Electron\n(Client)"]:::external
    ReactApp["React App (Vite)"]:::frontend
    AppRoutes["AppRoutes (Router)"]:::frontend
    ProtectedRoute["ProtectedRoute"]:::frontend
    Navbar["Navbar"]:::frontend
    LandingPage["Landing Page"]:::frontend
    LoginPage["Login Page"]:::frontend
    RegisterPage["Register Page"]:::frontend
    DoctorDashboard["Doctor Dashboard"]:::frontend
    PatientDashboard["Patient Dashboard"]:::frontend
    APIUtil["API Utility"]:::frontend
  end

  subgraph "Server Layer"
    Express["Express Server (index.js)"]:::backend
    DBConfig["db.js (Config)"]:::backend
    DoctorRoute["Doctor Routes"]:::backend
    PatientRoute["Patient Routes"]:::backend
    AuthMW["authMiddleware"]:::backend
    DoctorController["Doctor Controller"]:::backend
    PatientController["Patient Controller"]:::backend
    DoctorModel["Doctor Model"]:::backend
    PatientModel["Patient Model"]:::backend
    AppointmentModel["Appointment Model"]:::backend
  end

  DB["MongoDB Atlas"]:::db

  %% Client flows
  Browser --> ReactApp
  ReactApp --> AppRoutes
  AppRoutes --> LandingPage
  AppRoutes --> LoginPage
  AppRoutes --> RegisterPage
  AppRoutes --> ProtectedRoute
  ProtectedRoute --> DoctorDashboard
  ProtectedRoute --> PatientDashboard
  ReactApp --> APIUtil
  Navbar --- AppRoutes

  %% API calls
  APIUtil -->|"REST API calls\nPOST/GET"| Express

  %% Server flows
  Express --> DBConfig
  DBConfig --> DB
  Express --> DoctorRoute
  Express --> PatientRoute
  DoctorRoute -->|"Protected"| AuthMW
  PatientRoute -->|"Protected"| AuthMW
  AuthMW --> DoctorController
  AuthMW --> PatientController
  DoctorRoute --> DoctorController
  PatientRoute --> PatientController
  DoctorController --> DoctorModel
  PatientController --> PatientModel
  DoctorController --> AppointmentModel
  PatientController --> AppointmentModel
  DoctorModel --> DB
  PatientModel --> DB
  AppointmentModel --> DB

  %% Click events
  click ReactApp "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/main.jsx"
  click AppRoutes "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/AppRoutes.jsx"
  click APIUtil "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/api.js"
  click ProtectedRoute "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/components/ProtectedRoute.jsx"
  click Navbar "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/components/Navbar.jsx"
  click LandingPage "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/pages/landing/LandingPage.jsx"
  click LoginPage "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/pages/login/LoginPage.jsx"
  click RegisterPage "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/pages/register/RegisterPage.jsx"
  click DoctorDashboard "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/pages/doctor_dashboard/Doctordashboard.jsx"
  click PatientDashboard "https://github.com/abhishek9680/digital-healthcare-system/blob/main/frontend/src/pages/patient_dashboard/Patientdashboard.jsx"
  click Express "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/index.js"
  click DBConfig "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/config/db.js"
  click DoctorRoute "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/router/doctorRoute.js"
  click PatientRoute "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/router/patientRoute.js"
  click AuthMW "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/middleware/authMiddleware.js"
  click DoctorController "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/controllers/doctorController.js"
  click PatientController "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/controllers/patientController.js"
  click DoctorModel "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/models/Doctor.js"
  click PatientModel "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/models/Patient.js"
  click AppointmentModel "https://github.com/abhishek9680/digital-healthcare-system/blob/main/backend/models/Appointment.js"

  %% Styles
  classDef frontend fill:#BBE1FA,stroke:#22577A,stroke-width:1px
  classDef backend fill:#B5EAD7,stroke:#2F4858,stroke-width:1px
  classDef db fill:#FFDAC1,stroke:#D65A31,stroke-width:1px
  classDef external fill:#CBAACB,stroke:#6A0572,stroke-width:1px
```
