# mohamedboukthir/doctor-appointment-booking-mern-stack architecture

> Architecture diagram of the GitHub repository mohamedboukthir/doctor-appointment-booking-mern-stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamedboukthir/doctor-appointment-booking-mern-stack
- Repository: https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack

## Overview

##### Project Type and Purpose
- This is a full‑stack web application built with the MERN stack (MongoDB, Express, React, Node.js) plus Stripe for payments.
- Purpose: Allow patients to sign up/in, browse doctors, book appointments, leave reviews, and pay via Stripe.

##### File Structure
- Top‐level splits: “frontend/” (React client) and “backend/” (Node/Express API).
- backend/Controllers, backend/Routes, backend/models → MVC pattern.
- backend/auth/verifyToken.js → JWT‑based auth middleware.
- Configuration: .env.example for secrets, package.json, index.js as entry point.
- frontend/src → React components, pages, routes, utils, assets. Vite for bundling, Tailwind for styling.

##### Extract Insights from README
- Confirms MERN stack, Stripe integration for payments, core flows (book appointments, user auth).

##### Main Components & Interactions
a. Frontend (React SPA)
- Pages (Home, Login, Signup, Doctors list/details, Feedback, Contact)
- Components (Header/Footer, DoctorCard, ServiceList, FaqList, etc.)
- Router (frontend/src/routes/Routers.jsx) handles client‑side navigation
- Util (formatDate) for UI data formatting
b. Backend (Node.js + Express)
- Routes: /auth, /user, /doctor, /review (defined under backend/Routes/*.js)
- Controllers: Business logic for each route (CRUD operations in backend/Controllers)
- Models: Mongoose schemas for User, Doctor, Booking, Review
- Auth Middleware: verifyToken protects endpoints requiring authentication
c. Database
- MongoDB (cloud or local), stores users, doctors, bookings, reviews
d. External Services
- Stripe: handles payment intents & webhooks
- (Optional) Email provider or SMS for notifications

##### Architectural Patterns & Principles
- Client‑Server: React SPA ↔ RESTful Express API
- MVC on Server: Models ↔ Controllers ↔ Routes
- JWT Authentication: Stateless token flow
- Third‑Party Integration: Stripe as external payment processor
- Single Page Application: Frontend routing & state

a. Layers & Components
1. Client Layer (Browser)
- React App
- UI Components & Router
2. API Layer (Server)
- Express Server
- Auth Middleware (verifyToken)
- Controllers (authController, userController, doctorController, reviewController)
- Routes (auth.js, user.js, doctor.js, review.js)
3. Data Layer
- MongoDB Database (collections: Users, Doctors, Bookings, Reviews)
4. External Service
- Stripe API
b. Data Flows & Interactions
- User submits booking → React calls POST /doctor/book → verifyToken → BookingSchema → MongoDB
- User signup/login → React calls POST /auth/signup or /auth/login → authController → returns JWT
- Payment flow → React requests payment intent from Express → Express calls Stripe API → Stripe responds → React displays payment form
- Review posting → React calls POST /review → verifyToken → ReviewSchema → MongoDB
– Frontend → Backend (HTTP requests)
– Backend → Database (DB queries)
– Backend ↔ Stripe (HTTPS calls)
– Blue for UI components
– Green for API/server components
– Orange for database
– Purple for external services
– Rectangles for services/modules
– Clouds for third‑party

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Client Layer (Browser)"
    ReactSPA["React SPA"]:::frontend
  end

  subgraph "Frontend (React Application)"
    ME["main.jsx"]:::frontend
    AP["App.jsx"]:::frontend
    RT["Routers.jsx"]:::frontend
    UI["UI Components & Pages"]:::frontend
    UT["formatDate.js"]:::frontend
  end

  subgraph "Backend (Express API)"
    EX["Express Server (index.js)"]:::backend
    MW["verifyToken Middleware"]:::backend

    subgraph "Controllers"
      AC["authController.js"]:::backend
      UC["userController.js"]:::backend
      DC["doctorController.js"]:::backend
      RC["reviewController.js"]:::backend
    end

    subgraph "Routes"
      AR["auth.js"]:::backend
      UR["user.js"]:::backend
      DR["doctor.js"]:::backend
      RR["review.js"]:::backend
    end

    subgraph "Models"
      US["UserSchema.js"]:::database
      DS["DoctorSchema.js"]:::database
      BS["BookingSchema.js"]:::database
      RS["ReviewSchema.js"]:::database
    end

    EC[".env.example"]:::backend
  end

  MDB["MongoDB"]:::database
  STR["Stripe API"]:::external

  ReactSPA -->|User actions| ME
  ME -->|bootstrap| AP
  AP -->|renders| RT
  RT -->|navigates| UI
  UI -->|calls API| EX

  EX -->|uses config| EC
  EX -->|routes through| AR
  EX -->|routes through| UR
  EX -->|routes through| DR
  EX -->|routes through| RR
  EX -->|applies middleware| MW

  AR -->|handles auth| AC
  UR -->|handles user| UC
  DR -->|handles doctor| DC
  RR -->|handles review| RC

  MW -->|protects routes| DR
  MW -->|protects routes| RR

  AC -->|queries| US
  UC -->|queries| US
  DC -->|queries| DS
  DC -->|queries| BS
  RC -->|queries| RS

  EX -->|calls| STR

  classDef frontend fill:#D6EAF8,stroke:#21618C,color:#1B4F72
  classDef backend fill:#D5F5E3,stroke:#196F3D,color:#145A32
  classDef database fill:#FCF3CF,stroke:#B7950B,color:#7D6608
  classDef external fill:#F5EEF8,stroke:#7D3C98,color:#512E5F

  click ReactSPA "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/tree/master/frontend/src"
  click ME "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/frontend/src/main.jsx"
  click AP "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/frontend/src/App.jsx"
  click RT "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/frontend/src/routes/Routers.jsx"
  click UT "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/frontend/src/utils/formatDate.js"
  click EX "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/index.js"
  click MW "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/auth/verifyToken.js"
  click AC "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Controllers/authController.js"
  click UC "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Controllers/userController.js"
  click DC "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Controllers/doctorController.js"
  click RC "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Controllers/reviewController.js"
  click AR "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Routes/auth.js"
  click UR "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Routes/user.js"
  click DR "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Routes/doctor.js"
  click RR "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/Routes/review.js"
  click US "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/models/UserSchema.js"
  click DS "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/models/DoctorSchema.js"
  click BS "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/models/BookingSchema.js"
  click RS "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/models/ReviewSchema.js"
  click EC "https://github.com/mohamedboukthir/doctor-appointment-booking-mern-stack/blob/master/backend/.env.example"
```
